colossal-manchester-31772
08/14/2025, 6:41 AMtall-airline-16756
08/14/2025, 6:41 AMtall-airline-16756
08/14/2025, 6:42 AMimport { RoomAgentDispatch, RoomConfiguration } from '@livekit/protocol';
import { AccessToken } from 'livekit-server-sdk';
const token = new AccessToken();
token.identity = 'participant-id';
token.addGrant({ roomJoin: true, room: 'room-name' });
token.roomConfig = new RoomConfiguration({
agents: [
new RoomAgentDispatch({
agentName: 'agent-name',
metadata: '{"key": "value"}',
}),
],
});
const jwt = token.toJwt();
console.log(jwt);
1. Then, when the participant connects to the room, the agent you specified will be dispatched automatically—pretty neat, right?
If you’d rather have more hands-on control, you can also dispatch an agent manually using the AgentDispatchClient like this:
import { AgentDispatchClient } from 'livekit-server-sdk';
const client = new AgentDispatchClient('LIVEKIT_URL');
const dispatch = await client.createDispatch('room-name', 'agent-name', {
metadata: '{"key": "value"}',
});
console.log(dispatch);
Feel free to reach out if you want me to walk you through any of this or if you have other questions—I’m here to help!
Sources: packages/livekit-server-sdk/src/AgentDispatchClient.ts | Dispatching agents | LiveKit Docs | livekit/livekit_agent_dispatch.twirp.go