bumpy-cricket-48637
09/14/2025, 7:48 PMtall-airline-16756
09/14/2025, 7:48 PMtall-airline-16756
09/14/2025, 7:48 PMRoomConfiguration in the participant's access token. This way, the agent will automatically be dispatched to the room as soon as the participant joins.
Here’s how you can do it step-by-step:
1. Include the agent's name in the agents list within the RoomConfiguration.
2. Attach this RoomConfiguration to the participant’s access token when you generate it.
Here’s an example in Node.js to guide you:
import { AccessToken } from 'livekit-server-sdk';
import { RoomAgentDispatch, RoomConfiguration } from '@livekit/protocol';
const at = new AccessToken('api-key', 'secret-key', {
identity: 'my-participant',
});
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();
And here’s a Python example for you:
from livekit.api import AccessToken, RoomAgentDispatch, RoomConfiguration, VideoGrants
token = (
AccessToken()
.with_identity("my_participant")
.with_grants(VideoGrants(room_join=True, room="my-room"))
.with_room_config(
RoomConfiguration(
agents=[
RoomAgentDispatch(agent_name="test-agent", metadata='{"user_id": "12345"}')
],
),
)
.to_jwt()
)
Just a quick note: please make sure your agent is already deployed and registered as a worker with the LiveKit server. If you run into any questions or if you’re using a different SDK, feel free to reach out—I’m here to help!
Sources: Authentication | LiveKit Docs | examples/agent-dispatch/index.ts | Agent dispatch | LiveKit Docs | examples/agent_dispatch.py | LiveKit Agents | LiveKit Docs