wonderful-account-72949
09/12/2025, 9:24 AMconst agentDispatchClient = new AgentDispatchClient(
env.LIVEKIT_URL,
env.LIVEKIT_API_KEY,
env.LIVEKIT_API_SECRET
);
// Check if there are already active dispatches for this room
const existingDispatches = await agentDispatchClient.listDispatch(
roomName
);
console.log(
`Found ${existingDispatches.length} existing dispatches in ${roomName}`
);
// Filter for active dispatches (not completed or failed)
// Note: Using any type temporarily until we confirm the exact properties
const activeDispatches = existingDispatches.filter(
(dispatch: any) =>
dispatch.status === "pending" || dispatch.status === "running"
);
if (activeDispatches.length > 0) {
console.log(
`Agent already dispatched to room ${roomName}, skipping duplicate dispatch`
);
return {
message: "Agent already dispatched to this room",
existingDispatches: activeDispatches.length,
skipped: true,
};
}
// create a dispatch request for an agent named "local-agent" to join the room
const dispatch = await agentDispatchClient.createDispatch(
roomName,
"local-agent",
{
metadata: '{"user_id": "12345"}',
}
);
console.log("created dispatch", dispatch);
const dispatches = await agentDispatchClient.listDispatch(roomName);
console.log(`there are ${dispatches.length} dispatches in ${roomName}`);
tall-airline-16756
09/12/2025, 9:24 AMtall-airline-16756
09/12/2025, 9:25 AMagent_name
. This method turns off automatic dispatch and lets you decide exactly which agent gets assigned to a room.
Here’s a simple way to set it up:
• Give a unique agent_name
in your WorkerOptions
to disable automatic dispatch for that particular worker.
• Then, explicitly send the agent to the room you want using the AgentDispatchService
API. For example:
const dispatch = await agentDispatchClient.createDispatch(
roomName,
"my-unique-agent",
{
metadata: '{"user_id": "12345"}',
}
);
console.log("Agent dispatched:", dispatch);
By doing this, you’ll make sure that only the agent you specify joins the room, which helps prevent multiple agents from showing up and stops those overlapping AI voices. If you have any questions or want to walk through this together, I’m here to help!
Sources: Dispatching agents | LiveKit Docs | Agent dispatch | LiveKit Docswonderful-account-72949
09/12/2025, 9:25 AMconst dispatch = await agentDispatchClient.createDispatch(
roomName,
"local-agent",
{
metadata: '{"user_id": "12345"}',
}
);
tall-airline-16756
09/12/2025, 9:26 AM