Hi AI, What type of workflow is recommended for te...
# ask-ai
b
Hi AI, What type of workflow is recommended for testing with a phone number locally? Now that my agent is deployed to lk cloud with (the dispatch rule, inbound trunk , and sip) when I run local to test:
uv run python src/agent.py dev
the logs don't work locally, only in lk cloud. Do I have to use multiple numbers and dispatch rules? I'd rather just test using the console
uv run python src/agent.py console
but with egress enabled the console run fails with an error (I posted it in the egress channel)
livekit.api.twirp_client.TwirpError: TwirpError(code=not_found, message=requested room does not exist, status=404)
(
t
Thanks for reaching out, Matt. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding about your local testing workflow, dispatch rules/SIP, and the
TwirpError: requested room does not exist
you saw when running
console
with egress. Short answers • Use
dev
mode (
uv run python src/agent.py dev
) to test locally with your real phone number, inbound trunk, and existing dispatch rules. You do not need extra numbers or dispatch rules. • Do not use
console
mode when egress is enabled.
console
runs entirely locally and does not connect to a LiveKit room, so egress calls fail with the 404 TwirpError because no room exists. What to do next 1. Run in dev mode so your local agent connects to the LiveKit Cloud room created by your dispatch rule: ◦ Command:
uv run python src/agent.py dev
◦ Add
--log-level=DEBUG
if you need more verbose logs. 1. Verify room lifecycle before starting egress: ◦ Confirm the dispatch rule is creating/joining a room when a call arrives. ◦ Ensure your agent has joined that exact room name/ID before initiating egress. The 404 means egress tried to operate on a room that wasn’t present. 1. If you want to test interactively without egress: ◦ You can use
console
mode for logic/flow testing that doesn’t call egress or require a LiveKit room. If you’d like, tell me: • Which mode you want to use (dev or console), • The exact egress call you’re making (code snippet or command), and • Whether your agent logs show it successfully joining the room when a call arrives. I’ll give the smallest targeted troubleshooting steps based on that. Sources: Voice AI quickstart | LiveKit docs | Deploying to production | LiveKit Docs | Observability data hooks | LiveKit docs | Agent server options | LiveKit docs
b
when I run:
uv run python src/agent.py dev --log-level=DEBUG
I get this in the terminal
Auto-reload is not supported on the iTerm2 terminal, disabling...
09:01:06 DEBUG  asyncio          Using selector: KqueueSelector
INFO   livekit.agents   starting worker {"version": "1.3.3", "rtc-version": "1.0.19"}
INFO   livekit.agents   registered worker {"agent_name": "hvac-service-agent", "id": "AW_nbC8C2gQXoRX", "url":
"wss://hvac-agent-hello-67gp4wqp.livekit.cloud", "region": "US West B", "protocol": 16}
I call the number and the agent answers, but it's happening all in cloud, the live logs are logging, but not local. Claude says I need multiple dispatch rules. You're saying this should just log in my local terminal ?
t
Thanks — I’m following up about why you only see cloud logs and what to check next. Quick answers • You do not need multiple dispatch rules. One dispatch rule is sufficient. • Running
uv run python src/agent.py dev
connects your local agent to LiveKit Cloud; that makes most session-level logs (transcripts, egress, full agent traces) appear in LiveKit Cloud rather than your local terminal. • Local terminal will show connection events and any stdout/stderr your code emits, but not the full cloud-side session observability. To troubleshoot and make the right logs visible locally, please share the following so I can give targeted steps: 1. Which logs you expect locally vs what you actually see (examples: transcript text, request/response payloads, audio I/O, handler debug prints). 2. Full agent startup command and the complete terminal output around the time a call arrives and the agent joins the room. 3. A short snippet showing where your agent logs inside call/room handlers (your print/log statements). 4. Any logger/observability config or env vars that could forward logs to cloud (mask secrets). 5. Whether you use the LiveKit CLI (
lk
) and if you run
lk agent logs
during tests. 6. The dispatch rule config (what it routes to — agent name or room template) and the basic call steps you perform. What I’ll do once you share that: • Explain exactly which events are local vs cloud and why. • Show minimal changes to emit more local logs (logger config or adding local debug prints). • If you want transcripts/egress artifacts locally, provide steps to fetch them or run egress only after the agent is in the room. Send the details you can and I’ll give concise, step-by-step changes you can apply. Sources: Voice AI quickstart | LiveKit docs | Agents telephony integration | LiveKit Docs | Agent insights in LiveKit Cloud | LiveKit docs
b
here's perhaps a better illlustration of the problem. when I uv run python src/agent.py dev I would think the agent would use a company id defined in my .env.local file. Instead it uses a company id defined in my secrets.env file. Is that how it's supposed to work? I feel like I sshould be able to test egress using a local.env id
t
Thanks — I’m responding about why your run in
dev
used the company ID from
secrets.env
and why logs are showing in the cloud. Short answer • You do not need multiple dispatch rules. • Your
uv run python src/agent.py dev
is connecting to LiveKit Cloud, so the agent is running as a cloud-connected instance and cloud-managed secrets (from
secrets.env
) are being used rather than your local
.env.local
. • Cloud-managed sessions produce full session logs in the LiveKit dashboard; your local terminal only shows the local process stdout/stderr and connection events. What to do to use your
.env.local
and see local behavior 1. Confirm you are running an un-deployed local process (not a cloud-managed agent): ◦ Do not run
lk agent deploy
or use an agent that is registered/managed in the cloud. ◦ If you previously created a cloud agent, check
lk agent list
to see if it’s registered. 1. Ensure
.env.local
is loaded by your code: ◦ Add/verify
from dotenv import load_dotenv; load_dotenv('.env.local')
(or equivalent) early in startup so
COMPANY_ID
and LiveKit creds come from
.env.local
. 1. Run locally (uses local env values): ◦ For pure local testing (no egress):
uv run python src/agent.py console
◦ For local process connecting to LiveKit cloud (allows egress while using local creds): run your script directly without deploying to cloud, e.g.
uv run python src/agent.py dev
but ensure your code loads
.env.local
and you haven’t uploaded
secrets.env
for that agent name. 1. If egress must run, keep this workflow: ◦ Run the agent locally (so it uses
.env.local
) but let it connect to LiveKit Cloud to join a real room. Egress will work because the room exists in cloud while credentials come from
.env.local
. If you want, paste: • The top of your agent startup code (how env vars are loaded), • The exact
uv
command you run, and I’ll point out the minimal change so your local
.env.local
COMPANY_ID
is used and which logs you’ll see locally vs in the dashboard. Sources: Secrets management | LiveKit Docs | Voice AI quickstart | LiveKit docs | Agent server options | LiveKit docs | Log collection | LiveKit Docs | Agent deployment CLI reference | LiveKit docs
b
My agent is already deployed to livekit cloud. So I am not sure I follow this; ◦ For local process connecting to LiveKit cloud (allows egress while using local creds): run your script directly without deploying to cloud, e.g.
uv run python src/agent.py dev
but ensure your code loads
.env.local
and you haven’t uploaded
secrets.env
for that agent name.
t
You're right to be confused — thanks for clarifying that your agent is already deployed. Here's the precise behavior and the exact steps to run a local instance that uses your
.env.local
while the cloud-deployed agent still exists. Why this happens (short) • A deployed agent uses secrets uploaded to LiveKit Cloud (
secrets.env
) for its runtime. That is why the cloud-managed instance uses the company ID from
secrets.env
. • Running
uv run ... dev
can either start a local process or be used in workflows that register/manage an agent in the cloud. If your local process connects with the same agent name/registration as the deployed one, the cloud-managed config/secrets and cloud observability will dominate the session and logs. What you want: run locally, use
.env.local
, and still allow egress via LiveKit Cloud 1. Ensure your local code explicitly loads
.env.local
at startup: ◦ Add/verify:
Copy code
from dotenv import load_dotenv
     load_dotenv('.env.local')
• Do this before any LiveKit client/agent initialization so credentials and
COMPANY_ID
are read from
.env.local
. 1. Run a true local instance that does not impersonate the deployed cloud agent: ◦ Use a different agent name/ID than the deployed agent (change
AGENT_NAME
or equivalent in
.env.local
) so LiveKit treats your local process as a separate participant instead of the cloud-managed agent. ◦ Start locally:
uv run python src/agent.py dev --log-level=DEBUG
◦ Confirm in startup logs you see your
.env.local
values (or add a debug print for
COMPANY_ID
). 1. Allow egress while local: ◦ Keep the LiveKit project credentials in
.env.local
so your local process connects to the same LiveKit project. ◦ Because the room/egress runs in LiveKit Cloud, egress will work while your agent is local (the room lives in the cloud, your local agent joins it). 1. See local logs ◦ With a different agent name and local run that loads
.env.local
, your terminal will show connection events, your handler prints, and debug logs. ◦ Full session observability (transcripts, stored traces) will still be available in the LiveKit dashboard, but your local stdout/stderr will contain the runtime logs you add. If you prefer minimal risk: • Use a local-only agent name (e.g., append
-local
) in
.env.local
so you can run tests without touching the deployed agent or its secrets. If you want, paste: • The top of your startup file (how envs are loaded) and • The `AGENT_NAME`/identifier you use, and I’ll point out the exact minimal edits so your local run uses
.env.local
and produces local logs while still enabling egress.
b
I see, so then if I make the agent name here environment based it should work?
Copy code
if __name__ == "__main__":
    cli.run_app(
        WorkerOptions(entrypoint_fnc=entrypoint, agent_name="agent-name")
    )
t
Yes — making the agent name environment‑based is the right approach. That will let your local process use
.env.local
values and avoid colliding with the deployed agent (so cloud-managed secrets and logs won’t override your local run). Use an env var and load it before starting the worker. Example:
Copy code
import os
from dotenv import load_dotenv
from livekit.agents import cli, WorkerOptions

load_dotenv(".env.local")
agent_name = os.getenv("AGENT_NAME", "agent-name-local")

if __name__ == "__main__":
    cli.run_app(
        WorkerOptions(entrypoint_fnc=entrypoint, agent_name=agent_name)
    )
Notes: • Set AGENT_NAME in
.env.local
to a distinct value (e.g., append
-local
) so the cloud-deployed agent and your local agent are separate. • Ensure you load
.env.local
before any LiveKit client/agent initialization so
COMPANY_ID
and credentials come from your local file. • With a different agent name your terminal will show your local stdout/stderr and debug logs; egress still works because the room runs in LiveKit Cloud while your agent joins it.
b
I'll try it. Thanks
t
Great — glad that helped. If anything fails when you try it, share the small outputs below and I’ll give precise next steps: • The top 10 lines of your agent startup logs after running locally • The
AGENT_NAME
value from
.env.local
• A short snippet showing where you load envs (or confirm you used the example) Happy to review and help adjust any remaining bits.
b
no changing the agent name to a local one didn't fix it. Here's what happens when I start local: uv run python src/agent.py dev --log-level=DEBUG Auto-reload is not supported on the iTerm2 terminal, disabling... 122021 DEBUG asyncio Using selector: KqueueSelector INFO livekit.agents starting worker {"version": "1.3.3", "rtc-version": "1.0.19"} INFO livekit.agents registered worker {"agent_name": "hvac-service-agent-local", "id": "AW_jfcs3H3iawtH", "url": "wss://hvac-agent-hello-67gp4wqp.livekit.cloud", "region": "US West B", "protocol": 16} but those are the only logs I continue to see after I start a call. I know before I used to see the real call logs in my terminal when I ran
uv run python src/agent.py dev --log-level=DEBUG
But now since my agent is deployed to livekit cloud this has stopped working. The call logs livekit cloud. Not my local logs. So I am either misunderstanding something, or it no longer works like it did before. I certainly would need teh abilility to run a call with
uv run python src/agent.py dev --log-level=DEBUG
and test the operations of the call (like egress and reporting) without deleting the agent in production. I am on 1.3.3. here is my code: ``````
t
Thanks — I’m responding to your latest test where changing the agent name didn’t surface call logs locally. Short answer • The deployed cloud agent still claims incoming jobs by dispatch rules, so your local process never receives the call work even though it registers. That’s why you only see the single registration log and no per-call logs. • To get full local logs (egress/reporting) while keeping production deployed, run your local agent as a distinct worker that actually receives the job (not just registers). Below are concise, concrete options. Options to see local call logs without deleting production agent • Use a distinct test room and join it manually a. Create a test room name (e.g., "test-local-123"). b. Join that room from a client (or the Agents Playground) so the room exists in LiveKit Cloud. c. Start your local agent with a unique agent name (you already did this) and ensure no dispatch rule claims that test room. Result: your local agent will be assigned that job and you’ll see full logs locally. • Scope dispatch rules to avoid claiming test rooms a. Modify production dispatch rules to target only production prefixes (e.g., "prod-"). b. Use test prefixes (e.g., "test-") for local work. Result: production agent won’t steal test sessions. • Manually create a job for your local agent (programmatic or CLI) a. Use Agents Playground or an API/CLI call to create a job that targets your local agent name. b. Start your local agent and it will receive the job. Result: immediate local execution and logs. • Temporarily disable the production dispatch rule (if safe) a. Turn off/rename the production dispatch rule while testing. b. Re-enable it after tests. Result: all matching calls will be eligible for your local agent. Checklist to ensure your local agent actually logs call activity 1. Verify env loading happens before agent init (you already added
load_dotenv
). 2. Confirm agent_name differs from prod and you see that name in startup logs. 3. Add explicit debug logs at session start and key handlers: ◦ log at session entry: ctx.room.name, ctx.worker_id ◦ log before/after egress start 1. Confirm the room your test call creates does NOT match a production dispatch rule. 2. If you want to trigger egress locally, either: ◦ Manually start egress for the test room (CLI/API) after local agent joins, or ◦ Ensure no cloud-side egress rule is already running for that room. What I need if you want a precise next step • The active dispatch rule(s) (room prefix or matching config). • How you’re initiating test calls (SIP inbound number, Agents Playground, or frontend). • The session-start logging snippet or confirm you added a log in your entrypoint. If you send those three items I’ll tell you the exact minimal change so your local agent receives jobs and prints the call-level logs you expect. Sources: Agent server | LiveKit docs | Agents playground | LiveKit Docs | Job lifecycle | LiveKit docs | Agents telephony integration | LiveKit docs
b
After running:
uv run python src/agent.py dev --log-level=DEBUG
I still see no logs running locally when I use a different local agent name at the entry point. I know I saw real stats happening here before like participants entering room, etc.. in my local terminal. Now that I agent is deployed to livekit I only see those logs in livekit cloud
Copy code
if __name__ == "__main__":
    cli.run_app(
        WorkerOptions(entrypoint_fnc=entrypoint, agent_name=os.getenv("AGENT_NAME", "hvac-service-agent"))
    )
t
Thanks — I’m responding to your update that local logs still don’t appear even after changing
AGENT_NAME
. Short answer • The deployed cloud agent is still claiming the jobs via dispatch, so your local worker never receives the per-call work. Seeing only the registration log is expected when dispatch routes calls to the cloud agent. To diagnose quickly, please share these three things (small snippets/values only): 1. The active dispatch rule(s) config (roomPrefix or matching criteria). 2. How you trigger the test call (SIP inbound number, Agents Playground, or a custom client). 3. The room name created when you make the test call (copy it from the LiveKit dashboard or logs). With those I will: • Tell you the minimal change so the test room won’t be claimed by production (one-line dispatch change or room name pattern). • Show the exact steps to run a local job that will produce full call logs and allow egress without deleting the production agent.
b
here's my dispatch rules:
Copy code
{
  "dispatch_rule": {
    "rule": {
      "dispatchRuleIndividual": {
        "roomPrefix": "call-"
      }
    },
    "name": "My dispatch rule",
    "roomConfig": {
      "agents": [
        {
          "agentName": "service-agent",
          "metadata": "dispatch metadata"
        }
      ]
    }
  }
}
I trigger it with a google voice call to my sip inbound number. here's the trunk
Copy code
{
  "trunk": {
    "name": "My trunk",
    "numbers": [
      "+snip"
    ],
    "krispEnabled": true
  }
}
here's the last room that was created: call-_anonymous_ZWwb7zXAkXzq My google voice comes in anonymous, but that should matter for this
t
Thanks — I’m responding to your dispatch, trunk, and recent room example. Why this is happening (short) • Your dispatch rule matches any room with prefix "call-" and targets the deployed agent
hvac-service-agent
. When a SIP call creates room
call_anonymous_...
, the cloud dispatch rule assigns that job to the deployed cloud agent. Your local worker (even with a different name) only registers — it never receives that job — so you see only the registration log locally and full call activity in the LiveKit Cloud logs. What to change so your local run receives the job (pick one) 1) Use a test room prefix (recommended, no prod changes) • Make the test call create a room with a different prefix, e.g.
testcall-...
instead of
call-
. • Join that
testcall-...
room from a client (Agents Playground or test client). • Run your local agent (unique agent_name) — it will get the job because the prod dispatch rule doesn't match. 2) Scope dispatch rules to exclude test rooms • Change production dispatch rule to only match
prod-call-
(or similar). • Use
call-
→
prod-call-
for production calls. • Use
test-call-
locally. This prevents production agent from claiming test sessions. 3) Manually create a job that targets your local agent • Use the Agents Playground or an API/CLI to create a job that specifically targets your local agent_name (no dispatch rule involved). • Start your local agent; it will accept the job and print full logs. 4) Temporarily disable the production dispatch rule (if safe) • Turn off or rename the rule while you run tests, then re-enable it after. • This makes incoming SIP calls eligible for your local agent. Quick verification checklist (do these now) • Confirm production dispatch rule remains as shown (matches
call-
). • Make a test room name that does NOT start with
call-
(e.g.,
testcall-local-1
) and join it. • Start local agent with distinct
AGENT_NAME
and DEBUG logging. • Observe local terminal — you should now see session start, participant events, egress start/finish, etc. One minimal concrete step to try immediately • Place a test call that results in a room name NOT starting with "call-". Or manually create/join
testcall-local-1
in the Agents Playground. Then run: uv run python src/agent.py dev --log-level=DEBUG You should see session logs when the local agent gets the job. If that still doesn’t produce local call logs, paste: • The exact test room name you used, • The local agent_name shown in startup logs, • The first 20 lines of terminal logs after the test join. I’ll pinpoint the next minimal change.
b
where do I create testcall-local-1
t
You can create/join a test room in three easy ways so your local agent receives the job (none of these will match your production dispatch rule if the room name does NOT start with "call-"): 1) Agents Playground (quick, no code) • Open the Agents Playground. • Enter the room name
testcall-local-1
and join as a participant. • Start your local agent (with a unique
AGENT_NAME
) — your agent will receive the job for that room if no dispatch rule matches it. 2) LiveKit CLI (manual job/egress) • Create or join the room via CLI: ◦ Create a participant or start a session that connects to
testcall-local-1
(use the playground/your test client to join the room). • Optionally run egress for that room with the CLI after the local agent joins. 3) Use your SDK or a tiny script (most flexible) • Run a short script in JS/Python to connect a test participant to `testcall-local-1`: ◦ Ensure the script uses the same LiveKit project credentials as your local agent. ◦ Join the room; once the room exists and your local agent is running, it will be assigned the job. Checklist to ensure the local agent gets the job • Room name must NOT start with "call-" (e.g.,
testcall-local-1
). • Local agent runs with a distinct
AGENT_NAME
and has
.env.local
loaded. • No dispatch rule in cloud matches
testcall-local-1
. • Start your local agent before or immediately after joining the test room. • Add debug logs at session entry to confirm assignment. If you want, I can give: • A one‑file Python snippet you can run to join
testcall-local-1
, or • Exact Agents Playground instructions (link and UI steps). Which do you prefer?
b
tive me the exact agents playground instructions to create a room. This is not for video, will just be two participants, a caller from to my telnyx number, and an agent, audio only
t
Follow these steps in the Agents Playground to create/join an audio-only test room so your local agent receives the job and you can see local logs. 1. Start your local agent • Run your agent locally with a distinct agent name and debug logging: uv run python src/agent.py dev --log-level=DEBUG • Confirm the startup log shows your local agent name (e.g.,
hvac-service-agent-local
). 1. Open the Agents Playground • Go to: https://agents-playground.livekit.io/ 1. Enter room and identity • In the Playground UI, set: ◦ Room Name: testcall-local-1 ◦ Identity: caller-test (or any string) 1. Connect as the caller • Click Connect (or Join). Allow microphone access when the browser prompts. 1. Confirm the local agent receives the job • In your local terminal you should see session-start logs (room name, participant joins) and any debug logs your agent emits. • If you only see the registration log and no session logs, the room name likely matches a production dispatch rule — ensure it does NOT start with "call-". 1. (Optional) Use your Telnyx number as caller • To test with a real PSTN caller, have Telnyx/SIP inbound create or join the same room name
testcall-local-1
. Ensure your production dispatch rules do not match that room name so the cloud agent won’t claim it. 1. Troubleshooting • If no session logs appear: ◦ Verify
AGENT_NAME
printed at startup equals your local agent name. ◦ Verify the room name in the LiveKit dashboard matches
testcall-local-1
. ◦ Ensure no dispatch rule matches
testcall-local-1
. ◦ Add an explicit debug log at session entry (e.g., log ctx.room.name) to confirm assignment. Do you want a tiny JS/Python snippet to programmatically join
testcall-local-1
instead of using the browser?
b
nah that's not how the ux works, when I start on the agent playgroud it have two options; LiveKitCloud with a few agent names, or Manual with a wss url and room token if I pick, my agent on livekit cloud and press connect I am taken to a room that starts with playgroud and already has an id, and my options after that are RPC method, RPC payload and Perform RPC call
t
Thanks — I see the Playground UX you described. Use the Playground’s Manual mode so you can join a test room that your local agent can handle (not the cloud-picked "Playground" room). Steps: 1. Generate a room token for testcall-local-1 • Use the LiveKit CLI or a short script to create a token scoped to room
testcall-local-1
and an identity (e.g.,
caller-test
). Example CLI (if you have
lk
auth configured): ◦ Create a token via your own helper script or SDK that signs a token for room
testcall-local-1
(I can paste a one-line example if you want). 1. Open Agents Playground → choose Manual • For WebSocket URL use your project WSS URL (e.g.,
wss://<your-project>.livekit.cloud
). • For Room Token paste the token you generated. • For Room Name enter
testcall-local-1
(must match token). • Identity:
caller-test
. 1. Connect from Manual mode • Click Connect. This will join the exact room
testcall-local-1
instead of the auto-playground room. 1. Ensure local agent receives the job • Start your local agent with unique
AGENT_NAME
and DEBUG logging before or right after connecting: uv run python src/agent.py dev --log-level=DEBUG • Confirm your local agent startup shows that agent_name. • Because
testcall-local-1
does not start with
call-
, the production dispatch rule will not claim it. Your local agent should be assigned the session and you’ll see session logs (participant joins, egress start, etc.) in your terminal. 1. If you need to test with your Telnyx PSTN caller • Make sure the inbound SIP/Trunk flow or your test script creates/joins the same
testcall-local-1
room (or a non-
call-
prefixed test room). If the SIP inbound automatically names rooms with
call-...
, it will trigger the production dispatch rule and be claimed by the deployed agent. If you want, I’ll provide: • A one-file Python script to mint a room token for
testcall-local-1
, or • Exact CLI/SDK commands for your environment to generate the token. Which would you like?
b
what's an easy way to do this, what is a common workflow set up so I can simply run uv run python src/agent.py dev --log-level=DEBUG and make calls that run logs locally? there's a config step missing for us devs here. Claude said it's dispatch for local and I feel like you're just painfully headed in that direction
t
Totally get the frustration — you should be able to run one command and see full call logs locally. Here’s a small, reliable developer workflow that most teams use so
uv run python src/agent.py dev --log-level=DEBUG
produces call-level logs locally without touching production. Summary (one-sentence) • Create test rooms that do NOT match your production dispatch rule (avoid the "call-" prefix) and run your local agent under a unique agent name; then make calls that land in those test rooms so the cloud won’t assign them to the deployed agent. Minimal step-by-step (do this exactly) 1. Make your local agent use a distinct agent name • In
.env.local
set: AGENT_NAME=hvac-service-agent-local • Ensure you load
.env.local
before initialization (you already did). 1. Start your local agent • Run: uv run python src/agent.py dev --log-level=DEBUG • Confirm startup shows
agent_name=hvac-service-agent-local
. 1. Use a test room prefix (no prod dispatch) • Pick a room name that does NOT start with "call-" (example): testcall-local-1 1. Create/join that test room (easy, no token gymnastics) • Open Agents Playground → Manual. • For WSS URL use your project WSS (same project as prod). • For Room Token use the Playground’s built-in token generator (Manual mode will prompt or let you paste a token; if it requires you to generate one, use a tiny helper below). • Room name: testcall-local-1 • Identity: caller-test • Connect — this creates the exact room name in the cloud. 1. Make sure production dispatch cannot claim it • Confirm your production dispatch rule only matches rooms starting with
call-
. Because
testcall-local-1
doesn’t match, the cloud agent won’t claim it. 1. Observe local logs • After the Playground joins testcall-local-1, your local terminal should show session start logs (room join, participant events, egress starts). Add an explicit debug log at the start of your entrypoint if you want guaranteed visibility: logger.debug("session started for room=%s worker=%s", ctx.room.name, ctx.worker_id) Optional: Quick token helper (if Playground prompts for a token) • Use a tiny server/script to mint a room-scoped token for
testcall-local-1
with your project API key/secret. I can paste a one‑file Python example if you want it. Why this is the common workflow • Production dispatch rules assign matching rooms to the deployed agent. Using test rooms isolates local runs without changing or disabling production. • Running locally while joining a non-matching room lets the local worker receive the job and produce full logs while egress and recording still happen in the cloud. If this still doesn’t show local logs, paste these three small things and I’ll give the exact one-line fix: • The Agent startup line you see (first 5 lines). • The exact room name you used (e.g., testcall-local-1). • A one-line snippet where you log session start (or I’ll show where to add it). I’ll then give the single command or tiny code line to make it work.
b
great, and where can I find what you just said in the livekit docs?
t
Totally understand — you want a single, reliable dev workflow so
uv run python src/agent.py dev --log-level=DEBUG
gives you full call logs locally without disturbing production. Here’s the simplest, battle-tested setup and the exact doc pages that cover each piece. Minimal, reliable developer workflow (do these steps) 1) Use a distinct local agent name • In
.env.local
set: AGENT_NAME=hvac-service-agent-local • Load
.env.local
before any LiveKit init (use python-dotenv or equivalent). 2) Avoid production dispatch matching • Keep your production dispatch rule matching "call-" unchanged. • Use test rooms that do NOT start with "call-" (e.g.,
testcall-local-1
) so the prod agent won’t claim them. 3) Start your local agent • Run: uv run python src/agent.py dev --log-level=DEBUG • Confirm startup shows your local agent name. 4) Create / join the test room manually (so it’s not dispatched to prod) • Use Agents Playground → Manual mode: ◦ WSS URL: your project WSS (wss://<project>.livekit.cloud) ◦ Room Name: testcall-local-1 ◦ Identity: caller-test ◦ Room Token: paste a token you mint (or use the Playground helper) ◦ Connect • Or run a tiny script to join
testcall-local-1
with your SDK. 5) Observe local logs • Your local terminal will show session start, participant joins, egress starts, etc., because the room name doesn’t match the production dispatch rule and your local worker will be assigned the job. If you prefer a one-click pattern: • Use a test prefix (e.g.,
testcall-
) everywhere for dev, and keep prod on
call-
. Then running
uv run ... dev
+ joining
testcall-*
always hits your local worker. Docs that back this up • Voice AI quickstart / agent CLI modes: https://docs.livekit.io/agents/start/voice-ai/#speak-to-your-agent • Environment variables / local secrets: https://docs.livekit.io/agents/start/voice-ai/#environment-variables and https://docs.livekit.io/agents/ops/deployment/secrets/ • Agent dispatch (telephony): https://docs.livekit.io/agents/start/telephony/#agent-dispatch • SIP dispatch rules: https://docs.livekit.io/sip/dispatch-rule/ • Phone numbers & trunks: https://docs.livekit.io/sip/cloud/phone-numbers/ If you want, I can: • Paste a tiny Python script to mint a room token for
testcall-local-1
, or • Give a 1-file script that joins that room automatically from your machine. Which would you like? Sources: Voice AI quickstart | LiveKit docs | Deploying to custom environments | LiveKit Docs | Secrets management | LiveKit docs | Agents telephony integration | LiveKit docs | SIP dispatch rule | LiveKit docs
b
step 4 is asking for 4) Create / join the test room manually (so it’s not dispatched to prod) • Use Agents Playground → Manual mode: ◦ WSS URL: your project WSS (wss://<project>.livekit.cloud) ◦ ROOM TOKEN
t
You need a room-scoped join token. Two easy ways: (A) mint one with the LiveKit CLI (if configured), or (B) run a tiny Python script. Pick whichever fits — both produce the Room Token to paste into Playground → Manual. A) Using the LiveKit CLI (if you have
lk
set up) 1. Create a short JSON file token request (optional) or run: lk token create --room testcall-local-1 --identity caller-test 1. Copy the token output and paste it into Playground → Manual → Room Token. B) One-file Python token generator (run locally) 1. Save this as
mint_token.py
and fill in
API_KEY
,
API_SECRET
, and
LIVEKIT_URL
(your project host, e.g., "your-project.livekit.cloud"):
Copy code
import jwt
import time
import base64
from urllib.parse import urlparse

