would like to know if we can set the name of agent...
# ask-ai
b
would like to know if we can set the name of agent that has been created for explicit dispatch. I tried several ways but could never set its name.
t
Thanks for reaching out, Suba. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to help you with setting the name of an agent created for explicit dispatch! You can do this by specifying the
agent_name
field in the
WorkerOptions
when defining the agent. This is a great way to enable explicit dispatch, which means the agent won't be automatically assigned to rooms. Instead, you can manually assign the agent to rooms through the API, participant token configuration, or SIP dispatch rules. Here’s a simple example in Python to get you started:
Copy code
opts = WorkerOptions(
    entrypoint_fnc=entrypoint,
    agent_name="test-agent"
)
And if you’re working with Node.js, it looks like this:
Copy code
const opts = new WorkerOptions({
    entrypoint_fnc: entrypoint,
    agentName: "test-agent"
});
Once you’ve set the
agent_name
, just keep in mind that the agent won’t be automatically dispatched to new rooms. You’ll need to explicitly dispatch them using one of the supported methods. If you have any questions or need further guidance, feel free to ask—I’m here to help! Sources: Dispatching agents | LiveKit Docs | Agent dispatch | LiveKit Docs | Agents telephony integration | LiveKit Docs | Making calls using SIP | LiveKit Docs | Accepting incoming calls | LiveKit Docs
b
I am using python
t
Since you're using Python, you can easily set the agent name by specifying the
agent_name
field in the
WorkerOptions
. Here's a simple example to guide you:
Copy code
opts = WorkerOptions(
    entrypoint_fnc=entrypoint,
    agent_name="test-agent"
)
Just replace
"test-agent"
with the name you'd like for your agent. If you have any questions or need a hand with this, feel free to reach out—I'm here to help!
b
so will this reflect in the UI?
t
Hi there! I wanted to share a little insight about the
agent_name
set in
WorkerOptions
. It doesn’t show up directly in the LiveKit UI as the agent's visible name; instead, it’s used behind the scenes for dispatch control and routing. If you'd like the agent’s name to be visible in the UI, you’ll want to set it explicitly when the agent joins a room. For example, when accepting a job, you can do this:
Copy code
await req.accept(name="Call Agent")
The
name
parameter here is what determines the participant’s visible name in the room. If you have any questions or want me to walk you through it further, just let me know—I’m here to help! Sources: Worker options | LiveKit Docs | Agents telephony integration | LiveKit Docs
b
no I meant the dashboard of livekit
t
I wanted to share a little insight about the
agent_name
set in
WorkerOptions
. It’s mainly used for explicit dispatch and is accessible internally or through the API. That said, I’m not entirely sure if this name shows up in the LiveKit dashboard UI, so it might be a good idea to take a quick look there to confirm. If you have any more questions or if there’s anything else you’d like help with, please don’t hesitate to reach out—I’m here for you! Sources: Dispatching agents | LiveKit Docs | livekit-agents/livekit/agents/worker.py
b
I have configured the name and it's getting displayed in live kit UI successfully. however when I mention the agent name in sandbox option for explicit dispatch, it always sends the other agent in the project
t
I'm here to help you resolve the issue with the wrong agent being dispatched, even after specifying the
agent_name
. Let's go through a few important points together: 1. Exact Match: Please make sure the
agent_name
set in
WorkerOptions
exactly matches the name used in your dispatch request. Remember, agent names are case-sensitive, so even small differences matter. 2. Unique Agent: It's important that only one agent worker is registered with the specified
agent_name
. If multiple agents share the same name, the system might dispatch any one of them, which could cause confusion. 3. Correct Dispatch Method: Double-check that you're using the right dispatch method, like API or CLI, and that the
agent_name
is specified properly. For example, in Python, it looks like this:
Copy code
dispatch = await lkapi.agent_dispatch.create_dispatch(
    api.CreateAgentDispatchRequest(
        agent_name="test-agent",
        room="my-room"
    )
)
1. Automatic Dispatch Disabled: Please verify that automatic dispatch is turned off for the agent to avoid conflicts. 2. Room Name: Ensure the room name in your dispatch request matches exactly the room you intend to use. 3. Check for Typos: It’s always good to double-check there are no typos or case mismatches in the
agent_name
. If you continue to experience this issue, it might help to check the running agent instances and logs to see which agents are registered and receiving dispatch requests. Feel free to reach out if you want me to guide you through those steps or if there’s anything else I can assist you with! Sources: Agent dispatch | LiveKit Docs | livekit-api/livekit/api/agent_dispatch_service.py
b
how to check below point? 1. Automatic Dispatch Disabled: Please verify that automatic dispatch is turned off for the agent to avoid conflicts.
t
Hi there! To check if automatic dispatch is turned off for an agent, you can take a look at the agent's
WorkerOptions
configuration. When the
agent_name
field is set, it means automatic dispatch is disabled. Here’s a quick example in Python:
Copy code
opts = WorkerOptions(
    entrypoint_fnc=entrypoint,
    agent_name="my-telephony-agent"
)
So, if you see the
agent_name
set, automatic dispatch won’t happen automatically. Instead, the agent will need to be dispatched manually through the API, SIP rules, or participant tokens. If you have any questions or want me to walk you through it, just let me know—I’m here to help! Sources: Agent dispatch | LiveKit Docs | Agents telephony integration | LiveKit Docs | Dispatching agents | LiveKit Docs
b
I named the agent. but get below in logs when starting a call: {"message": "failed to connect to livekit, retrying in 0s", "level": "WARNING", "name": "livekit.agents", "exc_info": "Traceback (most recent call last):\n File \"/app/.venv/lib/python3.13/site-packages/livekit/agents/worker.py\", line 689, in _connection_task\n await self._run_ws(ws)\n File \"/app/.venv/lib/python3.13/site-packages/livekit/agents/worker.py\", line 770, in _run_ws\n await asyncio.gather(*tasks)\n File \"/app/.venv/lib/python3.13/site-packages/livekit/agents/worker.py\", line 742, in _recv_task\n raise Exception(\"worker connection closed unexpectedly\")\nException: worker connection closed unexpectedly", "timestamp": "2025-09-20T234632.475636+00:00"}
t
I'm sorry to hear you're encountering the errors "failed to connect to livekit, retrying" and "worker connection closed unexpectedly." These usually happen because of connectivity, authentication, or server-side issues. Let’s work through some steps together to help you resolve this: 1. Check Authentication: Please double-check that the API key and secret you're using for the agent are correct and still valid. 2. Verify WebSocket URL: Make sure the WebSocket URL in your configuration is accurate and properly set. 3. Network Connectivity: It’s a good idea to look into any network issues that might be affecting the connection, like firewalls or VPNs that could be blocking access. 4. Server Logs: Take a look at the LiveKit server logs for errors such as
HandshakeAgentWorker
or
DispatchAgentWorkerSignal
. These can give clues about authentication or connection hiccups. 5. Connection Test: Try using the Connection Test utility to check your WebSocket, WebRTC, and TURN server connectivity to the LiveKit servers. 6. Worker Load: Also, ensure the worker isn’t overloaded and is operating within the configured thresholds. If you’d like, I’m here to help you through any of these steps or answer any questions you might have. Just let me know! Sources: livekit-protocol/src/livekit.rs | protobufs/livekit_models.proto | livekit-rtc/livekit/rtc/_proto/participant_pb2.pyi | pkg/service/agentservice.go | livekit-agents/livekit/agents/_exceptions.py
b
the problem is, the agent is not joining room if the name is set in worker options. I have set the agent name in sandbox options for explicit dispatch.
t
I'd love to help you get this sorted out! Could you please share a bit more information with me? • Are you seeing any specific error messages or logs when the agent has trouble joining the room? • Have you checked that the
agent_name
in
WorkerOptions
exactly matches the name used in the sandbox options for explicit dispatch? • Is the room name entered correctly in the dispatch request? Having these details will really help us figure out what's going on together.
b
• Is the room name entered correctly in the dispatch request? how to check this?
t
Let's make sure the room name is correctly specified in your dispatch request. You can easily check this by using the
listDispatch
method from the
AgentDispatchClient
. This handy method will fetch all dispatches for a particular room and help confirm if the dispatch was created with the right room name. Here's a simple example in TypeScript to guide you:
Copy code
const agentDispatchClient = new AgentDispatchClient(
  process.env.LIVEKIT_URL,
  process.env.LIVEKIT_API_KEY,
  process.env.LIVEKIT_API_SECRET
);

