how can I use different agent when I join the live...
# ask-ai
h
how can I use different agent when I join the livekit room?
t
Thanks for reaching out, YUNYI. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
If you'd like to use a different agent when joining a LiveKit room, you can turn off automatic dispatch and take control by assigning agents explicitly. Here’s how you can do it: • Set Up Agent with Explicit Dispatch: Give your agent a specific
agent_name
in the agent’s
WorkerOptions
. This stops automatic dispatch and lets you decide which agent joins. • Dispatch Agent via API: Use the
AgentDispatchService
from your backend to assign an agent to a room whenever you want. • Dispatch Agent on Participant Join: Set up the agent dispatch right in the participant’s access token using
RoomConfiguration
, so an agent gets assigned automatically as soon as someone connects. If you want me to walk you through some examples or need a hand with anything else, just give me a shout! Sources: Agent dispatch | LiveKit Docs | Dispatching agents | LiveKit Docs | packages/livekit-server-sdk/src/AgentDispatchClient.ts
h
I use the official livekit cloud, how can I change the user access token?
t
Hey there! If you want to change a user access token in LiveKit Cloud, you’ll just need to create a new token with the updated details. Here are a few easy ways to do that: • Using the LiveKit CLI: First, install the CLI and then run this command:
lk token create --api-key <project_key> --api-secret <project_secret> --identity <user_identity> --room <room_name> --join --valid-for 24h
Just swap out the placeholders with your actual info. • Using the LiveKit Cloud Dashboard: Head over to Settings > Keys in your project dashboard, and you can generate tokens right there. • Using Server SDKs: If you prefer coding, LiveKit’s server SDKs (like Node.js or Python) let you create tokens programmatically. Here’s a quick example in Node.js:
Copy code
import { AccessToken } from 'livekit-server-sdk';

const at = new AccessToken(apiKey, apiSecret, { identity: 'user123' });
at.addGrant({ roomJoin: true, room: 'test-room', canPublish: true });
const token = await at.toJwt();
If you have any questions or want a hand with any of these steps, just let me know—I’m here to help! Sources: CLI Setup | LiveKit Docs | packages/livekit-server-sdk/src/AccessToken.ts | Authentication | LiveKit Docs
h
I don't mean this, I mean *"*the participant’s access token*".*
t
Hey there! Just a quick heads-up: you can't directly change a participant's access token in LiveKit Cloud. But no worries—LiveKit has a neat way of refreshing tokens automatically when you update certain participant details. Here’s how you can make that happen: • Update Permissions: Try using the
UpdateParticipant
API to tweak what the participant can do (like allowing publishing). This will kick off a token refresh. • Update Metadata: Change the participant’s metadata with
UpdateParticipant
, and the client will get a
ParticipantMetadataChanged
event along with a fresh token. • Update Name: Even updating the participant’s name through
UpdateParticipant
will refresh the token. If you want, I’m happy to walk you through some examples or help out with any of these steps—just let me know! Sources: Managing participants | LiveKit Docs | Authentication | LiveKit Docs | Authentication | LiveKit Docs