steep-translator-89612
08/20/2025, 1:08 AMtall-airline-16756
08/20/2025, 1:08 AMtall-airline-16756
08/20/2025, 1:08 AMagent_name
in `WorkerOptions`: This turns off automatic dispatch and lets you control dispatch explicitly through the API. For example:
if __name__ == "__main__":
cli.run_app(
WorkerOptions(
entrypoint_fnc=entrypoint,
agent_name="outbound-caller", # This enables explicit dispatch
)
)
1. Use the AgentDispatchService
API to dispatch the Agent: Once your worker is up and running, you can programmatically dispatch it to a specific room like this:
import asyncio
from livekit import api
room_name = "my-room"
agent_name = "outbound-caller"
async def create_explicit_dispatch():
lkapi = api.LiveKitAPI()
dispatch = await lkapi.agent_dispatch.create_dispatch(
api.CreateAgentDispatchRequest(
agent_name=agent_name,
room=room_name,
metadata="my_job_metadata"
)
)
print("created dispatch", dispatch)
1. Make sure the Agent worker is running: Simply start the worker script so it connects to the LiveKit server, like this:
python agent_worker.py dev
1. Handle multi-tenancy: Keep things isolated by using room isolation and pass any tenant-specific info through the metadata
field in CreateAgentDispatchRequest
.
2. (Optional) Build a dispatcher service: If you want, you can create a custom service (maybe with FastAPI) to manage your worker processes dynamically.
This method lets you activate Agents on demand, perfectly tailored for your multi-tenant setup. If you have any questions or want to dive deeper, just let me know—I’m here to help!
Sources: Making calls using SIP | LiveKit Docs | Making calls using SIP | LiveKit Docs | Dispatching agents | LiveKit Docs | examples/avatar_agents/audio_wave/dispatcher.pysteep-translator-89612
08/20/2025, 1:13 AMtall-airline-16756
08/20/2025, 1:13 AMsteep-translator-89612
08/20/2025, 1:15 AMtall-airline-16756
08/20/2025, 1:16 AMsubprocess.Popen
to spin up a new Python process for the agent worker. Just pass the needed environment variables (like LIVEKIT_URL
, LIVEKIT_TOKEN
, and LIVEKIT_ROOM
) so the agent connects properly to LiveKit.
4. Keep an eye on the workers: It’s a good idea to monitor and clean up these subprocesses when they’re done to keep things running smoothly.
Here’s an example of what the POST request payload might look like when the frontend talks to the dispatcher server:
{
"room_name": "test-room",
"url": "<wss://your-livekit-server>",
"token": "your-agent-token"
}
For a hands-on example, check out the dispatcher.py
file in the LiveKit Agents repo. It shows exactly how to spin up agent workers dynamically using FastAPI and subprocess.Popen
.
If you want, I’m here to help with more details or code snippets to get your dispatcher service up and running!
Sources: examples/other/translation/multi-user-translator.py | LiveKit Docs | Worker lifecycle | LiveKit Docs | Anatomy of an Agent | LiveKit Docs | Worker options | LiveKit Docs