cuddly-kite-65599
09/03/2025, 8:57 AMtall-airline-16756
09/03/2025, 8:57 AMtall-airline-16756
09/03/2025, 8:58 AMroomJoin). If you want an agent to be dispatched automatically when someone joins, include a RoomConfiguration too.
2. Send Token to Frontend: Next, securely send that token to your frontend through an API endpoint. Make sure it contains the server URL, room name, and participant token.
3. Frontend Connection: On the frontend, use the LiveKit client SDK to connect to the room using the token you just sent.
4. Agent Dispatch: If your token has a RoomConfiguration with agent info, LiveKit will handle dispatching the agent(s) automatically when the participant joins. Or, if you prefer, you can dispatch agents manually using the API.
If you want me to walk you through any of these steps with more details or examples, just give me a shout—I’m here to help!
Sources: Web and mobile frontends | LiveKit Docs | Authentication | LiveKit Docs | Agent dispatch | LiveKit Docs | packages/livekit-server-sdk/src/AgentDispatchClient.ts | Next.js quickstart | LiveKit Docscuddly-kite-65599
09/03/2025, 9:00 AMapi.AccessToken(settings.livekit_api_key, settings.livekit_api_secret) \
.with_identity(request.user_id) \
.with_name(request.target_persona) \
.with_grants(api.VideoGrants(
room_join=True,
room=room_name,
)).with_room_config(
api.RoomConfiguration(
agents=[
api.RoomAgentDispatch(agent_name="test-agent", metadata=meta)
],
),
)tall-airline-16756
09/03/2025, 9:01 AMRoomAgentDispatch really needs to match the one in WorkerOptions for everything to work smoothly. If they don’t line up, the agent won’t get assigned to the room, and the dispatch won’t go through.
Here’s a quick example to make it clearer:
• In WorkerOptions, you’d set agent_name = "test-agent" when you’re defining your agent worker.
• Then, in RoomAgentDispatch, use that exact same name: agent_name="test-agent" when you’re setting up the dispatch rule or token configuration.
This way, you’re making sure the right agent gets sent to the room just like you planned. If anything’s still fuzzy or you want to dive deeper, just let me know—I’m here to help!
Sources: SIP troubleshooting guide | LiveKit Docs | Agent dispatch | LiveKit Docs | Dispatching agents | LiveKit Docs | packages/livekit-server-sdk/src/AgentDispatchClient.tscuddly-kite-65599
09/03/2025, 9:02 AMtall-airline-16756
09/03/2025, 9:02 AMcuddly-kite-65599
09/03/2025, 9:02 AMtall-airline-16756
09/03/2025, 9:03 AMsession.history to pull the full conversation history and save it as a JSON file right after the session ends, using a shutdown callback.
◦ Or, listen to real-time transcription events (like conversation_item_added) to log or stream transcripts as the session happens.
If you want, I’m happy to share some detailed examples or help you get these features set up!
Sources: Session recording and transcripts | LiveKit Docscuddly-kite-65599
09/03/2025, 9:06 AMtall-airline-16756
09/03/2025, 9:07 AMRoomConfiguration that includes the agent dispatch details, like the agentName and any optional metadata you might want to add.
2. Expose an API Endpoint: Next, set up a backend endpoint that can generate and send this token to your frontend. Make sure this endpoint securely signs the token using your LiveKit API key and secret.
3. Frontend Requests the Token: On the frontend side, simply make a request to that backend endpoint to grab the token—using something like fetch works great here.
4. Connect to LiveKit: Finally, use the token you received with the LiveKit client SDK to connect the participant to the room. The agent will be dispatched automatically as soon as the connection happens.
This method keeps your token delivery secure and makes agent dispatch smooth and hassle-free. If you want, I’d be happy to share some code examples or explain anything in more detail—just let me know!
Sources: Agent dispatch | LiveKit Docs | examples/agent-dispatch/index.ts | src/pages/api/token.ts | client/web/src/app/api/connection-details/route.ts | Generating tokens | LiveKit Docscuddly-kite-65599
09/03/2025, 9:09 AMapi.AccessToken(settings.livekit_api_key, settings.livekit_api_secret) \
.with_identity(request.user_id) \
.with_name(request.target_persona) \
.with_grants(api.VideoGrants(
room_join=True,
room=room_name,
)).with_room_config(
api.RoomConfiguration(
agents=[
api.RoomAgentDispatch(agent_name="test-agent", metadata=meta)
],
),
)
If not, then how will the frontend know that user will enter which room?tall-airline-16756
09/03/2025, 9:10 AMAgentDispatchService to send an agent straight to a room without needing a token. This works great if you’re managing things on the backend or want to dispatch agents proactively.
• Token-Based Dispatch: If you want the agent to join automatically as soon as a participant connects, you’ll want to generate a token with a RoomConfiguration that includes the agent dispatch details. This is perfect for setups where the user kicks things off and the agent should jump in right away.
Pick the approach that fits your needs best. And if you’d like a hand figuring it out or getting it set up, just let me know what you’re aiming for—I’m here to help!
Sources: Agent dispatch | LiveKit Docs | Web and mobile frontends | LiveKit Docs | examples/agent-dispatch/index.ts | examples/agent_dispatch.py | app/api/connection-details/route.tscuddly-kite-65599
09/03/2025, 9:11 AMapi.AccessToken(settings.livekit_api_key, settings.livekit_api_secret) \
.with_identity(request.user_id) \
.with_name(request.target_persona) \
.with_grants(api.VideoGrants(
room_join=True,
room=room_name,
)).with_room_config(
api.RoomConfiguration(
agents=[
api.RoomAgentDispatch(agent_name="test-agent", metadata=meta)
],
),
)
If not, then how will the frontend know that user will enter which room?tall-airline-16756
09/03/2025, 9:11 AMroom_join=True).
Here’s a simple way the frontend can figure out which room the user will enter:
1. Backend Determines Room Name: The backend picks or creates the room name when it sets up the dispatch request or gets the user’s token ready.
2. Send Room Details to Frontend: Along with the user’s token, the backend can send the room name and server URL to the frontend through an API response.
3. Frontend Connects to Room: The frontend then uses the room name and token it received to connect to the LiveKit server.
So, even if you’re working with API-based dispatch, the user’s token is still super important for joining the room. If you want me to walk you through it more or share some examples, just let me know—I’m here to help!cuddly-kite-65599
09/03/2025, 9:26 AMtoken = api.AccessToken(settings.livekit_api_key, settings.livekit_api_secret) \
.with_identity(request.user_id) \
.with_name(request.target_persona) \
.with_grants(api.VideoGrants(
room_join=True,
room=room_name,
)).with_room_config(
api.RoomConfiguration(
agents=[
api.RoomAgentDispatch(agent_name="test-agent", metadata=meta)
],
),
)
now, using the token and my livekit url, I pasted in hosted deployments manual mode and tried to enter a room. My assumption is that my agent job should auto dispatch the agent, i am running it in debug mode. It also ran fine for 1-2 times but now when i enter a room with new token, no new agent is being dispatched.
if __name__ == "__main__":
cli.run_app(
WorkerOptions(
entrypoint_fnc=entrypoint,
prewarm_fnc=prewarm,
agent_name="test-agent"
),
)tall-airline-16756
09/03/2025, 9:27 AMagent_name in WorkerOptions, it actually turns off automatic dispatch on purpose. So, if you’ve defined agent_name, you’ll need to dispatch the agent explicitly either:
• By making an API call using AgentDispatchService.
• Or by using a participant token that includes RoomConfiguration.agents with a RoomAgentDispatch entry.
To make sure your agent gets dispatched as soon as a participant connects, just double-check that your participant token has the agent configuration like this:
at.roomConfig = new RoomConfiguration({
agents: [
new RoomAgentDispatch({
agentName: 'test-agent',
metadata: '{"mydata": "myvalue"}',
}),
],
});
If you’d prefer things to happen automatically without having to manage it yourself, simply remove the agent_name from WorkerOptions. And hey, if you have any questions or want a hand with this, just let me know—I’m here to help!
Sources: Dispatching agents | LiveKit Docs | Agent dispatch | LiveKit Docs | examples/agent-dispatch/index.ts | examples/agent_dispatch.pycuddly-kite-65599
09/03/2025, 9:28 AMtall-airline-16756
09/03/2025, 9:28 AMagent_name in WorkerOptions is set correctly. Without this, the agent won’t be able to dispatch.
2. Match Those Agent Names: Take a look at the agent_name in your participant token’s RoomAgentDispatch and make sure it exactly matches the agent_name in the agent’s WorkerOptions. Even small differences can cause issues.
3. Check the Token Setup: Make sure your participant token has a properly formatted RoomConfiguration that includes the agents field with the right agent name and any optional metadata.
4. Confirm Room and Agent Are Ready: Verify that the room was created successfully and that your agent worker is idle and ready to receive dispatch requests. You can use the LiveKit CLI or API to peek at active dispatches.
5. Peek at the Logs: Take a look at both the agent logs and server logs for any errors or warnings related to dispatch or room creation—they often give great clues.
6. Check Version Compatibility: Make sure all your SDKs and services are running compatible versions to avoid any unexpected hiccups.
If you’re still stuck after trying these, just give me a shout! We can dig into specific logs or configurations together and get this sorted out.
Sources: Agent dispatch | LiveKit Docs | SIP troubleshooting guide | LiveKit Docs | examples/agent-dispatch/index.ts | Authentication | LiveKit Docs | Getting Help | livekit/livekit_composite | DeepWikicuddly-kite-65599
09/03/2025, 9:33 AMtall-airline-16756
09/03/2025, 9:33 AMcuddly-kite-65599
09/03/2025, 9:34 AM