How do i set the agent's name ?
# ask-ai
e
How do i set the agent's name ?
t
Thanks for reaching out, Aditya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to set an agent's name — here's how to do that and what it changes. For Python 1. Pass
agent_name
when declaring the agent session:
Copy code
server = AgentServer()

@server.rtc_session(agent_name="my-telephony-agent")
async def my_agent(ctx: JobContext):
    ...
For Node.js 1. Set
agentName
in `WorkerOptions`:
Copy code
const opts = new WorkerOptions({
  agentName: "my-telephony-agent",
});
Notes • Setting an agent name enables explicit agent dispatch and disables automatic dispatch; the agent will be assigned to rooms only when explicitly dispatched. • You can dispatch named agents via the CLI, for example:
Copy code
lk dispatch create --agent-name my-telephony-agent --new-room
Would you like the exact code snippet inserted into your existing agent file or help dispatching the agent to a room? Sources: Agents telephony integration | LiveKit docs | Agent dispatch | LiveKit docs
e
Is it possible to set the name dynamically ?
t
You're asking whether the agent name can be set dynamically — yes. You can set the agent name dynamically in these ways: • Use the Agent Dispatch API when creating a dispatch and pass the desired
agent_name
(Python or Node client). • Include the agent name in room configuration when minting an access token (
RoomAgentDispatch.agent_name
) so the room requests that specific agent. • Call the CLI with
--agent-name
when creating a dispatch. Notes to keep in mind: • Setting an explicit
agent_name
on an agent disables automatic dispatch; the agent will only be assigned when explicitly dispatched. • Changing agent names after deployment can affect dispatch rules and frontends, so plan changes carefully. • You can run multiple workers with the same
agent_name
for load balancing/high availability. Would you like an example for Python or Node that fits into your current code or help wiring dynamic names from your backend (e.g., based on user or metadata)? Sources: Agent dispatch | LiveKit docs | Agent Builder | LiveKit docs | Agents Framework | livekit/livekit_composite | DeepWiki
e
const r = new Room({ adaptiveStream: true, dynacast: true, videoCaptureDefaults: { resolution: { width: 1280, height: 720, frameRate: 30 }, }, }); How do i set the room metada here ?
t
You're asking how to set room metadata from your Room initialization code. You cannot set room metadata in the client-side
Room
constructor. What you can do: • Set metadata server-side when creating the room with the RoomService API:
Copy code
const room = await roomService.createRoom({
  name: 'my-room',
  metadata: JSON.stringify({ purpose: 'meeting', host: 'user123' }),
});
• Update metadata later from the server:
Copy code
await roomService.updateRoomMetadata('my-room', JSON.stringify({ status: 'active' }));
• On the client, listen for updates:
Copy code
room.on('metadataChanged', (newMeta: string) => {
  console.log('Room metadata:', newMeta);
});
Would you like a ready-to-use server example (Node or Python) that fits your backend? Sources: Room metadata | LiveKit docs
e
how to listen the room disconnect event on the client side ?
t
You're asking how to listen for the room disconnect event on the client side. Below are concise examples for common LiveKit client SDKs — use the one that matches your platform. JavaScript / TypeScript
Copy code
room.on('Disconnected', () => {
  console.log('Disconnected from room');
  // cleanup UI, stop timers, notify user, etc.
});
Swift (iOS/macOS)
Copy code
room.on(.disconnected) {
  print("Disconnected from room")
  // cleanup or UI updates
}
Kotlin (Android)
Copy code
room.addConnectionListener(object : RoomConnectionListener {
  override fun onDisconnected() {
    println("Disconnected from room")
    // cleanup or UI updates
  }
})
Flutter / Dart
Copy code
room.on<RoomDisconnectedEvent>((event) {
  print("Disconnected from room");
  // cleanup or UI updates
});
Would you like a brief example that shows cleanup steps (reconnect UI, state reset) for your specific app? Sources: Handling events | LiveKit docs | Connecting to LiveKit | LiveKit docs
e
room.on('Disconnected', () => { console.log('Disconnected from room'); // cleanup UI, stop timers, notify user, etc. }); How would i get the room on the client side when room is created on the server side
t
You create the Room instance on the client by connecting the client to the server-created room with a join token (or URL). Server creates the room and mints a token; client uses that token to call
connect
and receives a
Room
object you can listen on. Example flow (server + client): 1) Server: create room & mint token (room created via RoomService) • Create or ensure room exists, then generate an access token scoped to that room and participant identity. Return the token (JWT) to the client. 2) Client: connect with the token and get the Room instance
Copy code
import { Room } from 'livekit-client';

// token received from your backend
const token = '<TOKEN_FROM_SERVER>';

const room = new Room({
  adaptiveStream: true,
  dynacast: true,
  videoCaptureDefaults: { resolution: { width: 1280, height: 720, frameRate: 30 } },
});

// connect and obtain the Room instance to listen for events
await room.connect('<wss://your-livekit-url>', token);

// now you can listen for disconnect and other events
room.on('Disconnected', () => {
  console.log('Disconnected from room');
});
If you already create the room server-side, just ensure your server returns the join token (and room name if needed) to the client. The client uses that token in
room.connect(...)
to obtain the Room object for event handling. Do you want a snippet showing how to mint the token on Node or Python?