I created an agent but it doesn't have a name, how...
# ask-ai
s
I created an agent but it doesn't have a name, how to set the agent name?
✅ 1
t
Thanks for reaching out, Stanislas. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I can help with that. You're asking how to set a name for an agent you created. • For Python agents using the server decorator, add
agent_name
to `@server.rtc_session()`:
Copy code
@server.rtc_session(agent_name="my-agent")
  async def my_agent(ctx: JobContext):
      ...
This makes the agent use explicit dispatch (it will only join rooms when requested). • For Node.js, set
agentName
in
ServerOptions
when creating the agent (use your code's server options object). • If you used the Agent Builder UI, the name is set in the UI when creating/editing the agent. Changing it after deployment can affect dispatch rules. Tip: In dev environments, append a developer-specific suffix (via env var) so names stay unique across runs. If you tell me whether you’re using Python, Node, or the Agent Builder UI, I’ll give the exact code or UI steps for your case. Sources: Agent dispatch | LiveKit Documentation | Build Your First AI Voice Agent in Python: Complete Tutorial | LiveKit | Avoiding crosstalk when multiple developers share a LiveKit project | LiveK... | Agent Builder | LiveKit Documentation, with interactive elements
s
I am using python, agent's main is: if name == "__main__": logger.info("Starting LiveKit agent application") agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))
t
Thanks — I can help with that. You're using Python and running the agent with
agents.cli.run_app(...)
, so set the agent name on your entrypoint using the
@server.rtc_session()
decorator. Example:
Copy code
from livekit import agents

server = agents.AgentServer()

@server.rtc_session(agent_name="my-agent")
async def entrypoint(ctx: agents.JobContext):
    # your agent logic
    ...
    
if __name__ == "__main__":
    logger.info("Starting LiveKit agent application")
    agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))
Notes: •
agent_name
must be set on the
rtc_session
decorator —
WorkerOptions
does not set the agent dispatch name. • Setting
agent_name
enables explicit dispatch (the agent only joins rooms when requested by that name). If you want, tell me the agent name you want and I’ll show how to add a dev suffix via an env var for unique names in development. Sources: Tavus virtual avatar integration guide | LiveKit Documentation | Agent dispatch | LiveKit Documentation | Server options | LiveKit Documentation | OpenAI and LiveKit partner to turn Advanced Voice into an API | LiveKit, with interactive elements
s
I am deploying the same code to 2 different agents (one for prod and one for staging) inside the the same livekit project, can I pass the agent name as a variable to lk agent deploy toml config?
t
Thanks — I’m replying about whether you can pass the agent name as a variable in the
livekit.toml
/
lk agent deploy
flow. You cannot pass or template the agent name via
livekit.toml
or
lk agent deploy
. Agent dispatch names are set in code (Python:
@server.rtc_session(agent_name=...)
) and are not configurable from the TOML deploy file. Two practical options: • Set the name in code from an env var so the same code deploys with different names:
Copy code
import os
  AGENT_NAME = f"my-agent-{os.getenv('ENV', 'dev')}"
  server = agents.AgentServer()

  @server.rtc_session(agent_name=AGENT_NAME)
  async def entrypoint(ctx: agents.JobContext):
      ...
• Use separate LiveKit projects for prod vs staging to fully isolate agents/rooms/config. Which approach do you prefer (env var naming or separate projects)? I can give exact deploy steps for that option. Sources: Build Your First AI Voice Agent in Python: Complete Tutorial | LiveKit | Agent dispatch | LiveKit Documentation | Avoiding crosstalk when multiple developers share a LiveKit project | LiveK..., with interactive elements
s
env var naming
t
Great — below is a concise pattern to set the agent name from an environment variable in Python, plus examples for common deployment methods. Code (use in your agent module):
Copy code
import os
from livekit import agents

ENV = os.getenv("ENV", "dev")            # e.g. "prod" or "staging"
BASE_AGENT_NAME = "my-agent"
AGENT_NAME = f"{BASE_AGENT_NAME}-{ENV}"  # my-agent-prod or my-agent-staging

server = agents.AgentServer()

@server.rtc_session(agent_name=AGENT_NAME)
async def entrypoint(ctx: agents.JobContext):
    # agent logic
    ...
How to set the env var when deploying: • Docker: docker run -e ENV=staging your-image • Kubernetes: add env var to the Pod spec (env: - name: ENV value: "prod") • lk agent deploy (container image): ensure the container image reads ENV from the environment you provide in your deployment pipeline or container runtime • Local/.env: export ENV=staging or use a .env loader in dev Notes: • The agent name must still be set in code via `agent_name`; TOML cannot parameterize it. • Choose unique names per environment to avoid dispatch crosstalk (e.g.,
my-agent-prod
,
my-agent-staging
). Would you like an example Dockerfile, Kubernetes manifest snippet, or exact lk deploy snippet for your CI pipeline? , with interactive elements