clever-doctor-15083
09/27/2025, 5:51 AMtall-airline-16756
09/27/2025, 5:52 AMtall-airline-16756
09/27/2025, 5:52 AMadorable-petabyte-73906
09/29/2025, 7:17 AMtall-airline-16756
09/29/2025, 7:17 AMclever-doctor-15083
09/29/2025, 8:08 AMtall-airline-16756
09/29/2025, 8:09 AMimport logging
from pathlib import Path
from dotenv import load_dotenv
from livekit.agents import JobContext, WorkerOptions, cli
from livekit.agents.voice import Agent, AgentSession
from livekit.plugins import openai, deepgram, silero
# Load environment variables from .env file
load_dotenv(dotenv_path=Path(__file__).parent.parent / '.env')
class SimpleAgent(Agent):
def __init__(self):
super().__init__(
instructions="You are a helpful agent.",
stt=deepgram.STT(),
llm=openai.LLM(model="gpt-4o"),
tts=openai.TTS(),
vad=silero.VAD.load()
)
async def on_enter(self):
# Automatically greet the caller when the call starts
self.session.generate_reply()
async def entrypoint(ctx: JobContext):
session = AgentSession()
agent = SimpleAgent()
await session.start(
agent=agent,
room=ctx.room
)
# Optionally greet the caller
await session.generate_reply(
instructions="Greet the user and offer your assistance."
)
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
1. Configure Inbound SIP Trunk: Next, you’ll want to create a JSON file for your trunk configuration and then use the LiveKit CLI to set it up like this:
{
"trunk": {
"name": "My inbound trunk",
"numbers": [
"+15105550100"
]
}
}
lk sip inbound create inbound-trunk.json
1. Create a Dispatch Rule: This step is about defining a dispatch rule to route calls smoothly to your agent. Here’s how you can do it:
{
"dispatch_rule": {
"rule": {
"dispatchRuleIndividual": {
"roomPrefix": "call-"
}
},
"roomConfig": {
"agents": [
{
"agentName": "inbound-agent"
}
]
}
}
}
lk sip dispatch create dispatch-rule.json
1. Start the Agent: Finally, run your agent in development mode with this command:
python3 agent.py dev
Once your agent is up and running, you can give your SIP number a call and interact with the AI agent. If you hit any bumps or have questions along the way, please don’t hesitate to reach out—I’m here to help!
Sources: telephony/sip_lifecycle.py | Agents telephony integration | LiveKit Docs | Accepting incoming calls | LiveKit Docs | Docs::Telephony | Creating SIP Inbound Trunks and Dispatch Rules with Python SDKadorable-petabyte-73906
09/29/2025, 8:10 AMclever-doctor-15083
09/29/2025, 8:11 AMadorable-petabyte-73906
09/29/2025, 8:11 AMclever-doctor-15083
09/29/2025, 8:11 AM