careful-iron-56445
10/24/2025, 10:48 AMtall-airline-16756
10/24/2025, 10:48 AMtall-airline-16756
10/24/2025, 10:48 AMagent_name in the worker configuration.
◦ Then, use the AgentDispatchService API to create a dispatch so the agent joins the room. For example: // Node.js
const agentDispatchClient = new AgentDispatchClient(process.env.LIVEKIT_URL);
const dispatch = await agentDispatchClient.createDispatch(roomName, agentName, {
metadata: '{"mydata": "myvalue"}',
});
◦ If you want the agent to leave, simply delete the dispatch like this: // Node.js
await agentDispatchClient.deleteDispatch(dispatchId, roomName);
1. Dispatch Agent via Access Token:
◦ You can also embed the agent dispatch configuration directly into the participant’s access token. This way, the agent will join automatically when the participant connects. Here’s how: // Node.js
at.roomConfig = new RoomConfiguration({
agents: [
new RoomAgentDispatch({
agentName: agentName,
metadata: '{"mydata": "myvalue"}',
}),
],
});
1. Agent Exit Behavior:
◦ Agents can exit manually by deleting the dispatch, or you can define custom behavior for when they disconnect using the on_exit method in the agent class.
If you have any questions or need a hand with implementing these, please don’t hesitate to ask. I’m here to help!
Sources: packages/livekit-server-sdk/src/AgentDispatchClient.ts | livekit-api/livekit/api/agent_dispatch_service.py | docs/index.yamlcareful-iron-56445
10/24/2025, 10:53 AMtall-airline-16756
10/24/2025, 10:53 AMfrom livekit import api
lkapi = api.LiveKitAPI()
dispatch = await lkapi.agent_dispatch.create_dispatch(
api.CreateAgentDispatchRequest(
agent_name="agent_name_here",
room="room_name_here",
metadata="my_metadata"
)
)
◦ To remove the agent from the room: await lkapi.agent_dispatch.delete_dispatch(dispatch_id="dispatch_id_here", room_name="room_name_here")
1. Dispatch Agent via Access Token:
◦ To set up the agent to join automatically when a participant connects: from livekit import api
room_config = api.RoomConfiguration(
agents=[
api.RoomAgentDispatch(
agent_name="agent_name_here",
metadata="my_metadata"
)
]
)
1. Agent Exit Behavior:
◦ To define custom behavior when the agent leaves: async def on_exit(self):
await self.session.say("Goodbye!")
If you have any questions or would like me to walk you through these examples in more detail, please don’t hesitate to ask. I’m here to help!