API_KEY = "your_api_key"
API_SECRET = "your_api_secret"
ROOM = "testcall-local-1"
IDENTITY = "caller-test"
TTL = 60 * 5

now = int(time.time())
payload = {
  "jti": f"token-{now}",
  "iat": now,
  "exp": now + TTL,
  "sub": API_KEY,
  "room": ROOM,
  "video": False,
  "audio": True,
  "name": IDENTITY,
  "kid": API_KEY
}
token = jwt.encode(payload, API_SECRET, algorithm="HS256")
print(token)
1. Install PyJWT if needed:
pip install pyjwt
. 2. Run:
python mint_token.py
3. Copy the printed token into Playground → Manual → Room Token. Ensure Room Name =
testcall-local-1
and Identity =
caller-test
. Manual mode fields in Playground • WSS URL: wss://<your-project>.livekit.cloud (example: wss://myproj.livekit.cloud) • Room Token: (token you generated) • Room Name: testcall-local-1 • Identity: caller-test Order to run for local logs 1. Start local agent: uv run python src/agent.py dev --log-level=DEBUG 2. In Playground → Manual, paste WSS URL and Room Token, set Room Name and Identity, then Connect. 3. Your local agent (with distinct AGENT_NAME) should receive the job and print the session logs locally. If you want, I can produce a one‑line
lk
CLI command for your environment or tailor the Python script to read API keys from
.env.local
. Which do you prefer?
b
there is no room name, I get this in my logs when I start my agent: INFO livekit.agents registered worker {"agent_name": "hvac-service-agent-local", "id": "AW_tWZGNnZgnsSk", "url": "wss://hvac-agent-hello-67gp4wqp.livekit.cloud", "region": "US West B", "protocol": 16} how what do I generate a room token with?
t
Totally — you can pick any test room name (e.g.,
testcall-local-1
). Your local agent doesn’t create the room; a participant must join it using a room-scoped token. Here are two minimal ways to mint a token you can paste into Playground → Manual. A) One‑line lk CLI (if you have
lk
configured) 1. Run: lk token create --room testcall-local-1 --identity caller-test 1. Copy the token output into Playground → Manual → Room Token, set Room Name = testcall-local-1, Identity = caller-test, WSS = your project wss URL. B) Tiny Python script that reads keys from .env.local 1. Save as
mint_token.py
next to your
.env.local
(fills API key/secret from env):
Copy code
# mint_token.py
import os, time, jwt
from dotenv import load_dotenv
load_dotenv(".env.local")

