abundant-father-33863
05/16/2025, 11:41 AMtall-airline-16756
05/16/2025, 11:41 AMtall-airline-16756
05/16/2025, 11:41 AM.env.local
or .env.development.local
, containing:
LIVEKIT_API_KEY=<your api key>
LIVEKIT_API_SECRET=<your api secret>
LIVEKIT_URL=<your livekit server url>
This setup ensures proper separation and management of environments.
Sources: Deploying to production | LiveKit Docs | Next.js 13+ quickstart | LiveKit Docsabundant-father-33863
05/16/2025, 11:42 AMtall-airline-16756
05/16/2025, 11:42 AMagent_name
field: When registering your agents, specify the agent_name
in `WorkerOptions`: `opts = WorkerOptions(
...
agent_name="test-agent",
)`This ensures the agent is not automatically dispatched to newly created rooms.
2. Dispatch agents to rooms: You can dispatch these named agents in several ways:
◦ Via API: Use the AgentDispatchService
to explicitly dispatch agents to rooms: import asyncio
from livekit import api
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"
)
)
◦ From inbound SIP calls: Use SIP dispatch rules to route calls to specific agents.
◦ On participant connection: Configure a participant’s token to include agent dispatch: from livekit.api import (
AccessToken,
RoomAgentDispatch,
RoomConfiguration,
VideoGrants,
)
def create_token_with_agent_dispatch() -> str:
token = (
AccessToken()
.with_identity("my_participant")
.with_grants(VideoGrants(room_join=True, room=room_name))
.with_room_config(
RoomConfiguration(
agents=[
RoomAgentDispatch(agent_name="test-agent", metadata="my_metadata")
],
),
)
.to_jwt()
)
return token
1. Multi-agent systems: You can also implement a multi-agent system where one agent hands off to another during a session. Refer to the multi_agent.py
example for guidance.
This setup allows you to manage and dispatch agents effectively on a single LiveKit server.
Sources: Dispatching agents | LiveKit Docs | Tree View: | dse-workbench