aloof-scooter-47164
09/05/2025, 2:11 AMtall-airline-16756
09/05/2025, 2:11 AMtall-airline-16756
09/05/2025, 2:11 AMagent_name when you register them via WorkerOptions. This turns off automatic dispatch, so the agent only joins rooms when you tell them to.
Also, before you create a new dispatch, you can check if that agent is already dispatched using the listDispatch method in the AgentDispatch service. Here’s a quick example:
const dispatches = await agentDispatchClient.listDispatch(roomName);
const existing = dispatches.find(d => d.agentName === agentName);
if (!existing) {
await agentDispatchClient.createDispatch(roomName, agentName);
} else {
console.log("Agent is already dispatched to this room");
}
This little check helps keep things neat by preventing duplicate agents from showing up in the same room. Hope this helps!
Sources: src/test/kotlin/io/livekit/server/AgentDispatchServiceClientTest.kt | pkg/rtc/room.go | Dispatching agents | LiveKit Docs | Agent dispatch | LiveKit Docs | Agents telephony integration | LiveKit Docsaloof-scooter-47164
09/05/2025, 2:14 AMtall-airline-16756
09/05/2025, 2:15 AMctx.shutdown() to make sure everything tidies up nicely and no stale states hang around.
2. Check Existing Dispatches: Use the listDispatch method to see if the agent is already dispatched to the room. If they’re not, then it’s time to re-dispatch.
3. Re-Dispatch the Agent: Create a new dispatch request with createDispatch. Here’s a quick example:
const dispatches = await agentDispatchClient.listDispatch(roomName);\nconst existing = dispatches.find(d => d.agentName === agentName);\nif (!existing) {\n await agentDispatchClient.createDispatch(roomName, agentName);\n} else {\n console.log("Agent is already dispatched to this room");\n}
Also, if you want to make things even smoother, you can embed the agent dispatch right into the participant’s access token. That way, the agent automatically rejoins whenever the participant reconnects.
If you have any questions or want a hand setting this up, just let me know—I’m here to help!
Sources: Inside a session | LiveKit Docs | Job lifecycle | LiveKit Docs | Recording agent sessions | LiveKit Docs | packages/livekit-server-sdk/src/AgentDispatchClient.ts | pkg/rtc/room.go