i have purchased a third party telephonic service ...
# ask-ai
f
i have purchased a third party telephonic service number. I have setup SIP trunk and dispatch rule for inbound calling. How can i setup this in agent.py which is a voice agent with llm, stt, tts to test 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 wire your existing
agent.py
(LLM + STT + TTS) to handle inbound calls that arrive via your SIP trunk + dispatch rule. Below are the exact steps and minimal code pointers to get that working. 1) Give your agent a name for explicit dispatch • Add the
agent_name
to the rtc session decorator so LiveKit can dispatch it from your rule:
Copy code
@server.rtc_session(agent_name="my-inbound-agent")
async def my_agent(ctx: JobContext):
    ...
2) Ensure your dispatch rule references that agent name • In your dispatch rule JSON, include the agent in `roomConfig.agents`:
Copy code
"roomConfig": {
  "agents": [
    { "agentName": "my-inbound-agent" }
  ]
}
• Apply the rule with the CLI you used to create dispatch rules so inbound SIP calls create rooms and dispatch this agent. 3) In
agent.py
join the room and start your voice session (STT, LLM, TTS) • Create and start an AgentSession tied to the room from `ctx.room`:
Copy code
session = AgentSession(
    stt="assemblyai/universal-streaming:en",
    llm="openai/gpt-4.1-mini",
    tts="cartesia/sonic-3",
    vad=...,
    turn_detection=...
)
await session.start(room=ctx.room, agent=Assistant())
4) Receive SIP caller audio (no extra steps required unless you want filtering) • SIP callers are published as participants with `kind=SIP`; the agent will receive their audio by default. • If you want to target only the SIP participant, filter via RoomIO or participant identity when processing input. 5) Answer the call / speak to the caller • Use
generate_reply()
to synthesize and send speech back into the room:
Copy code
await session.generate_reply(instructions="Thank you for calling. How can I help you?")
6) Run your agent service so it can be dispatched • Start the agent process (example):
Copy code
uv run agent.py dev
Then place a call to your purchased number — the SIP trunk + dispatch rule will create a room like
call-XXXXX
and dispatch
my-inbound-agent
into it. If you want, I can: • Show a compact, complete
agent.py
example with join/start/generate_reply included. • Help with filtering logic to handle only SIP participants or multiple participants. Which would you prefer? Sources: Agents telephony integration | LiveKit docs | sip | livekit/livekit_composite | DeepWiki
f
please note i cant use server anymore in agent.py
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
f
hi
how to setup agent_name in voice bot agentsession which matches dispatch rule which is connected to sip trunk for inbound calling?