const roomName = 'my-room';
const dispatches = await agentDispatchClient.listDispatch(roomName);
console.log(`There are ${dispatches.length} dispatches in ${roomName}`);
If the room name is spot on, you’ll see a list of dispatches returned. Feel free to reach out if you have any questions or need a hand with this! Sources: Agents telephony integration | LiveKit Docs | packages/livekit-server-sdk/src/AgentDispatchClient.ts | Dispatching agents | LiveKit Docs | Agent dispatch | LiveKit Docs
b
I am using the default sandbox in livekit. below is the agent code for session creation in agent.py. should we mention anything here ? await session.start( agent=Assistant(), room=ctx.room, _room_input_options_=RoomInputOptions( # LiveKit Cloud enhanced noise cancellation # - If self-hosting, omit this parameter # - For telephony applications, use
BVCTelephony
for best results
_noise_cancellation_=noise_cancellation.BVC(), ), )
t
In the default sandbox, agents are automatically dispatched unless you set an
agent_name
in
WorkerOptions
. If you'd like to use explicit dispatch, here’s what you can do: 1. Set the
agent_name
in
WorkerOptions
to disable automatic dispatch. For example:
Copy code
cli.run_app(agents.WorkerOptions(
    entrypoint_fnc=entrypoint,
    agent_name="my-agent"
))
1. Then, use an explicit dispatch method, like the
AgentDispatchService
API, to assign the agent to a room. For example:
Copy code
await lkapi.agent_dispatch.create_dispatch(
    api.CreateAgentDispatchRequest(
        agent_name="my-agent",
        room="my-room"
    )
)
Also, just a heads-up: the
session.start
method in
agent.py
kicks off the agent's session after dispatch—it doesn’t handle the dispatch itself. So, please make sure the room name (
ctx.room
) is correctly passed to
session.start
. If anything’s unclear or you’d like a hand with this, feel free to reach out—I’m here to help! Sources: Authentication | LiveKit Docs | agent.py | Agent dispatch | LiveKit Docs | Dispatching agents | LiveKit Docs | Agents telephony integration | LiveKit Docs
b
where should I add this code? await lkapi.agent_dispatch.create_dispatch( api.CreateAgentDispatchRequest( agent_name="my-agent", room="my-room" ) )
t
I'd love to help you out! Could you please share a bit more about where exactly in your application flow you'd like the agent to be dispatched? For instance: • Would you want the agent to be dispatched when a specific event happens, like when a user joins a room or a call starts? • Are there any triggers or conditions you're using to decide when the agent should join a room? Knowing these details will really help us find the perfect spot to add the
create_dispatch
API call for you.
b
I am using the default sandbox in live kit. want the specific agent to be dispatched when a user joins the room
t
When a user joins a room in the default sandbox, you can easily dispatch a specific agent by adding the
create_dispatch
API call right where your application handles the user joining the room. This way, the agent will be sent directly to that room, making the process smooth and clear. Here’s a simple example of how you might do this in the event handler or function that deals with a user joining:
Copy code
async def on_user_join(room_name):
    await lkapi.agent_dispatch.create_dispatch(
        api.CreateAgentDispatchRequest(
            agent_name="my-agent",
            room=room_name
        )
    )
    print(f"Agent 'my-agent' dispatched to room {room_name}")
