I have one kind of agent working, and would like t...
# ask-ai
b
I have one kind of agent working, and would like to have another, created using a different agent_name. Should that go in a separate Python file? Does the filename matter?
✅ 1
t
Thanks for reaching out, Mat. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — good question. You're free to put multiple agents in the same Python file or split them across files; the filename does not affect agent behavior. LiveKit identifies agents by the
agent_name
you set in the
@server.rtc_session
decorator, so each agent just needs a unique
agent_name
for dispatch. If helpful, quick guidance: • For small projects or closely related agents, keeping them in one file is fine. • For clarity and maintainability, split agents into separate files (modules) by responsibility. • Ensure your dispatch/entry logic references the correct
agent_name
. If you'd like, share a snippet of your current code and your planned agent responsibilities and I can suggest a concrete file layout. Sources: Avoiding crosstalk when multiple developers share a LiveKit project | LiveK... | Agent dispatch | LiveKit Documentation, with interactive elements
b
If I have two agents, in separate Python files, how should I structure the folders where I keep them? I would like to be able to create/dispatch/test each type of agent separately.
t
Thanks — I’m responding to your question about folder structure for two agents in separate Python files and how to create/dispatch/test each independently. Recommended layout (modular and testable)
Copy code
project/
├── agents/
│   ├── __init__.py
│   ├── agent_server.py          # shared AgentServer / server instance
│   ├── intake/
│   │   ├── __init__.py
│   │   ├── agent.py             # @server.rtc_session(agent_name="intake-agent")
│   │   └── test.py              # local/console tests for intake agent
│   └── billing/
│       ├── __init__.py
│       ├── agent.py             # @server.rtc_session(agent_name="billing-agent")
│       └── test.py              # local/console tests for billing agent
├── dispatch_rules.yaml         # optional: mapping agent_name -> rules
└── pyproject.toml / requirements.txt
Key points and practices • Use one shared
AgentServer
(or server instance) defined in
agent_server.py
and import it into each
agent.py
. Agents are identified by their
agent_name
in
@server.rtc_session(...)
, not by filename. • Keep each agent’s logic and tests inside its own folder to allow independent development and clear responsibilities. • For local testing, run the per-agent test script or use console mode to exercise the agent without LiveKit dispatch. • For dispatching, specify the exact
agent_name
when creating tokens or routing so jobs go to the correct agent handler. • Use env vars or CLI flags in
test.py
to control which agent runs in dev, and deploy multiple workers with the same
agent_name
for production scale. If you want, share your current repo layout or one agent’s
agent.py
and I’ll suggest a concrete refactor and a sample
test.py
you can run locally. Sources: Build Your First AI Voice Agent in Python: Complete Tutorial | LiveKit | Agents and handoffs | LiveKit Documentation | Avoiding crosstalk when multiple developers share a LiveKit project | LiveK... | Avoiding crosstalk when multiple developers share a LiveKit project | LiveK... | Agents Framework | livekit/livekit_composite | DeepWiki, with interactive elements