Hey, I've seen that when agents are deployed in li...
# ask-ai
s
Hey, I've seen that when agents are deployed in livekit cloud an "id" is created but they have no "name". How do I add a name to them so that I can easily recognize which one it is? Also, if I want to dispatch a job. How do I specify which agent should receive it?
t
Thanks for reaching out, Roman. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to both parts of your question: how to give agents a readable name, and how to dispatch a job to a specific agent. Short answer • Give an agent a name by setting
agent_name
in the agent code (this is not set in the LiveKit Cloud UI). • After naming an agent, dispatch jobs explicitly to that name via the CLI, API, or by embedding the dispatch in a participant token. How to add a name to an agent • The agent’s human-friendly name is set in your agent code using the
agent_name
parameter (it’s not added from the Cloud UI). • Example patterns: ◦ Python:
@server.rtc_session(agent_name="my-telephony-agent")
◦ Node.js:
new ServerOptions({ agentName: "my-telephony-agent" })
• Important: setting
agent_name
disables automatic dispatch for that agent. The agent will only be assigned via explicit dispatch. How to specify which agent receives a dispatched job • Once the agent has a name, you can target it explicitly: 1. CLI ◦ Example:
Copy code
lk dispatch create \
       --agent-name my-telephony-agent \
       --room my-room \
       --metadata '{"user_id":"12345"}'
1. API (programmatic) ◦ Python example:
Copy code
dispatch = await lkapi.agent_dispatch.create_dispatch(
         api.CreateAgentDispatchRequest(
             agent_name="my-telephony-agent",
             room="my-room",
             metadata='{"user_id":"12345"}'
         )
     )
• Node.js example (similar parameters via SDK client). 1. Dispatch on participant join (token-based) ◦ Embed the agent dispatch in the participant’s token so the agent is dispatched automatically when the participant joins: ▪︎ Example flow: include a
RoomConfiguration
with
agents=[RoomAgentDispatch(agent_name="my-telephony-agent")]
in the token generation step. Additional notes • The Cloud-created “id” you see for deployments is the deployment slot identifier;
agent_name
is the logical identifier you use for routing and recognition. • You can give the same
agent_name
to multiple agent instances for load distribution — dispatching to that name will be balanced across instances that share it. If you want, tell me: • Which language/runtime you’re using (Python or Node.js) and I’ll provide a copy-paste snippet for your agent and for creating a dispatch in that language. • Whether you want dispatch triggered from the server (CLI/API) or embedded in participant tokens, and I’ll show the exact steps. Sources: Agent dispatch | LiveKit Documentation
s
but the question is, if the name is added in the code how can I have a "dev" agent and a "prod" agent? I should be able to deploy 2 diferent instances with the same code
t
You're right — you should be able to run the same code for both dev and prod and have each instance use a different agent name. The simplest and recommended approach is to set
agent_name
dynamically at runtime using deployment-specific configuration rather than hard-coding it. Quick options • Use an environment variable (most common). • Use a config file specific to each deployment. • Pass the name as a startup/CLI flag from your deployment system. How that looks in practice 1) Environment variable (recommended) • Set an env var in each deployment: e.g.,
AGENT_NAME=dev-agent
for your dev deployment and
AGENT_NAME=prod-agent
for production. • Read that env var when you initialize the agent. Example patterns: • Python:
Copy code
import os

  AGENT_NAME = os.getenv("AGENT_NAME", "default-agent")

  @server.rtc_session(agent_name=AGENT_NAME)
  async def my_agent(ctx: JobContext):
      ...
• Node.js:
Copy code
const agentName = process.env.AGENT_NAME || "default-agent";
  const opts = new ServerOptions({ agentName });
2) Config file or secrets manager • Keep environment-specific config (JSON/YAML) or use your secrets manager. Load the config at startup and pass the value into the same
agent_name
parameter. 3) Startup flag from deploy tooling • If your orchestrator (Kubernetes, Docker compose, CI/CD) supports startup args, pass the agent name as a flag and consume it in your app. Important behavior to remember • When you set
agent_name
, the agent is only assigned via explicit dispatch. That means you must dispatch to
dev-agent
or
prod-agent
explicitly (CLI, API, or token-based dispatch). • You can deploy multiple instances with the same
agent_name
for load balancing, or use unique names per instance if you need exact targeting. Next step Which runtime are you using (Python or Node.js) and how do you deploy (Docker, Kubernetes, Vercel, etc.)? I’ll give a copy-paste snippet and an example deploy config for your environment.