Just swap out
on_user_join
with the actual function or event handler you’re using for user room joins. If you have any questions or want to walk through this together, I’m here to help!
b
I only have sandbox, no other application
t
I understand you're working with the default sandbox in LiveKit, and I’m here to help you with explicit dispatch. You can still achieve this by manually triggering the
create_dispatch
API call. Since there’s no external application involved, you can simply run this API call through a script or tool whenever you want to dispatch an agent to a room. Here’s a friendly example in TypeScript to guide you:
Copy code
const agentDispatchClient = new AgentDispatchClient(
  process.env.LIVEKIT_URL,
  process.env.LIVEKIT_API_KEY,
  process.env.LIVEKIT_API_SECRET
);

const roomName = 'my-room';
const agentName = 'my-agent';

await agentDispatchClient.createDispatch(roomName, agentName);
console.log(`Agent ${agentName} dispatched to room ${roomName}`);
Feel free to run this script whenever you need to dispatch your agent. And of course, if you have any questions or need a hand with anything else, just let me know—I’m here to help!
b
can you send python code
t
Thanks for reaching out! Right now, the
create_dispatch
API call is definitely available in TypeScript. However, the documentation doesn’t clearly confirm if it’s directly supported in Python just yet. If you’re working with Python, a good approach might be to look at the TypeScript example and see if you can adapt it to your setup—especially if the Python SDK offers similar features. If you have any questions or need a hand with this, please don’t hesitate to ask. I’m here to help!