colossal-lock-10836
09/21/2025, 4:59 PMtall-airline-16756
09/21/2025, 5:00 PMtall-airline-16756
09/21/2025, 5:00 PMlivekit-server-sdk to create an access token. Make sure to include a RoomConfiguration with a RoomAgentDispatch entry that specifies the target agentName. Here’s a simple example to guide you:
import { AccessToken } from 'livekit-server-sdk';
import { RoomAgentDispatch, RoomConfiguration } from '@livekit/protocol';
const at = new AccessToken('your-api-key', 'your-api-secret', {
identity: 'my-participant',
});
at.addGrant({
roomJoin: true,
room: 'my-room',
});
at.roomConfig = new RoomConfiguration({
agents: [
new RoomAgentDispatch({
agentName: 'test-agent',
metadata: '{"user_id": "12345"}',
}),
],
});
const token = await at.toJwt();
console.log('Access token:', token);
1. Configure the Agent: It’s important to make sure the agent is registered with the same agentName in its WorkerOptions. This way, automatic dispatch is disabled, allowing for explicit assignment.
2. Optional: If you want, you can also dispatch agents programmatically using the AgentDispatchClient. It’s a handy option when needed.
If you have any questions or would like me to provide more examples, please don’t hesitate to ask. I’m here to help!
Sources: Authentication | LiveKit Docs | Agent dispatch | LiveKit Docs | Dispatching agents | LiveKit Docs | packages/livekit-server-sdk/src/AgentDispatchClient.ts | templates.yaml