is this code correct for inbound telephony calling...
# ask-ai
f
is this code correct for inbound telephony calling? i have dispatch rule and sip trunk created. Also do i need to register my agent on livekit console?? async def entrypoint(ctx: agents.JobContext): # build session (same as your original) bot = SalesAgent() session = AgentSession( vad=silero.VAD.load(), stt=deepgram.STT(model="nova-3", language="multi", interim_results=False), llm=groq.LLM(model="meta-llama/llama-4-scout-17b-16e-instruct", temperature=0.2), tts=deepgram.TTS(model="aura-2-andromeda-en", sample_rate=24000) ) # Start session with enhanced audio settings await session.start( agent=bot, room=ctx.room, room_input_options=RoomInputOptions( noise_cancellation=noise_cancellation.BVC(), audio_sample_rate=16000, audio_num_channels=1, ), room_output_options=RoomOutputOptions( audio_enabled=True, ) ) logger.info("✅ Session started successfully") if name == "__main__": # Load environment variable # Start the application cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, agent_name= "testing"))
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.
Thanks — I reviewed your snippet and will address three things you asked about: code correctness, dispatch/SIP trunk, and agent registration. 1) Code correctness • Structure is correct: creating AgentSession with VAD/STT/LLM/TTS and calling
session.start(..., room=ctx.room)
is the right approach. • Fix needed:
room_input_options
and
room_output_options
are not valid parameters. Use
room_options
with a
RoomOptions
object and set audio/noise options there. • Noise cancellation: for SIP/phone callers use
BVCTelephony()
rather than
BVC()
for better telephony performance; you can choose it conditionally when participant is SIP. 2) Dispatch rule and SIP trunk • You do need a dispatch rule to route inbound calls to a room. • If you use a third-party SIP provider, you also need an inbound SIP trunk attached to your number. If you use LiveKit Phone Numbers, a SIP trunk is not required, but you still need a dispatch rule. • Ensure your dispatch rule’s room config lists your agent name (see example below). 3) Agent registration / console • You do not manually register agent code in the LiveKit console. The agent must be running and connected with the same
agent_name
you reference in your dispatch rule or API dispatch. LiveKit dispatches to that active agent process. Quick fixes / examples • start() with room options (conceptual):
Copy code
await session.start(
  agent=bot,
  room=ctx.room,
  room_options=RoomOptions(
    noise_cancellation=lambda params: noise_cancellation.BVCTelephony()
    if params.participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP
    else noise_cancellation.BVC(),
    audio_sample_rate=16000,
    audio_num_channels=1,
  ),
)
• Dispatch rule snippet:
Copy code
"roomConfig": {
  "agents": [{ "agentName": "testing" }]
}
If you’d like, share: • the exact error you’re seeing (if any), or • whether you’re using LiveKit Phone Numbers or a third-party SIP provider and I’ll give the precise code adjustments or dispatch/SIP settings to use. Sources: Agents telephony integration | LiveKit docs | Voice AI quickstart | LiveKit docs | SIP inbound trunk | LiveKit docs | SIP dispatch rule | LiveKit docs | Accepting inbound calls | LiveKit docs
f
the number rings, but agent is not connected in livekit, python main.py dev logs: 2025-12-01 131447,103 - DEBUG asyncio - Using proactor: IocpProactor 2025-12-01 131447,107 - DEV livekit.agents - Watching D:\Viren\personal\gen_ai_cv\lenden\development\agents_botverse 2025-12-01 131448,972 - DEBUG asyncio - Using proactor: IocpProactor 2025-12-01 131448,976 - INFO livekit.agents - starting worker {"version": "1.2.2", "rtc-version": "1.0.12"} 2025-12-01 131449,286 - INFO livekit.agents - registered worker {"id": "AW_edGhsxDsHkJD", "url": "wss://botverse-xt52adcy.livekit.cloud", "region
t
Thanks — you're seeing the right signs (number rings and the worker registered), so let's narrow what's stopping the agent from joining the room. What I’m responding to: your logs showing the worker registered but the agent not appearing in the room when the call rings. Checklist + next checks (do these in order): 1) Confirm exact agent name • Share the
@server.agent(name="...")
value or the
agent_name
you pass to
WorkerOptions
. • Confirm the dispatch rule uses that exact string in
roomConfig.agents[].agentName
. Case and spelling must match exactly. 2) Show me the dispatch rule JSON • Paste the dispatch rule you created (or the output of
lk sip dispatch list
). If the rule doesn’t include
roomConfig.agents
, the agent won’t be dispatched. 3) Verify the dispatch rule is active and attached to the inbound trunk/number • Run
lk sip dispatch list
and confirm the rule you expect is present. • Confirm your inbound trunk’s
numbers
includes the phone number being called. 4) Confirm agent runtime logs for dispatch attempts • Add a log line at the top of your entrypoint, e.g.
logger.info("entrypoint invoked, room=%s", ctx.room.name)
or a simple
print
so we can quickly see if the entrypoint ever runs. • Call again and share the agent-side logs (not just the worker registered line). If you do NOT see the entrypoint log, LiveKit never dispatched the job. 5) Noise-cancellation / room options (not the immediate cause, but ensure correct params) • Ensure you use
room_options
(not `room_input_options`/`room_output_options`) when calling
session.start(...)
. Incorrect params won’t prevent dispatch, but will surface errors when the agent starts. If you prefer, paste: • Your agent declaration (
@server.agent(...)
or WorkerOptions entrypoint line), • The dispatch rule JSON, • The output of
lk sip dispatch list
I’ll review those and tell you the exact field to fix. Sources: Agents telephony integration | LiveKit docs | SIP dispatch rule | LiveKit docs | SIP inbound trunk | LiveKit docs | SIP troubleshooting guide | LiveKit docs
f
dispatch rule: { "sipDispatchRuleId": "SDR_irdHBirVeQzJ", "rule": { "dispatchRuleIndividual": { "roomPrefix": "call-" } }, "trunkIds": [ "ST_diGTDK94bvRy" ], "name": "My dispatch rule", "roomConfig": { "agents": [ { "agentName": "testing" } ] } } # sip trunk: { "sipTrunkId": "ST_diGTDK94bvRy", "name": "botverse_inbound", "numbers": [ "+919240904637" ], "authUsername": "upttuser", "authPassword": "upttuser-p@ssword", "krispEnabled": true }
t
Thanks — your dispatch rule and SIP trunk look correct and reference agent name "testing", so dispatch should trigger. Next steps to pinpoint why the agent process isn’t joining the room: 1) Confirm agent name usage in your agent process • Show the line where you register the agent (either
@server.agent(name="testing")
or
WorkerOptions(..., agent_name="testing")
). They must match exactly. 2) Verify the entrypoint is invoked when calls arrive • Add a simple log at the top of your entrypoint:
Copy code
logger.info("entrypoint invoked for room=%s", getattr(ctx, "room", None))
• Call the number and paste the agent-side logs after the registered worker line. If you don’t see this log, LiveKit did not dispatch the job. 3) Confirm dispatch rule is active for that trunk/number • Run
lk sip dispatch list
(or show the dashboard) and confirm the rule SDR_irdHBirVeQzJ is present and attached to trunk ST_diGTDK94bvRy. • Confirm the trunk’s
numbers
includes +919240904637 (your shown trunk does). 4) Check LiveKit cloud/telephony logs for dispatch attempts • In the telephony dashboard or logs, look for an incoming call event and whether a dispatch job was created or errored. Share any error messages you find. 5) Small fixes to avoid runtime errors once dispatched • Use
room_options
(not `room_input_options`/`room_output_options`) with proper noise-cancellation (use
BVCTelephony()
for SIP calls). Incorrect params may cause the agent to fail on start:
Copy code
await session.start(
  agent=bot,
  room=ctx.room,
  room_options=RoomOptions(
    noise_cancellation=noise_cancellation.BVCTelephony(),
    audio_sample_rate=16000,
    audio_num_channels=1,
  ),
)
If after adding the entrypoint log you still don’t see it when calling, paste: • the agent registration line (
@server.agent(...)
or WorkerOptions snippet), • the agent-side logs from the time of call (everything after the "registered worker" log), • output of
lk sip dispatch list
. I’ll examine those and tell you the exact field or log message to fix.
f
entrypoint doesn't work, i am currently using agent_name in worker options and not server. async def entrypoint(ctx: agents.JobContext): logger.info("entrypoint invoked, room=%s", ctx.room.name) # build session (same as your original) bot = SalesAgent() session = AgentSession( vad=silero.VAD.load(), stt=deepgram.STT(model="nova-3", language="multi", interim_results=False), llm=groq.LLM(model="meta-llama/llama-4-scout-17b-16e-instruct", temperature=0.2), tts=deepgram.TTS(model="aura-2-andromeda-en", sample_rate=24000) ) cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, agent_name= "testing"))
t
Thanks — you confirmed the dispatch rule and trunk are correct and that you’re using
agent_name
via
WorkerOptions
, but the entrypoint never runs. That means LiveKit is not dispatching the job to your worker. Next steps to pinpoint and fix: 1) Confirm agent registration with LiveKit Cloud • Run:
lk agent status
• If your agent is not listed, run:
lk agent create
(or show me the output of
lk agent status
). 2) Verify dispatch rule is active and attached to the trunk • Run:
lk sip dispatch list
• Confirm the rule SDR_irdHBirVeQzJ appears and is attached to trunk ST_diGTDK94bvRy. 3) Double-check exact agent name matching • Show the exact code line where you start the worker or declare the agent. You said: cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, agent_name="testing")) Ensure the dispatch JSON uses exactly "testing" (it does in your earlier paste). 4) Add an entrypoint heartbeat log and watch logs during a call • Add at top of entrypoint:
Copy code
logger.info("entrypoint invoked, room=%s", getattr(ctx, "room", None))
• Then call the number and paste all agent-side logs from process start through the call (not just the registered worker line). If you never see the entrypoint log, dispatch did not reach the worker. 5) If agent is registered and entrypoint still not invoked • Share outputs of: ◦
lk agent status
◦
lk sip dispatch list
◦ Full agent logs around the call time (from process start) I’ll review those and point to the exact field or error to fix. Sources: Agents telephony integration | LiveKit docs | Agent dispatch | LiveKit docs | SIP dispatch rule | LiveKit docs | Voice AI quickstart | LiveKit docs | LiveKit Phone Numbers | LiveKit docs
f
agent is not registered, how can i delete other agents?
t
You can remove old agents from LiveKit Cloud and then create/register the agent you want. Do these steps and paste outputs if you want me to confirm which to delete. 1) List agents • Run:
Copy code
lk agent list
• Paste the output here so I can identify IDs to remove. 2) Delete an agent • Delete by ID:
Copy code
lk agent delete --id <AGENT_ID>
• Or, from an agent directory with livekit.toml:
Copy code
lk agent delete
3) Create/register your agent • From your project directory:
Copy code
lk agent create --region <region>
• Verify:
Copy code
lk agent status --id <AGENT_ID>
4) If you prefer the Console • Open LiveKit Cloud → Agents → select agent → Delete. What I need from you to proceed: paste the output of
lk agent list
. I’ll tell you exactly which IDs to delete and confirm the next create/register command. Sources: Agent deployment CLI reference | LiveKit docs | Deploying to production | LiveKit Docs
f
i have my voice bot as a main.py file in local, how to create an agent and register on livekit?
t
Good — you’ve got a local
main.py
. Below are concise, ordered steps to package it as a LiveKit Cloud agent and register it so dispatch will find it. Run each step and paste errors/output if you want help troubleshooting. 1) Install & authenticate CLI • Install: follow your platform instructions for the
lk
CLI. • Authenticate:
Copy code
lk cloud auth
lk project set-default "<your-project-name>"
2) Create a minimal
livekit.toml
in your project folder (next to
main.py
) • Example content (edit
name
and
region
):
Copy code
name = "my-voice-agent"
region = "us-east"
runtime = "python"
3) Provide an entrypoint the agent expects • Ensure
main.py
exposes the agent entrypoint the Agents SDK expects (you already have
entrypoint(ctx: agents.JobContext)
and call
cli.run_app(...)
). • Confirm the file runs locally:
python main.py dev
(you should see the worker register logs). 4) Add a Dockerfile (CLI will auto-generate if missing, but you can supply one) • Simple Python Dockerfile example:
Copy code
FROM python:3.11-slim
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
CMD ["python", "main.py", "prod"]
• Ensure
requirements.txt
lists
livekit-agents
and other deps. 5) Create the agent in LiveKit Cloud (builds and registers it) • From the project folder:
Copy code
lk agent create
• This builds, deploys, and registers an agent with an ID. Note the agent ID printed. 6) Verify agent status
Copy code
lk agent status --id <AGENT_ID>
lk agent list
• Status should be
Running
(or
Sleeping
if idle). If
Error
or
Build Failed
, run:
Copy code
lk agent logs --id <AGENT_ID> --log-type deploy
7) Update / re-deploy after changes • Edit code, then:
Copy code
lk agent deploy --id <AGENT_ID>
# or rebuild with
lk agent create --force
8) Wire the agent into telephony dispatch • Ensure your SIP dispatch rule includes the agent name (the
name
from
livekit.toml
or the
agentName
you want). • Example dispatch rule snippet:
Copy code
"roomConfig": {
  "agents": [{ "agentName": "my-voice-agent" }]
}
• Attach the dispatch rule to the trunk/number. 9) Quick local debug before deploy • To confirm entrypoint works locally, run:
Copy code
python main.py dev
• Add a log at the top of `entrypoint`:
Copy code
logger.info("entrypoint invoked for room=%s", getattr(ctx, "room", None))
• If this appears when you simulate dispatch, your code is fine. If you want, paste: • your
livekit.toml
, •
Dockerfile
(if any) or
requirements.txt
, • output of
lk agent create
or
lk agent list
and I’ll tell you exact edits to get the agent registered and dispatch-ready.
f
lk agent create Using project [botverse] project does not match agent subdomain []
t
You're seeing a project/subdomain mismatch. Fix by ensuring your CLI project and the agent's subdomain (in livekit.toml or the create command) match. Do this: 1. Confirm current CLI project
Copy code
lk project show
1. If it’s not the correct project, set it:
Copy code
lk project set-default "<your-project-name>"
1. Add or update livekit.toml in your agent folder with matching name/subdomain and region, for example:
Copy code
name = "botverse"        # must match your project/subdomain
region = "us-east"
runtime = "python"
1. Re-run agent create from the folder with that livekit.toml:
Copy code
lk agent create
Or explicitly set subdomain during create:
Copy code
lk agent create --name botverse --region us-east
If you still get the error, paste the output of: •
lk project show
• the contents of your
livekit.toml
(if present) I’ll tell you the exact field to change.
f
so when i run python main.py dev, i can see the logs on terminal and the details on livekit console: # logs: 2025-12-01 135955,304 - DEBUG asyncio - Using proactor: IocpProactor 2025-12-01 135955,304 - DEV livekit.agents - Watching D:\Viren\personal\gen_ai_cv\lenden\development\agents_botverse 2025-12-01 135956,996 - DEBUG asyncio - Using proactor: IocpProactor 2025-12-01 135957,011 - INFO livekit.agents - starting worker {"version": "1.2.2", "rtc-version": "1.0.12"} 2025-12-01 135957,406 - INFO livekit.agents - registered worker {"id": "AW_DWt6oNYaVoRP", "url": "wss://botverse-xt52adcy.livekit.cloud", "region": "India South", "protocol": 16} # livekit -agents - console: WorkerID: AW_DWt6oNYaVoRP0 Status: Ready *This agent is self-hosted. Deploy your agent to LiveKit Cloud to access versioning and rollbacks.
t
You're running the agent locally and LiveKit shows it as a self-hosted Ready worker — that confirms the worker is connected but not registered as a Cloud-managed agent. For inbound telephony dispatch, LiveKit Cloud must know the agent (a Cloud agent record). Do the following to register/deploy the agent to LiveKit Cloud so dispatch can find it. 1) Confirm CLI project
Copy code
lk project show
2) Add or update livekit.toml in your agent folder (next to main.py). Example — set name to your project/subdomain:
Copy code
name = "botverse"
region = "india-south"
runtime = "python"
The
name
must match your LiveKit project subdomain. 3) Create the agent in Cloud (from that folder)
Copy code
lk cloud auth          # if not already authenticated
lk project set-default "<your-project-name>"
lk agent create
If you prefer, set name explicitly:
Copy code
lk agent create --name botverse --region india-south
4) Verify agent is registered
Copy code
lk agent list
lk agent status --id <AGENT_ID>
Status should be Running/Sleeping (not just Ready self-hosted). 5) Re-run an inbound call — dispatch will now be able to route to the Cloud-registered agent named in your dispatch rule. If you hit the earlier "project does not match agent subdomain" error again, paste the outputs of: •
lk project show
• contents of your
livekit.toml
and I’ll tell you the exact field to change.
f
No help topic for 'show'
t
You're seeing "No help topic for 'show'" because
lk project show
isn't a CLI command. Use these exact commands to register your agent and fix project/subdomain mismatches. 1) See available projects and which is default
Copy code
lk project list
2) Set the correct default project (use the project name from the list)
Copy code
lk project set-default "<your-project-name>"
3) Ensure livekit.toml matches that project subdomain • In your agent folder, open or create
livekit.toml
and set
name
to your project subdomain and correct region, for example:
Copy code
name = "botverse"
region = "india-south"
runtime = "python"
4) Create/register the agent in Cloud (run from the folder with livekit.toml)
Copy code
lk cloud auth        # if not already authenticated
lk agent create
Or set name explicitly:
Copy code
lk agent create --name botverse --region india-south
5) Verify agent registration
Copy code
lk agent list
lk agent status --id <AGENT_ID>
If you see the "project does not match agent subdomain" error again, paste the outputs of: •
lk project list
• the contents of your
livekit.toml
I’ll tell you exactly which field to change. Sources: LiveKit CLI Setup | LiveKit Docs | Agent deployment CLI reference | LiveKit docs | Deploying to production | LiveKit Docs | server-sdk-go | livekit/livekit_composite | DeepWiki | Introducing LiveKit Phone Numbers: Zero to Ringing in 60 Seconds
f
when i run python main.py dev from terminal, i get these logs and livekit console shows this infromation under agents: however the call is not connected: # livekit console - agents section Worker ID: AW_yXxiUSHZ5X2K Concurrent sessions: 0 Resource load: 9.2% Started at: 1 Dec 2025, 141128 Updated at: 1 Dec 2025, 141158 Status: Ready # logs: 2025-12-01 141126,625 - DEBUG asyncio - Using proactor: IocpProactor 2025-12-01 141126,641 - DEV livekit.agents - Watching D:\Viren\personal\gen_ai_cv\lenden\development\agents_botverse 2025-12-01 141128,321 - DEBUG asyncio - Using proactor: IocpProactor 2025-12-01 141128,326 - INFO livekit.agents - starting worker {"version": "1.2.2", "rtc-version": "1.0.12"} 2025-12-01 141128,679 - INFO livekit.agents - registered worker {"id": "AW_yXxiUSHZ5X2K", "url": "wss://botverse-xt52adcy.livekit.cloud", "region": "India South", "protocol": 16}
t
You're running a local worker (logs + Console "Ready") but it is not a Cloud-registered agent — LiveKit will not dispatch inbound SIP calls to a self-hosted "Ready" worker. To get calls routed to your code, you must register/deploy the agent to LiveKit Cloud and ensure your dispatch rule references that agent name exactly. Do this next (concise): 1) Add/update livekit.toml next to main.py:
Copy code
name = "botverse"        # must match your project/subdomain
region = "india-south"
runtime = "python"
2) Ensure your code sets the agent name to match
name
(or dispatch rule): • If using WorkerOptions:
Copy code
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, agent_name="botverse"))
• Or use
@server.agent(name="botverse")
if using server style. 3) Register/create the agent in Cloud (from the folder with livekit.toml)
Copy code
lk cloud auth
lk project set-default "<your-project-name>"
lk agent create
If you see the project/subdomain mismatch error, run:
Copy code
lk project list
then set the correct default project with
lk project set-default "<project-name>"
, and ensure
livekit.toml
name matches that project's subdomain. 4) Verify registration
Copy code
lk agent list
lk agent status --id <AGENT_ID>
Status should be Running/Sleeping (not just "Ready" self-hosted). 5) Confirm dispatch rule uses the same agent name Your dispatch rule must include:
Copy code
"roomConfig": { "agents": [{ "agentName": "botverse" }] }
6) Test call & watch logs • After agent is Cloud-registered, call the number. Your entrypoint log (
logger.info("entrypoint invoked, room=%s", ctx.room.name)
) should appear. If you want, paste: • contents of your livekit.toml • output of
lk project list
• output of
lk agent list
I’ll tell you exactly which field to change or which agent IDs to delete. Would you like me to walk through the
lk agent create
command with you now?
f
yes i have a folder with main.py and other dependencies its in "botverse" folder. can u tell me how to register the agent on cloud?? my project name is also "botverse"
t
Great — since your project and folder are both named "botverse", follow these exact steps from the botverse folder to register your agent in LiveKit Cloud. 1) Authenticate and pick your project
Copy code
lk cloud auth
lk project list
lk project set-default "botverse"
2) Add or verify livekit.toml next to main.py Create or update file
botverse/livekit.toml
with:
Copy code
name = "botverse"
region = "india-south"
runtime = "python"
Make sure
name
exactly matches your project subdomain ("botverse") and pick the correct region. 3) Ensure entrypoint and requirements • Confirm
main.py
exposes your entrypoint and you start with:
Copy code
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, agent_name="botverse"))
• Ensure
requirements.txt
lists all dependencies (including
livekit-agents
). 4) (Optional) Provide Dockerfile — CLI will auto-generate if absent. 5) Create & register the agent (run in the botverse folder)
Copy code
lk agent create
If you prefer explicit name/region:
Copy code
lk agent create --name botverse --region india-south
6) Verify registration
Copy code
lk agent list
lk agent status --id <AGENT_ID>
Status should be Running or Sleeping. Note the agent ID. 7) Update dispatch rule Ensure your SIP dispatch rule references the agent name:
Copy code
"roomConfig": { "agents": [{ "agentName": "botverse" }] }
8) Test call and watch logs • Place an inbound call. Your local logs will show registration when running
python main.py dev
, but dispatched calls require the Cloud-registered agent. • Watch agent logs:
Copy code
lk agent logs --id <AGENT_ID> --log-type deploy
If you hit the "project does not match agent subdomain" error or any other error, paste the outputs of: •
lk project list
• the contents of your
livekit.toml
• the full output of
lk agent create
I’ll guide you on the exact fix.
f
what was the need to register the agent using cli?
t
Great question — here’s why you need to register the agent with the CLI and what it gives you, in plain terms. Why register the agent via CLI • Cloud dispatch needs a Cloud agent record: LiveKit only dispatches inbound SIP jobs to agents that it knows about in Cloud. A locally running self-hosted worker shows as “Ready” but isn’t a Cloud-registered agent, so dispatch rules won’t target it. • Matching names and routing:
lk agent create
registers an agent name/subdomain that your dispatch rule can reference. That exact name is what LiveKit uses to route incoming calls to your agent. • Builds, versioning, and deployment: The CLI packages your code, builds a deployable artifact, and records a version in LiveKit Cloud so you get consistent deployments, rollbacks, and status reporting. • Health, autoscaling, and logs: Cloud-registered agents show Running/Sleeping status, expose deploy/build logs, and integrate with LiveKit’s runtime features (instead of just a single self-hosted worker). • Easier management: You can list/delete agents, check status, and redeploy from the CLI or console. This avoids manual orchestration if you change code or region. What the local worker does vs a Cloud agent • Local worker (what you see with
python main.py dev
): connects to LiveKit for development and shows up as a Ready self-hosted worker. Useful for local testing but not sufficient for telephony dispatch. • Cloud-registered agent (created with
lk agent create
): a Cloud-managed agent record that LiveKit can dispatch to when calls arrive and that participates in Cloud deployments/versioning. Short summary • You must register/create the agent with
lk agent create
so LiveKit Cloud can discover and dispatch incoming calls to it. Local running alone is not enough. If you want, I can: • Walk through
lk agent create
from your botverse folder step‑by‑step, • Or show the exact minimal
livekit.toml
and command you should run now. Which would you prefer?