How can i give names to agents that are joining a ...
# ask-ai
f
How can i give names to agents that are joining a livekit meet? I am using the CLI command connect to connect the agent to a specific room. i tried using the ctx.agent.set_name command but this is not working as my agent is getting named simulated_Agent_277ys random names like this
t
Thanks for reaching out, Alexander. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To assign a custom name to an agent joining a LiveKit room, you’ll want to set the
agent_name
field directly in the agent’s code. This isn’t something that can be done through the
connect
CLI command, but don’t worry—I’m here to help you through it! Here’s a simple way to set the agent name: 1. Update the agent’s entry point code. 2. Add the
agent_name
parameter inside the
WorkerOptions
when you call
cli.run_app()
. For example, in Python:
Copy code
if __name__ == "__main__":
    cli.run_app(
        WorkerOptions(
            entrypoint_fnc=entrypoint,
            agent_name="custom-agent-name", 
        ),
    )
Once you’ve named your agent, you can easily dispatch it to rooms using the LiveKit API or other approaches. If you have any questions or need a hand with this setup, just let me know—I’m happy to assist! Sources: Dispatching agents | LiveKit Docs | Accepting incoming calls | LiveKit Docs | Accepting incoming calls | LiveKit Docs | examples/agent_dispatch.py | Making calls using SIP | LiveKit Docs
f
already have done this
t
Could you please check if the
agent_name
parameter is set correctly in the
WorkerOptions
? Also, it would be great to confirm if the agent is being dispatched explicitly to the room. If you’ve noticed any errors or logs during the agent’s connection process, sharing those would really help us get to the bottom of this together!
f
Copy code
if __name__ == "__main__":
    # Run the CLI worker - it will automatically handle dispatch requests from LiveKit API
    cli.run_app(WorkerOptions(
        agent_name="interviewer",
        prewarm_fnc=prewarm,
        entrypoint_fnc=entrypoint
    ))
This is the main of my agent entry point script.
t
The
agent_name
in your script looks like it’s set correctly, which is great! Let’s explore a few possible reasons why the agent might still be receiving random names, just to make sure everything is on track: 1. Mismatch in Agent Name Configuration: It’s important to double-check that the
agent_name
matches exactly in both the
WorkerOptions
and any dispatch rules or API calls you’re using to assign the agent to a room. 2. Automatic Dispatch Still Enabled: Keep in mind that setting
agent_name
actually disables automatic dispatch. This means the agent will only join rooms if they’re explicitly dispatched through the
AgentDispatchService
API. 3. Incorrect Dispatch Method: Make sure you’re using the
AgentDispatchService.create_dispatch()
method to explicitly dispatch the agent to a room. Also, verify that both the
agent_name
and room name are correct. 4. Environment or Credential Issues: It’s a good idea to confirm that the worker has the right credentials (
apiKey
,
apiSecret
,
wsURL
) to register properly with the LiveKit server. 5. Worker Not Running or Registered: Lastly, please ensure the worker is actively running and connected to the LiveKit server. If the worker isn’t started or loses connection, the
agent_name
won’t be recognized. I hope these pointers help! Please feel free to check these areas, and don’t hesitate to reach out if the issue continues or if you’d like me to walk through anything together. I’m here to help! Sources: SIP troubleshooting guide | LiveKit Docs | Dispatching agents | LiveKit Docs | Agent dispatch | LiveKit Docs | agents/src/worker.ts
f
Copy code
script_name = f"{agent_type}_worker.py"
    return subprocess.Popen([
        sys.executable,
        str(current_dir / script_name),
        "connect",
        "--room", room_name,
        #        "--participant-identity", agent_type,
    ])
This is how i am running this script. so for interviewer it will be like
python3 interviewer_worker.py connect --room 23r4-s4j5
t
The
agent_name
set in
WorkerOptions
is actually respected and not ignored when you use CLI commands like
connect
. However, it’s important to note that the
connect
command by itself doesn’t automatically send the agent to a room unless you have explicit dispatch set up. To make sure your agent joins the room with the right name, here are a few friendly steps you can follow: 1. Double-check that the
agent_name
in your
WorkerOptions
matches the name used in any dispatch rules or API calls. 2. Use the
AgentDispatchService.create_dispatch()
method to explicitly dispatch your agent to the room. 3. Make sure your worker is running with the correct credentials and is properly connected to the LiveKit server. If you’re running the
connect
command directly, it might not trigger the dispatch logic needed for named agents. Please feel free to reach out if you’d like me to walk you through this or if you have any other questions—I’m here to help! Sources: livekit-agents/livekit/agents/worker.py | agents/src/worker.ts | Making calls using SIP | LiveKit Docs | Making calls using SIP | LiveKit Docs | Agents telephony integration | LiveKit Docs