API_KEY = os.getenv("LIVEKIT_API_KEY")
API_SECRET = os.getenv("LIVEKIT_API_SECRET")
ROOM = "testcall-local-1"
IDENTITY = "caller-test"
TTL = 60*5
now = int(time.time())
payload = {
  "jti": f"token-{now}",
  "iat": now,
  "exp": now + TTL,
  "sub": API_KEY,
  "room": ROOM,
  "name": IDENTITY,
  "video": False,
  "audio": True
}
print(jwt.encode(payload, API_SECRET, algorithm="HS256"))
1. Install deps: pip install pyjwt python-dotenv 2. Run: python mint_token.py — copy printed token into Playground → Manual. Order to test 1. Start your local agent: uv run python src/agent.py dev --log-level=DEBUG 2. Open Playground → Manual, paste WSS URL, Room Token, Room Name = testcall-local-1, Identity = caller-test, Connect. 3. Your local agent (with unique AGENT_NAME) should receive the job and print full session logs. If you want, tell me which method you prefer and I’ll adapt the script to your
.env.local
keys or give the exact
lk
command for your project.
b
got it, so I just did this order: Order to test 1. Start your local agent: uv run python src/agent.py dev --log-level=DEBUG 2. Open Playground → Manual, paste WSS URL, Room Token, Room Name = testcall-local-1, Identity = caller-test, Connect. 3. Your local agent (with unique AGENT_NAME) should receive the job and print full session logs. I see my room in playground: It says I am connected, but when. I call the number nothing has changed, I get no local logs, the room appears to be connected to my computer mic, as almost as if I started local with console instead of dev.
t
Thanks — I’m responding to why your Playground manual room shows connected but inbound PSTN calls still go to the cloud and don’t produce local logs. Short answer • The manual room you joined in the Playground is a different session than the SIP inbound call. Dev mode only logs call activity locally when your local agent is the worker assigned to the room created by that inbound call. Right now the inbound SIP call creates a room with the "call-" prefix and is claimed by the deployed cloud agent, so your local agent never gets that job. What you can do now (pick one, in order of safety) 1) Make the inbound SIP call create/join a non-prod test room • Change the SIP flow (or trunk config) so the inbound call uses a test room name (e.g.,
testcall-local-1
) instead of
call_*
. • How: modify whatever creates the room for the SIP inbound (your SIP->LiveKit mapping or webhook) so it uses a test room name or prefix that does NOT match "call-". Result: the cloud dispatch rule will not match, your local worker will be assigned, and you’ll see full local logs. 2) Create a test dispatch rule that targets your local agent name • Add a temporary dispatch rule that routes a specific test phone number (or a specific rule matching a header) to
hvac-service-agent-local
only. • Use that test phone number to call. This keeps prod untouched and forces the job to your local worker. Result: inbound call lands on your local worker. 3) Manually create the room the inbound flow would use, then bridge the SIP call into that same room • Create/join
testcall-local-1
first (Playground or token), then make the SIP incoming call join that room (adjust your SIP->LiveKit integration/webhook to target that exact room). Result: both caller and local agent are in same room and local logs appear. 4) Temporarily disable/rename the prod dispatch rule (quick test) • If safe, temporarily remove or rename the prod rule so calls aren’t auto-claimed by the cloud agent, then call your number. Result: inbound calls become eligible for your local agent. Quick verification steps you can run now 1. Start local agent: uv run python src/agent.py dev --log-level=DEBUG 2. In Playground Manual, join
testcall-local-1
(WSS + token). Confirm local terminal shows session start logs. 3. Try to make the same inbound number join that exact room (change your SIP mapping/webhook to use that room name). If you can’t change SIP mapping, use option 2 and add a test dispatch rule for one test number. If you want, tell me: • Which option you prefer (1–4) and whether you can change the SIP->room mapping or add a temporary dispatch rule. I’ll give the exact one-line CLI or config change to make that option work.
b
ah I figured it out, although you should have just directed me to the paragraph in the docs that say you should run multiple projects for dev, prod. I didn't see that
t
Thanks — glad you figured it out, and I appreciate the feedback about the docs. Quick confirmation and doc pointer • The recommended pattern is to separate dev and prod (different agent names, dispatch rules, or projects) so local runs don’t clash with deployed agents. • The LiveKit docs that cover this are the Agent CLI / Voice AI quickstart and the Telephony/Dispatch pages: ◦ Voice AI quickstart (agent CLI modes & local testing): https://docs.livekit.io/agents/start/voice-ai/#speak-to-your-agent ◦ Agent dispatch for telephony (dispatch rules & agent names): https://docs.livekit.io/agents/start/telephony/#agent-dispatch ◦ SIP dispatch rules: https://docs.livekit.io/sip/dispatch-rule/ If you want I can: • Point to the exact paragraph(s) in those pages that mention separating environments, or • Draft a tiny checklist you can add to your repo README for dev vs prod runs. Which would help you most?
b
All good now. thanks