fast-hairdresser-13908
11/30/2025, 6:44 PMtall-airline-16756
11/30/2025, 6:44 PMtall-airline-16756
11/30/2025, 6:45 PMagent.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:
@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`:
"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`:
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:
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):
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 | DeepWikifast-hairdresser-13908
11/30/2025, 6:45 PMtall-airline-16756
11/30/2025, 6:45 PMfast-hairdresser-13908
11/30/2025, 7:41 PMfast-hairdresser-13908
11/30/2025, 7:42 PM