const createToken = async () => { // If this ...
# ask-ai
b
const createToken = async () => { // If this room doesn't exist, it'll be automatically created when the first // participant joins const roomName = 'quickstart-room'; // Identifier to be used for participant. // It's available as LocalParticipant.identity with livekit-client SDK const participantName = 'quickstart-username'; const at = new AccessToken(process.env.LIVEKIT_API_KEY, process.env.LIVEKIT_API_SECRET, { identity: participantName, // Token to expire after 10 minutes ttl: '10m', }); at.addGrant({ roomJoin: true, room: roomName }); return await at.toJwt(); }; i want to add agent_name also in the config of the token
t
Thanks for reaching out, Aman. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To include
agent_name
in the token configuration, you can use the
RoomConfiguration
class and specify the agent dispatch information. Here's a helpful example to guide you:
Copy code
const at = new AccessToken(process.env.LIVEKIT_API_KEY, process.env.LIVEKIT_API_SECRET, {
  identity: 'quickstart-username',
  ttl: '10m',
});

const roomConfig = new RoomConfiguration();
roomConfig.agents = [new RoomAgentDispatch({ agentName: 'your-agent-name' })];

at.roomConfig = roomConfig;
at.addGrant({ roomJoin: true, room: 'quickstart-room' });

const token = await at.toJwt();
This setup embeds the
agent_name
right into the JWT token, so LiveKit can dispatch the right agent when a participant joins the room. If you have any questions or want me to walk you through any part of this, just let me know—I’m here to help! Sources: src/pages/api/token.ts | Job lifecycle | LiveKit Docs | Authentication | LiveKit Docs | CHANGELOG.md | app/api/connection-details/route.ts