modern-winter-66316
12/06/2025, 1:09 AMtall-airline-16756
12/06/2025, 1:09 AMtall-airline-16756
12/06/2025, 1:10 AMmodern-winter-66316
12/06/2025, 1:10 AMtall-airline-16756
12/06/2025, 1:10 AMyourproject.livekit.cloud).
2. In livekit.toml set the project subdomain under [project] (e.g., subdomain = "yourproject").
3. Deploy your agent with the LiveKit CLI (for example lk agent create) — the agent is automatically associated with the project subdomain.
If you need SIP endpoints, construct them with your project subdomain and region: {sip_subdomain}.{region}.sip.livekit.cloud.
Would you like steps for creating the project, an example livekit.toml, or the exact lk CLI command to run?
Sources: Mini tutorial: setting up a LiveKit Cloud project | Deploying to production | LiveKit Docs | SIP cloud and region pinning | LiveKit docsmodern-winter-66316
12/06/2025, 4:38 AMtall-airline-16756
12/06/2025, 4:38 AMRoomConfiguration and RoomAgentDispatch from livekit.api, not livekit.protocol.
2) Required parameters for RoomAgentDispatch
• Only agent_name is required.
• metadata is optional and should be a string (JSON is fine).
• agent_id is not a valid parameter for RoomAgentDispatch and will cause errors.
3) What’s wrong with your code & corrected snippet
• Problems: you imported from livekit.protocol and passed agent_id.
• Fix: import from livekit.api and remove agent_id.
Corrected example:
from livekit import api
from livekit.api import RoomConfiguration, RoomAgentDispatch
import json
room_config = RoomConfiguration(
agents=[
RoomAgentDispatch(
agent_name="cloud-english-teacher",
metadata=json.dumps({"persona": "English Teacher"})
)
]
)
token = (
api.AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET)
.with_identity(identity)
.with_name("Student")
.with_grants(grants)
.with_room_config(room_config)
.to_jwt()
)
If you still see errors when running this in your Vercel function, please share the exact error message and the SDK version you’re using so I can help further. Would you like the exact lk CLI command to verify the agent name?
Sources: Agent dispatch | LiveKit docs | Authentication | LiveKit docs | SIP dispatch rule | LiveKit docs | server-sdk-kotlin | livekit/livekit_composite | DeepWikimodern-winter-66316
12/06/2025, 4:53 AMtall-airline-16756
12/06/2025, 4:53 AMagent_name you used (case-sensitive).
• Agent not running/registered: ensure the agent server is started and shows as registered with LiveKit Cloud.
• Dispatch method: confirm whether you expect automatic dispatch on join (token-based) or explicit dispatch via API. If the agent server has an agent_name set, automatic dispatch is disabled and you must explicitly dispatch.
• Token contents: decode the JWT and confirm it contains room_config.agents with your RoomAgentDispatch. If it’s missing, the agent won’t be dispatched on join.
• Agent server logs: check for any errors or incoming dispatch requests that were rejected.
Please provide
• How the agent is deployed (LiveKit Cloud CLI, Cloud UI, or self-hosted)
• Whether you intend token-based (automatic) dispatch or API/explicit dispatch
• The exact agent name you registered (copy/paste)
• A decoded JWT payload (redact secrets) or confirm presence of room_config.agents
• Agent server logs or any error lines you see
Send those and I’ll point to the next steps (fix token, dispatch via API, or check agent registration) and give the exact commands/snippets you’ll need.
Sources: SIP troubleshooting guide | LiveKit docs | Agent server | LiveKit docs | Agent dispatch | LiveKit docs | SIP dispatch rule | LiveKit docsmodern-winter-66316
12/06/2025, 4:55 AMtall-airline-16756
12/06/2025, 4:55 AMagent_name set, automatic dispatch is disabled. That means clicking Start must trigger an explicit dispatch call to LiveKit.
2) If you want explicit dispatch on button click (recommended given your description)
• On Start button pressed, have your server call CreateAgentDispatch (LiveKit API) for that room with agent_name="cloud-english-teacher" and optional metadata.
• Example flow:
a. Client clicks Start -> hits your backend endpoint (authenticated).
b. Backend calls the LiveKit CreateAgentDispatch API for room "lesson-..." specifying agent_name.
c. LiveKit assigns the job to the running agent server and the agent joins the room.
3) If you prefer token-based dispatch on join
• Ensure the JWT you issue includes room_config.agents with a RoomAgentDispatch that has agent_name="cloud-english-teacher" (and metadata as a JSON string).
• Also ensure the agent server does NOT have agent_name set in a way that disables automatic dispatch (or use a nameless agent for automatic dispatch).
4) Immediate checks to run now
• Decode the token you generated and paste the payload (redact secrets). Confirm presence/absence of room_config.agents.
• Check agent server logs for incoming dispatch attempts or errors around the time you press Start.
• Confirm exact agent name string (copy/paste) — it must match exactly.
If you want, tell me which method you prefer (explicit API dispatch on Start, or token-based auto-dispatch). I can then:
• Provide the exact CreateAgentDispatch API request example (JS/Node or Python) to call from your backend, or
• Show the corrected token-generation snippet that embeds room_config.agents.modern-winter-66316
12/06/2025, 4:56 AMtall-airline-16756
12/06/2025, 4:56 AMagent_name (that setting disables automatic dispatch).
• Easier to debug and observe in agent/server logs vs relying on token timing.
What to do next (high level)
1. User clicks Start → frontend calls your backend endpoint.
2. Backend calls LiveKit CreateAgentDispatch for the room with agent_name="cloud-english-teacher" and any metadata.
3. LiveKit assigns the job and the agent server joins the room and begins speaking.
Would you like the exact CreateAgentDispatch request example in Node or Python and the minimal backend endpoint code?modern-winter-66316
12/06/2025, 4:57 AMtall-airline-16756
12/06/2025, 4:57 AMfrom fastapi import FastAPI, Request, HTTPException
import os
import json
import time
import hmac
import hashlib
import base64
import requests
app = FastAPI()
API_KEY = os.environ["LIVEKIT_API_KEY"]
API_SECRET = os.environ["LIVEKIT_API_SECRET"]
PROJECT_HOST = os.environ["LIVEKIT_PROJECT_HOST"] # e.g. turbo-ms4yz8cm.livekit.cloud
AGENT_NAME = "cloud-english-teacher"
def make_auth_header(api_key: str, api_secret: str):
# LiveKit REST uses HMAC-based Authorization: Authorization: LK <apiKey>:<signature>
ts = str(int(time.time()))
msg = f"{api_key}:{ts}".encode()
sig = hmac.new(api_secret.encode(), msg, hashlib.sha256).hexdigest()
return {"Authorization": f"LK {api_key}:{sig}", "LiveKit-Timestamp": ts, "Content-Type": "application/json"}
@app.post("/dispatch")
async def dispatch(request: Request):
body = await request.json()
room_name = body.get("room_name")
metadata = body.get("metadata") # dict or string
if not room_name:
raise HTTPException(status_code=400, detail="room_name required")
if isinstance(metadata, dict):
metadata = json.dumps(metadata)
url = f"https://{PROJECT_HOST}/v1/agents/dispatch"
payload = {
"room": room_name,
"agent_name": AGENT_NAME,
"metadata": metadata or ""
}
headers = make_auth_header(API_KEY, API_SECRET)
resp = requests.post(url, headers=headers, json=payload, timeout=10)
if resp.status_code != 200:
raise HTTPException(status_code=resp.status_code, detail=resp.text)
return resp.json()
Notes and tips
• Use the project host for your LiveKit Cloud project (the same subdomain used by your frontend WebSocket URL).
• Ensure the agent server is running and registered under the exact name cloud-english-teacher.
• Check agent logs after dispatch — they show assignment and join events.
• If your environment (Vercel serverless) restricts outgoing requests, ensure outbound HTTPS to LiveKit is allowed.
• If your LiveKit deployment requires different auth, adjust the auth header accordingly. If you’d like, I can produce a version using the official LiveKit Python SDK or show how to call this from your frontend.
Would you like the same example using the LiveKit Python SDK (if available) or a minimal curl example to test quickly?modern-winter-66316
12/06/2025, 4:59 AMtall-airline-16756
12/06/2025, 5:00 AMroom_config.agents with a RoomAgentDispatch that has agent_name: "cloud-english-teacher" and optional metadata (JSON string).
• Ensure you import and build `RoomConfiguration`/`RoomAgentDispatch` from livekit.api (not livekit.protocol).
• The agent name in the token must exactly match the agent server’s registered name (case-sensitive).
• The agent server must be running and registered with LiveKit Cloud (check agent logs for incoming dispatch jobs).
• If your agent was created with an agent_name that disables automatic dispatch, automatic dispatch will not occur — in that case use explicit CreateAgentDispatch instead.
• Decode your issued JWT and confirm room_config.agents is present and correct. Also check LiveKit and agent server logs at the time the room is created.
If you want, paste the decoded token payload (redact secrets) or the agent server log lines around the room creation and I’ll spot any mismatch or missing field.modern-winter-66316
12/06/2025, 5:00 AMtall-airline-16756
12/06/2025, 5:00 AMagent_name. If the agent was created with agent_name that disables automatic dispatch, it will not auto-join.
• The JWT you issue must contain room_config.agents (RoomAgentDispatch) — if the token lacks it, no dispatch is triggered.
• If your frontend directly creates the token or room without a backend step, you may be issuing tokens that don’t include the room config or are missing required grants.
Two options (choose one)
1) Continue token-based automatic dispatch (keep current simpler approach)
• Ensure your JWT includes room_config.agents with agent_name: "cloud-english-teacher" and metadata as a JSON string.
• Import/build the room config from livekit.api in your token generation code:
◦ from livekit.api import RoomConfiguration, RoomAgentDispatch
• The agent server must be running and registered under exactly cloud-english-teacher.
• If the agent was created with agent_name that disables auto-dispatch, recreate or update it so automatic dispatch is allowed.
• Verify by decoding the token and confirming room_config.agents is present; check agent logs for incoming dispatch.
2) Recommended — explicit dispatch on Start (more reliable, minimal backend)
• When user presses Start, call LiveKit’s CreateAgentDispatch from a small serverless endpoint (Vercel function, Cloud Run, etc.). This is reliable even if agent has agent_name set.
• Minimal flow:
a. Frontend: POST /dispatch with room_name and metadata.
b. Backend: call POST https://{project_subdomain}.livekit.cloud/v1/agents/dispatch with room, agent_name, metadata.
c. LiveKit assigns agent and agent server joins room.
• Use HMAC auth header pattern shown earlier or the LiveKit SDK if available in your environment.
Quick next steps I can provide right now
• If you want to keep token-based dispatch: paste the decoded JWT payload (redact secrets) and I’ll confirm room_config.agents is correct.
• If you prefer explicit dispatch: I can give a compact Vercel serverless function example (Python or Node) to call CreateAgentDispatch with the exact headers/payload.
Which do you want to do now — verify the token or add a tiny dispatch endpoint?modern-winter-66316
12/06/2025, 5:13 AMtall-airline-16756
12/06/2025, 5:13 AMroom, agent_name, and metadata (metadata can be empty string).
• Agent server: verify agent is running and able to accept dispatches.
Quick code fixes (Python)
• Use resp.status_code and resp.text to inspect non-JSON responses before json.loads.
• Prefer resp.json() inside try/except; handle JSONDecodeError by returning resp.text.
Minimal corrected pattern:
1) Inspect status and body
resp = requests.post(url, headers=headers, json=payload, timeout=10)
print("status:", resp.status_code)
print("body:", resp.text[:200])
if resp.status_code != 200:
raise Exception(f"Dispatch failed: {resp.status_code} {resp.text}")
try:
data = resp.json()
except ValueError:
raise Exception(f"Invalid JSON response: {resp.text!r}")
2) Ensure headers include Accept and Content-Type
headers = {
"Authorization": f"LK {API_KEY}:{signature}",
"LiveKit-Timestamp": ts,
"Content-Type": "application/json",
"Accept": "application/json",
}
If you run that and still get "OK", paste:
• the printed status code and resp.text
• your full dispatch URL and headers (redact secrets)
• the exact payload body
I’ll review those and give the exact fix. Which of those outputs can you share?modern-winter-66316
12/06/2025, 5:18 AMtall-airline-16756
12/06/2025, 5:19 AMroom_admin=True (and room_join=True for the target room).
2. Yes — check the agent logs immediately after dispatch; they show if the agent received the job and why it may have declined or failed to join. Use lk agent logs --project "<project-id>" --id "<agent-id>".
3. The auth method (JWT via Authorization header) is correct, but the JWT must carry the admin grant. The dispatch endpoint won’t successfully cause the agent to join if the token lacks room_admin.
4. Yes — agent config matters. If the agent was registered with an agent_name that disables automatic dispatch, explicit dispatch is required and the agent_name used in the API call must exactly match the registered name.
Exact fix — generate a proper dispatch token (Python)
from livekit import api
from livekit.apis.rtc import VideoGrant
token = (
api.AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET)
.with_grants(VideoGrant(room="lesson-xxx", room_join=True, room_admin=True))
.to_jwt()
)
# Use this JWT as Authorization: Bearer <token> in your POST to /v1/agents/dispatch
What to do now (step-by-step)
1. Regenerate a dispatch token using the snippet above (replace room).
2. Call POST https://{project_subdomain}.livekit.cloud/v1/agents/dispatch with JSON:
{ "room": "lesson-xxx", "agent_name": "cloud-english-teacher", "metadata": "{\"persona\":\"Taxi Driver\"}" } and Authorization: Bearer <token>. Include Content-Type and Accept application/json headers.
1. Immediately tail agent logs:
lk agent logs --project "<project-id>" --id "CA_e7hLTus66nKZ" Look for job assignment or join attempts and any error lines.
1. If no log lines appear, verify the agent is RUNNING in Cloud and the registered name exactly equals "cloud-english-teacher". If agent logs show an error, paste the relevant lines.
If you want, paste:
• The dispatch response status and body (you said 200/OK — include headers if possible)
• The agent log lines after dispatch (redact secrets)
I’ll read those and tell you the exact next action.
Sources: Agent dispatch | LiveKit docs | Authentication | LiveKit docs | sip | livekit/livekit_composite | DeepWiki | Log collection | LiveKit Docs | SIP APIs | LiveKit docsmodern-winter-66316
12/06/2025, 5:21 AMtall-airline-16756
12/06/2025, 5:21 AMidentity and room fields. When generating a token used to join a room (or to dispatch an agent that will join a room), you must set both.
Fix — include identity and room when creating the token. Example Python:
from livekit import api
from livekit.apis.rtc import VideoGrant
token = (
api.AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET)
.with_identity("dispatch-service") # required
.with_grants(VideoGrant(room="lesson-xxx", room_join=True, room_admin=True))
.to_jwt()
)
# Use Authorization: Bearer <token> for POST /v1/agents/dispatch
Checklist
• Set .with_identity(...) to a unique string for the service making the dispatch.
• Set VideoGrant(room="<room_name>", room_join=True, room_admin=True).
• Use that JWT in the Authorization header when calling /v1/agents/dispatch.
• Tail agent logs after dispatch to confirm it receives the job.
If you want, paste the snippet you’re using to generate the token (redact keys) and I’ll point out the exact line to change.modern-winter-66316
12/06/2025, 5:29 AMmodern-winter-66316
12/06/2025, 5:29 AMtall-airline-16756
12/06/2025, 5:29 AMsession.start(...) and then explicitly calls session.generate_reply(...) or session.say(...). Joining alone does not produce speech.
• Check agent logs for errors from LLM/TTS calls (API failures, auth errors, or timeouts).
• Ensure the agent is registered with the exact name cloud-english-teacher and running in LiveKit Cloud.
Minimal agent fix (Python pseudocode)
async def my_agent_handler(ctx: JobContext):
session = AgentSession(
stt="assemblyai/universal-streaming:en",
llm="openai/gpt-4.1-mini",
tts="cartesia/sonic-3:...token..."
)
await session.start(room=ctx.room, agent=Assistant())
# trigger the first utterance explicitly:
await session.generate_reply(instructions="Greet the user warmly and introduce the lesson.")
What to do now
1. Tail logs immediately after dispatch:
lk agent logs --project "<project-id>" --id "CA_e7hLTus66nKZ"
• If no join/start lines appear, the agent didn’t receive the dispatch.
• If join/start appears but no generate/say calls or errors follow, the agent code isn’t initiating speech or LLM/TTS failed.
1. If you want, paste the agent log lines shown after dispatch (redact secrets). I’ll pinpoint whether it’s a join problem, a missing generate/say call, or an LLM/TTS error and give the exact code or config change. Sources: Agents (Node.js) | livekit/livekit_composite | DeepWiki | Agents v0.x migration guide - Python | LiveKit docs | Agents telephony integration | LiveKit docs | Voice AI quickstart | LiveKit docstall-airline-16756
12/06/2025, 5:30 AMsession.start(), generate_reply() or TTS/LLM calls.
• Paste the relevant log lines here (redact secrets). If no join/start lines appear, the agent never received/accepted the job.
2) If logs show the agent joined the room
• Check whether agent code explicitly triggers speech after start. The agent will not speak automatically; you must call session.generate_reply() or session.say() after session.start().
• Minimal pattern (ensure equivalent exists in your agent code):
await session.start(room=ctx.room, agent=Assistant())
await session.generate_reply(instructions="Greet the user warmly and introduce the lesson.")
• If this call is missing, add it, redeploy, and test again.
3) If logs show no join/start or show errors on join
• Confirm the dispatch token had correct grants: token used for dispatch must include an identity and VideoGrant with room_join=True and room_admin=True. Example:
token = (
api.AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET)
.with_identity("dispatch-service")
.with_grants(VideoGrant(room="lesson-27305393", room_join=True, room_admin=True))
.to_jwt()
)
• Verify the agent_name in your dispatch call exactly matches the agent’s registered name (cloud-english-teacher).
• Look for LLM/TTS errors in logs (auth, rate limits, or timeouts) — these prevent speech even if joined.
4) Quick diagnostic you can run now
• Dispatch, then immediately run the logs command and paste 20–50 lines of output here.
• If you prefer, paste the decoded JWT payload used for dispatch (redact secrets) so I can confirm room_config / grants.
Tell me which log output you can share (agent logs or decoded token) and I’ll point to the exact line to change.
Sources: Deploying to production | LiveKit Docs | Agent dispatch | LiveKit docs | Agents telephony integration | LiveKit docsmodern-winter-66316
12/06/2025, 5:31 AMtall-airline-16756
12/06/2025, 5:32 AMmodern-winter-66316
12/06/2025, 5:33 AM