narrow-advantage-65481
12/04/2025, 1:48 AMtall-airline-16756
12/04/2025, 1:48 AMtall-airline-16756
12/04/2025, 1:49 AMagent_name in WorkerOptions is all that's required on the agent worker to enable explicit dispatch and disable automatic dispatch.
After that, the agent will only be assigned to rooms when you explicitly dispatch it by one of these methods:
• Token-based dispatch: include a RoomConfiguration with RoomAgentDispatch in the participant's access token.
• API-based dispatch: call the AgentDispatchService API to create a dispatch request.
• SIP dispatch rules: configure a SIP dispatch rule with roomConfig.agents for inbound calls.
Would you like instructions for one of those dispatch methods (token, API, or SIP) for your environment?
Sources: Agent dispatch | LiveKit docs | SIP dispatch rule | LiveKit docsnarrow-advantage-65481
12/04/2025, 1:52 AMtall-airline-16756
12/04/2025, 1:52 AMRoomConfiguration with RoomAgentDispatch (agent_name and optional metadata) in the participant’s access token so the agent is dispatched when the participant joins the room.
• API-based dispatch: call the AgentDispatchService API to create a dispatch request and assign the agent to the room.
Token-based dispatch is simplest for Playground testing (agent joins as the participant connects); use the API when you need programmatic control or delayed/conditional dispatch. Which method would you like step-by-step instructions for?
Sources: Agent dispatch | LiveKit docs | Agents telephony integration | LiveKit docsnarrow-advantage-65481
12/04/2025, 1:56 AMtall-airline-16756
12/04/2025, 1:57 AM@server.rtc_session(agent_name="my-agent")
• Node.js: new WorkerOptions({ agentName: "my-agent" })
1. Generate a participant access token that includes RoomConfiguration.agents with a RoomAgentDispatch entry (agent name + optional metadata). Example — Python:
from livekit.api import AccessToken, VideoGrants, RoomConfiguration, RoomAgentDispatch
token = (
AccessToken()
.with_identity("participant-identity")
.with_grants(VideoGrants(room_join=True, room="my-room"))
.with_room_config(
RoomConfiguration(
agents=[RoomAgentDispatch(agent_name="my-agent", metadata='{"user_id":"12345"}')]
)
)
.to_jwt()
)
Node.js example:
import { AccessToken } from "livekit-server-sdk";
import { RoomConfiguration, RoomAgentDispatch } from "@livekit/protocol";
const at = new AccessToken("API_KEY","API_SECRET");
at.identity = "participant-identity";
at.addGrant({ roomJoin: true, room: "my-room" });
at.roomConfig = new RoomConfiguration({
agents: [ new RoomAgentDispatch({ agentName: "my-agent", metadata: '{"user_id":"12345"}' }) ]
});
const token = await at.toJwt();
1. Start the agent server so it can accept dispatch jobs (ensure the agent_name matches the token).
2. Connect the participant using the generated token. When they join, the room is created if needed and the named agent is dispatched automatically.
3. Optional: read metadata from the agent’s JobContext to personalize behavior.
Would you like this in a specific language or a complete minimal repo/example for the Playground?
Sources: Agent dispatch | LiveKit docs | Authentication | LiveKit docs | Agents telephony integration | LiveKit docs | Web and mobile frontends | LiveKit docsnarrow-advantage-65481
12/04/2025, 1:57 AMtall-airline-16756
12/04/2025, 1:58 AMfrom livekit.agents import AgentServer, JobContext
server = AgentServer()
@server.rtc_session(agent_name="my-agent")
async def my_agent(ctx: JobContext):
# example: read metadata
metadata = ctx.metadata or {}
print("Dispatched with metadata:", metadata)
# implement agent behavior here
await ctx.wait() # keep alive for demo; replace with real logic
if __name__ == "__main__":
server.run()
2) Generate a participant token that includes RoomConfiguration with RoomAgentDispatch (token generation script: create_token.py)
from livekit.api import AccessToken, VideoGrants, RoomConfiguration, RoomAgentDispatch
API_KEY = "your_api_key"
API_SECRET = "your_api_secret"
def create_token():
token = (
AccessToken(api_key=API_KEY, api_secret=API_SECRET)
.with_identity("participant-identity")
.with_grants(VideoGrants(room_join=True, room="my-room"))
.with_room_config(
RoomConfiguration(
agents=[
RoomAgentDispatch(
agent_name="my-agent",
metadata='{"user_id":"12345"}' # optional
)
]
)
)
.to_jwt()
)
return token
if __name__ == "__main__":
print(create_token())
3) Start the agent server
• Run the agent so it can accept dispatch jobs:
python agent.py
4) Connect the participant using the generated token
• Provide the printed JWT from create_token.py to your frontend/client SDK and join "my-room".
• When the participant connects, the room will be created if needed and the named agent my-agent will be dispatched automatically.
5) Use metadata in the agent
• In the agent handler ctx.metadata contains the JSON string from RoomAgentDispatch.metadata for per-job info.
Notes
• Ensure agent_name in the token matches the agent_name used in the agent code.
• Keep the agent process running in the Playground while testing.
Would you like a minimal repository structure or a full example that includes a simple frontend to join the room with the token?narrow-advantage-65481
12/04/2025, 1:59 AMtall-airline-16756
12/04/2025, 1:59 AMnarrow-advantage-65481
12/04/2025, 2:20 AM