aloof-scooter-47164
09/19/2025, 6:55 AMtall-airline-16756
09/19/2025, 6:55 AMtall-airline-16756
09/19/2025, 6:56 AMaloof-scooter-47164
09/19/2025, 5:59 PMtall-airline-16756
09/19/2025, 6:00 PMagentName in the WorkerOptions. This way, the agent will only join when you explicitly dispatch them.
2. Manually Dispatch the Agent: Next, use the AgentDispatchClient to manually dispatch the agent to the room. This method makes sure only one instance of that agent joins the room. Here’s an example in Node.js:
const agentDispatchClient = new AgentDispatchClient(
process.env.LIVEKIT_URL,
process.env.LIVEKIT_API_KEY,
process.env.LIVEKIT_API_SECRET
);
const dispatch = await agentDispatchClient.createDispatch(
"my-room",
"my-agent",
{ metadata: '{"user_id": "12345"}' }
);
console.log("Agent dispatched:", dispatch);
3. Enforce Uniqueness: Before you dispatch, it’s a good idea to check if the agent is already dispatched by using listDispatch(roomName). If you find an existing instance, you can skip or cancel the new dispatch to avoid duplicates:
const dispatches = await agentDispatchClient.listDispatch("my-room");
const existing = dispatches.find(d => d.agentName === "my-agent");
if (!existing) {
await agentDispatchClient.createDispatch("my-room", "my-agent");
}
This approach will help ensure that only one agent of the specified kind can join your room at any given time. If you have any questions or need more help, please don’t hesitate to ask—I’m here to support you!
Sources: Dispatching agents | LiveKit Docs | packages/livekit-server-sdk/src/AgentDispatchClient.ts | examples/agent_dispatch.py | Agent dispatch | LiveKit Docs