how to setup agent_name in voice bot agentsession ...
# ask-ai
f
how to setup agent_name in voice bot agentsession which matches dispatch rule which is connected to sip trunk for inbound calling?
t
Thanks for reaching out, Viren. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to make a voice bot's agent match a dispatch rule tied to a SIP trunk for inbound calls — specifically how to set the agent name so the dispatch rule routes the call to that agent. Below are the exact steps to do that. 1. Register the agent with an explicit agent name at the agent server entrypoint • Use the
agent_name
parameter on the
@rtc_session
decorator (or equivalent agent registration) when you define the agent entrypoint. This ties the running agent to a specific dispatch name. Example (Python):
Copy code
@server.rtc_session(agent_name="my-telephony-agent")
  async def entrypoint(ctx: JobContext):
      session = AgentSession(...)
      await session.start(ctx.room, agent=Agent(instructions="You are a helpful assistant."))
1. Create a dispatch rule that references the same agent name • The dispatch rule’s
room_config
must list the same
agentName
used above so incoming SIP calls dispatch that named agent into the room. Example dispatch JSON:
Copy code
{
  "dispatch_rule": {
    "roomConfig": {
      "agents": [
        {
          "agentName": "my-telephony-agent"
        }
      ]
    }
  }
}
• Apply the rule (CLI/API) so LiveKit will create the room and dispatch that named agent on inbound calls. 1. Ensure your SIP trunk / inbound number is configured • Confirm your inbound trunk or phone number is linked in LiveKit so incoming calls evaluate dispatch rules and create rooms accordingly. Call flow summary: • Inbound SIP call → LiveKit identifies the dispatch rule for that trunk/number → room is created → dispatch rule requests agent named "my-telephony-agent" → agent registered with
@rtc_session(agent_name="my-telephony-agent")
joins the room and runs its AgentSession. Key notes: •
agent_name
is set at the agent registration (
rtc_session
), not on
AgentSession
itself. • The names must match exactly between the agent registration and the dispatch rule. • If you leave
agent_name
unset, agents may be auto-dispatched to all rooms (not recommended for telephony). If you want, tell me: • which language/runtime you’re using (Python, Node, etc.), and • a snippet of your current agent registration or dispatch rule —I can provide a tailored code example or check for mismatches. Sources: Agents telephony integration | LiveKit docs | Agent session | LiveKit docs | SIP dispatch rule | LiveKit docs | SIP trunk setup | LiveKit docs
f
can i pass agent_name like this? cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, agent_name='botverse_test_new'))
t
You're asking whether
agent_name
can be passed via
cli.run_app(WorkerOptions(..., agent_name='botverse_test_new'))
. That will not set the dispatchable agent name. Set the agent name on the agent registration entrypoint (the
@rtc_session
decorator or equivalent) so dispatch rules can match it. Example (Python):
Copy code
@server.rtc_session(agent_name="botverse_test_new")
async def entrypoint(ctx: JobContext):
    session = AgentSession(...)
    await session.start(ctx.room, agent=Agent(instructions="You are a helpful assistant."))
Keep
WorkerOptions(entrypoint_fnc=entrypoint)
for launching the worker; do not rely on passing
agent_name
there. If you share which runtime or current entrypoint code you have, I can show the exact change.
f
For inbound SIP calling, you do not need to match the
agent_name
with your dispatch rule. The agent name is independent of SIP dispatch rules
t
You’re asking whether
agent_name
must match the dispatch rule for inbound SIP calls. To be clear: if you want deterministic routing to a specific agent, the dispatch rule must reference the same
agent_name
that the agent registers with (via
@rtc_session(agent_name=...)
or equivalent). Quick points: • Set
agent_name
on the agent registration entrypoint (not via
WorkerOptions
). • Make the dispatch rule’s
roomConfig.agents[].agentName
exactly match that name. • If you don’t set an
agent_name
, agents may be auto-dispatched to rooms (default behavior), but that is non-deterministic and not recommended for telephony. If you want, share your entrypoint code and dispatch JSON (or tell me your runtime) and I’ll point out exactly what to change.
f
error: ImportError: cannot import name 'AgentServer' from 'livekit.agents'
t
You're seeing ImportError because
AgentServer
isn't exported from
livekit.agents
. Import it from the correct submodule and confirm your package version. 1) Use this import:
Copy code
from livekit.agents.server import AgentServer
2) Verify package and extras: • Install/upgrade LiveKit Agents 1.x and required extras:
Copy code
pip install --upgrade "livekit-agents[silero,turn-detector]"
3) Check for version mismatch • If you still get import errors, confirm which livekit-agents version is installed (
pip show livekit-agents
) and share it if you want help interpreting it. 4) Reminder about agent_name (since you're configuring telephony) • Set
agent_name
on the agent registration entrypoint (
@server.rtc_session(agent_name="...")
), not via
WorkerOptions
. • Ensure your dispatch rule's
roomConfig.agents[].agentName
exactly matches that name. If you share your current imports, installed package version, and entrypoint snippet, I’ll point out the exact change. Sources: Agents telephony integration | LiveKit docs | SIP dispatch rule | LiveKit docs | Voice AI quickstart | LiveKit docs
f
Name: livekit-agents Version: 1.2.2 Summary: A powerful framework for building realtime voice AI agents Home-page: Author: Author-email: LiveKit <hello@livekit.io> License: Location: d:\viren\projects\genai\genai_env\lib\site-packages Requires: aiohttp, av, click, colorama, docstring-parser, eval-type-backport, livekit, livekit-api, livekit-blingfire, livekit-protocol, nest-asyncio, numpy, opentelemetry-api, opentelemetry-exporter-otlp, opentelemetry-sdk, prometheus-client, protobuf, psutil, pydantic, pyjwt, sounddevice, types-protobuf, typing-extensions, watchfiles Required-by: livekit-plugins-aws, livekit-plugins-cartesia, livekit-plugins-deepgram, livekit-plugins-elevenlabs, livekit-plugins-google, livekit-plugins-groq, livekit-plugins-openai, livekit-plugins-silero, livekit-plugins-turn-detector
t
Thanks — your installed package looks fine (livekit-agents 1.2.2). Next steps to fix the import error and ensure dispatchable agent routing: 1. Use the correct import:
Copy code
from livekit.agents.server import AgentServer
1. Example minimal agent entrypoint (Python):
Copy code
from livekit.agents.server import AgentServer
from livekit.agents import AgentSession, Agent

server = AgentServer()

@server.rtc_session(agent_name="botverse_test_new")
async def entrypoint(ctx: JobContext):
    session = AgentSession(...)
    await session.start(ctx.room, agent=Agent(instructions="You are a helpful assistant."))
1. Run worker with your entrypoint (don’t rely on
WorkerOptions.agent_name
for dispatch):
Copy code
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
1. Ensure your dispatch rule references the same name:
Copy code
"roomConfig": { "agents": [{ "agentName": "botverse_test_new" }] }
If you still see the ImportError after changing the import, please share: • the exact traceback, and • the output of
pip show livekit-agents
(you already provided version which is helpful).