Skip to main content

Agent Framework plugin for services from Ultravox

Project description

LiveKit Ultravox Plugin

LiveKit plugin for Ultravox's real-time speech-to-speech AI models, providing seamless integration with the LiveKit Agents framework.

Installation

pip install livekit-plugins-ultravox

Prerequisites

You'll need an API key from Ultravox. Set it as an environment variable:

export ULTRAVOX_API_KEY="your_api_key_here"

Optional: enable debug logs for the plugin (disabled by default):

export LK_ULTRAVOX_DEBUG=true

Basic Usage

Simple Voice Assistant

import asyncio
from livekit.agents import Agent, AgentSession, JobContext, JobProcess, WorkerOptions, cli
from livekit.plugins import silero
from livekit.plugins.ultravox.realtime import RealtimeModel

async def entrypoint(ctx: JobContext):
    await ctx.connect()
    
    session: AgentSession[None] = AgentSession(
        allow_interruptions=True,
        vad=ctx.proc.userdata["vad"],
        llm=RealtimeModel(
            model_id="fixie-ai/ultravox",
            voice="Mark",
        ),
    )
    
    await session.start(
        agent=Agent(
            instructions="You are a helpful voice assistant.",
        ),
        room=ctx.room,
    )

def prewarm(proc: JobProcess) -> None:
    proc.userdata["vad"] = silero.VAD.load()

if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, prewarm_fnc=prewarm))

Voice Assistant with Tools

from livekit.agents import function_tool, Agent, AgentSession, JobContext, JobProcess, WorkerOptions, cli
from livekit.plugins import silero
from livekit.plugins.ultravox.realtime import RealtimeModel

@function_tool
async def get_weather(location: str) -> str:
    """Get weather information for a location."""
    return f"The weather in {location} is sunny and 72°F"

@function_tool
async def book_appointment(date: str, time: str) -> str:
    """Book an appointment."""
    return f"Appointment booked for {date} at {time}"

async def entrypoint(ctx: JobContext):
    await ctx.connect()
    
    session: AgentSession[None] = AgentSession(
        allow_interruptions=True,
        vad=ctx.proc.userdata["vad"],
        llm=RealtimeModel(model_id="fixie-ai/ultravox"),
    )
    
    await session.start(
        agent=Agent(
            instructions="You are a helpful assistant with access to weather and scheduling tools.",
            tools=[get_weather, book_appointment],
        ),
        room=ctx.room,
    )

def prewarm(proc: JobProcess) -> None:
    proc.userdata["vad"] = silero.VAD.load()

if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, prewarm_fnc=prewarm))

Configuration Options

Ultravox API (/api/calls) Parameters

RealtimeModel(
    model_id="fixie-ai/ultravox",         # Model to use (warn + pass-through if unknown)
    voice="Mark",                         # Voice to use (warn + pass-through if unknown)
    api_key=None,                          # API key (defaults to env var)
    base_url=None,                         # API base URL (defaults to Ultravox API)
    system_prompt="You are helpful.",      # System prompt
    input_sample_rate=16000,               # Input audio sample rate
    output_sample_rate=24000,              # Output audio sample rate
    client_buffer_size_ms=60,              # Audio buffer size (min 200ms used on WS)
    http_session=None,                     # Custom HTTP session
)

Notes:
- Unknown models/voices: the plugin logs a warning and sends them as-is; the server validates.
- Metrics: the plugin emits a single `metrics_collected` event per generation. To log them,
  add a listener in your app and call the helper:

```python
from livekit.agents import metrics

@session.on("metrics_collected")
def on_metrics_collected(ev):
    metrics.log_metrics(ev.metrics)



Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

livekit_plugins_ultravox-1.5.0rc2.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

livekit_plugins_ultravox-1.5.0rc2-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file livekit_plugins_ultravox-1.5.0rc2.tar.gz.

File metadata

File hashes

Hashes for livekit_plugins_ultravox-1.5.0rc2.tar.gz
Algorithm Hash digest
SHA256 991b52419dbb5cf91f2fe54e595ee57673b0d0d99c0cb5c0d88ba104c04506f7
MD5 4c87f60d96e4dfafc02ed4413e73092d
BLAKE2b-256 e43076dac4615cfbbcb7e0c10572e0e858810e9f87e393736fa4b7f422479d41

See more details on using hashes here.

File details

Details for the file livekit_plugins_ultravox-1.5.0rc2-py3-none-any.whl.

File metadata

File hashes

Hashes for livekit_plugins_ultravox-1.5.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 3d6f9c7693d4ffc9d3834f3d0163018433808377e8be3b0b5628e5bf5e1f6401
MD5 0a0eebec738079635a0ff60ede34e700
BLAKE2b-256 9d3870b39449e3d961d89d467ba751d0803a908987c57e5c2f9a4ff73c103ce9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page