m
hi
t
Thanks for reaching out, aigentzi. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi — how can I help you today? Tell me what you're trying to do or any error you're seeing (project/room IDs, SDK/language, and a brief description are helpful).
m
please can you tell us why agent not joining room ?
t
Thanks — I’m looking into why your agent isn’t joining the room. To narrow this down quickly, please answer a few short questions about your setup and any errors you see: 1. Are you using automatic dispatch or explicit dispatch for agents? 2. Is this for a SIP inbound call, SIP outbound, or a standard participant connection? 3. Are you setting an
agent_name
in your agent code or dispatch request? If yes, what value (or confirm both sides match for SIP)? 4. Do you reuse room names or create a unique name per session? 5. Any error logs, timestamps, or observed behavior (e.g., agent cold-start delay ~10–20s, immediate failure, or silent no-join)? 6. Which SDK/language and plan (Build/cloud) are you running the agent on? With those details I’ll point to the most likely cause and the exact steps to fix it. Sources: Agent dispatch | LiveKit docs | SIP troubleshooting guide | LiveKit docs | Avoiding Room ID Reuse When Re-Creating Rooms With the Same Name | Quotas and limits | LiveKit docs | How to test your agent using another agent
m
can you read that text file ?
t
I can — please attach the text file here or paste its contents. If it contains logs, include the room ID, timestamps, and any error lines so I can pinpoint why the agent isn't joining.
m
t
I can read it — please paste the text file contents here (or attach the file). If it’s logs, include the room ID, agent name, timestamps, and any error lines.
m
Copy code
[DebugClient] Requesting token from /api/connect-debug
[DebugClient] Token endpoint response: {
  "token": "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiRW5nbGlzaCBUZWFjaGVyIFN0dWRlbnQiLCJ2aWRlbyI6eyJyb29tIjoiZW5nbGlzaC10ZWFjaGVyLTE3NjQ3MjQwNzYwNDItdDY0MGduNyIsInJvb21Kb2luIjp0cnVlLCJjYW5QdWJsaXNoIjp0cnVlLCJjYW5TdWJzY3JpYmUiOnRydWUsImNhblB1Ymxpc2hEYXRhIjp0cnVlfSwicm9vbUNvbmZpZyI6eyJhZ2VudHMiOlt7ImFnZW50TmFtZSI6IkNBXzRUMmN2cWJMNkp3SCIsIm1ldGFkYXRhIjoie1wic2NlbmFyaW9cIjpcImRlYnVnXCIsXCJsZXZlbFwiOlwiZGVidWdcIixcInZvaWNlX3Byb3ZpZGVyXCI6XCJsaXZla2l0XCIsXCJ2b2ljZVwiOlwiZGVmYXVsdFwifSJ9XX0sImlzcyI6IkFQSUxGSzY0V3JWTmVXTCIsImV4cCI6MTc2NDcyNDY3NiwibmJmIjowLCJzdWIiOiJ1c2VyLTE3NjQ3MjQwNzYzODQifQ.Dpkh_fzKj8eOjag9g7xEoiz_FRaLS2bqDQPuDXMzNX0",
  "url": "wss://englishlive-3qjapr2j.livekit.cloud",
  "room": "english-teacher-1764724076042-t640gn7",
  "metadata": {
    "scenario": "debug",
    "level": "debug",
    "voice_provider": "livekit",
    "voice": "default"
  },
  "dispatchId": null,
  "agentName": "CA_4T2cvqbL6JwH",
  "token_debug": {
    "name": "English Teacher Student",
    "video": {
      "room": "english-teacher-1764724076042-t640gn7",
      "roomJoin": true,
      "canPublish": true,
      "canSubscribe": true,
      "canPublishData": true
    },
    "roomConfig": {
      "agents": [
        {
          "agentName": "CA_4T2cvqbL6JwH",
          "metadata": "{\"scenario\":\"debug\",\"level\":\"debug\",\"voice_provider\":\"livekit\",\"voice\":\"default\"}"
        }
      ]
    },
    "iss": "APILFK64WrVNeWL",
    "exp": 1764724676,
    "nbf": 0,
    "sub": "user-1764724076384"
  }
}
[DebugClient] Decoded token payload: {
  "name": "English Teacher Student",
  "video": {
    "room": "english-teacher-1764724076042-t640gn7",
    "roomJoin": true,
    "canPublish": true,
    "canSubscribe": true,
    "canPublishData": true
  },
  "roomConfig": {
    "agents": [
      {
        "agentName": "CA_4T2cvqbL6JwH",
        "metadata": "{\"scenario\":\"debug\",\"level\":\"debug\",\"voice_provider\":\"livekit\",\"voice\":\"default\"}"
      }
    ]
  },
  "iss": "APILFK64WrVNeWL",
  "exp": 1764724676,
  "nbf": 0,
  "sub": "user-1764724076384"
}
[DebugClient] Connecting to wss://englishlive-3qjapr2j.livekit.cloud
[DebugClient] Connected. Local participant identity: user-1764724076384
[DebugClient] Published local audio track
[DebugClient] Staying connected for 30000ms to allow agent dispatch
[DebugClient] connectionQualityChanged excellent user-1764724076384
t
Thanks — I reviewed the logs you pasted (token fetch + connection). I’m responding about why the agent isn’t joining the room. What the logs show • The participant successfully requested and received a token that includes
roomConfig.agents
with
agentName: "CA_4T2cvqbL6JwH"
. • The client connected to wss://englishlive-3qjapr2j.livekit.cloud as
user-1764724076384
, published audio, and stayed connected waiting for agent dispatch. •
dispatchId
in the token response is null (no explicit dispatch was created). Next checks I need from you (quick answers) 1. Is your agent process/server running and able to receive dispatches? 2. Did you set
agent_name
in the agent code (e.g., WorkerOptions/@server.rtc_session)? If so, confirm it exactly equals
CA_4T2cvqbL6JwH
. 3. Are you expecting automatic dispatch or did you explicitly dispatch agents via API/SIP/participant token? (Token shows
roomConfig.agents
, which should dispatch the agent when the participant connects.) 4. Do you have agent-side logs from around this connection time showing any incoming dispatch, errors, or cold-start delays? 5. Which plan is this on (Build vs Cloud)? If Build, did the agent need a cold-start (10–20s delay)? Immediate troubleshooting steps you can try now • Confirm the agent process is online and listening for dispatches; check agent logs for an incoming dispatch matching
CA_4T2cvqbL6JwH
. • If the agent is configured with an explicit
agent_name
, ensure it exactly matches the token
agentName
. Mismatch prevents joins. • If you reuse room names often, create a unique room name for a fresh room and test again. • If on Build plan, allow ~20s after the participant connects for the agent cold-start and watch agent logs. If you prefer, paste the agent logs around the same timestamp (or confirm the answers to questions 1–5) and I’ll point to the exact cause and next fix.
m
agent s running : CA_4T2cvqbL6JwH
t
Thanks — you confirmed the agent process is running and its name matches
CA_4T2cvqbL6JwH
. To pinpoint why it still isn't joining, please answer these quick checks and share any agent logs if available: 1. How is the agent being dispatched — automatic (via
roomConfig.agents
in the token) or explicit (API/SIP)? 2. Do agent logs show an incoming dispatch or any errors at the time the participant connected? Please paste the agent log lines around that timestamp. 3. Which plan is the agent on (Build or Cloud)? If Build, did you observe a ~10–20s cold-start delay? 4. Are you reusing the same room name repeatedly or creating unique room names per session? 5. Does the agent require any special
RoomInputOptions
(e.g., to listen to agent audio) or other room configuration that might block joining? If you paste the agent-side logs for the connection time (or confirm answers 1–5), I’ll analyze them and give exact next steps.
m
i notice there is nmowhere to give an agent a name in livekit ?
t
You're right that LiveKit itself doesn't expose a top-level "agent name" field in the core SDK UI — agent naming is something you provide in your agent code and in dispatch/config so the dispatch system can match a running agent to a dispatch request. Quick summary of where to set the agent name and how dispatch works (pick the method you're using and I can give code examples): • In the agent code/process: ◦ If you set an
agent_name
in your agent server (for example via WorkerOptions or your framework's agent decorator), that value identifies the running agent instance. If you set this, automatic dispatch is disabled and the agent will only join when explicitly dispatched to that exact
agent_name
. • In the participant token or dispatch request: ◦ Include
roomConfig.agents
(in the token) or create an
AgentDispatch
via the API with
agentName: "YOUR_AGENT_NAME"
. When a participant connects with a token that contains
roomConfig.agents
, the system will attempt to dispatch an agent with that
agentName
. • For SIP inbound calls: ◦ Ensure the
agent_name
in the agent server matches the
agent_name
specified in the SIP dispatch rule (
RoomAgentDispatch.agent_name
). A mismatch prevents the agent from answering. What I can do next • If you tell me which SDK/language your agent uses (Node/Python/other) and whether you use automatic token-based dispatch or explicit API/SIP dispatch, I’ll give a short, exact code snippet showing where to set
agent_name
and how to dispatch.
m
Answers to your questions 1. How is the agent being dispatched? Automatic via token-based dispatch. The token includes roomConfig.agents: at.roomConfig = { agents: [{ agentName: AGENT_NAME, metadata: {...} }] }; 2. Agent logs Check with: lk agent logs CA_4T2cvqbL6JwH Look for: • "Agent configured with agent_name: CA_4T2cvqbL6JwH" (after the fix) • "Agent job received: room=..." when a participant connects • Any errors around connection time 3. Which plan? LiveKit Cloud (subdomain: englishlive-3qjapr2j). Cold-start delays may apply if the agent is on Build plan. 4. Room names Unique per session: const roomName = `english-teacher-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`; 5. RoomInputOptions Not set in the code, so defaults are used. No special configuration blocking agent joining. Fix applied The agent worker wasn't setting agent_name in WorkerOptions, so it wasn't matching the agentName in the token. Updated agent/main.py to: 1. Read AGENT_NAME from environment variable 2. Set agent_name in WorkerOptions to match the token's agentName
t
Thanks — you’ve given exactly the details needed. You're saying you added
agent_name
in the worker options and the token includes
roomConfig.agents
(automatic dispatch). That combination explains the behavior. Short explanation • When an agent process sets an
agent_name
in its WorkerOptions, automatic token-based dispatch is disabled for that agent process; the agent will only join when explicitly dispatched to that exact
agent_name
. Your token contains
roomConfig.agents
, which requests automatic dispatch, so the running agent didn't receive an automatic dispatch match. Two simple ways to fix (pick one) 1) Use automatic token-based dispatch (no
agent_name
in the agent process) • Remove setting
agent_name
from WorkerOptions so the agent can be auto-dispatched when a token contains
roomConfig.agents
. 2) Use explicit dispatch (keep
agent_name
in the agent and dispatch to it) • Keep
agent_name
in WorkerOptions and create a dispatch that targets that name (via the AgentDispatch API, or include the exact
agentName
in the participant token/dispatch request). What to check now • After making your chosen change, connect a participant with the token you posted and watch agent logs for either: ◦ "Agent job received: room=..." (explicit dispatch) or ◦ agent joining the room within ~10–20s (allow for Build cold-starts) if using automatic dispatch. • If you keep
agent_name
, verify the string exactly matches the token's
agentName
(
CA_4T2cvqbL6JwH
). If you'd like, tell me which option you prefer and I’ll provide a short code snippet for your agent language (Node or Python) showing the exact change and a sample dispatch call.
m
option 1 python please
t
You're choosing option 1 (automatic token-based dispatch). Below is a concise Python example showing the key change: do not set
agent_name
in WorkerOptions so the agent process remains eligible for automatic dispatch from
roomConfig.agents
. Python agent worker (minimal example)
Copy code
# agent/main.py
from livekit_agent import Worker, WorkerOptions, Agent  # adjust imports to your package

def create_agent():
    # DO NOT set agent_name here for automatic dispatch
    options = WorkerOptions(
        # agent_name=None,  # do not set or pass agent_name
        # other options as needed, e.g. region, logging, etc.
    )

    worker = Worker(options=options)

    @worker.on_rtc_session()  # example decorator - use your framework's handler
    async def handle_session(session):
        agent = Agent(session)
        await agent.run()

    return worker

if __name__ == "__main__":
    worker = create_agent()
    worker.start()
Testing steps 1. Deploy this updated agent without an
agent_name
in WorkerOptions. 2. Connect a participant using a token that includes
roomConfig.agents
(like the token you posted). 3. Watch agent logs — you should see an incoming dispatch/job and the agent joining the room. Allow ~10–20s if the agent requires a cold-start. 4. Confirm the participant hears/receives the agent and that logs show something like "Agent job received: room=..." or "Joined room ...". If you want, tell me which Python agent library or decorator names you use (exact imports), and I’ll give a snippet tailored to your code.
m
Library: livekit-agents (official LiveKit Agents SDK) We're using the livekit-agents package, not livekit_agent. Imports from livekit.agents import AgentSession, JobContext, WorkerOptions, cli from livekit.agents.worker import ServerType Current code (automatic dispatch) def cli_entry() -> None: """CLI entrypoint that exposes console/dev/start commands.""" _# NOTE: We do NOT set agent_name here to enable automatic token-based dispatch._ _# When agent_name is set in WorkerOptions, automatic dispatch is DISABLED._ # Since we use roomConfig.agents in the token for automatic dispatch, we must _# leave agent_name unset so the agent can be auto-dispatched._ cli.run_app( WorkerOptions( _entrypoint_fnc_=entrypoint, _worker_type_=ServerType.ROOM, _# agent_name is intentionally NOT set - allows automatic dispatch via roomConfig.agents_ ) ) Entrypoint function async def entrypoint(_ctx_: JobContext) -> None: """Main entrypoint for LiveKit Worker.""" logger.info(f"Agent job received: room={ctx.job.room_name}, metadata={metadata}") await ctx.connect() # Join the room logger.info("Connected to LiveKit room") # ... rest of agent logic ... Differences from the example • Using: livekit.agents (official SDK) • Not using: livekit_agent • Pattern: cli.run_app(WorkerOptions(...)) with entrypoint_fnc • Not using: @worker.on_rtc_session() decorator pattern
t
You're already on the right path — your code shows the correct approach for automatic token-based dispatch using the official livekit-agents SDK: do not set
agent_name
in
WorkerOptions
, provide
roomConfig.agents
in the participant token, and implement an entrypoint that calls
ctx.connect()
. Checklist to verify now • WorkerOptions: confirm you do NOT pass
agent_name
. • Token: contains
roomConfig.agents
with the exact
agentName
you expect (your pasted token shows this). • Agent logs: when participant connects, you should see "Agent job received: room=..." and then "Connected to LiveKit room" after
await ctx.connect()
. • Cold-start: if on Build or suspended worker, allow ~10–20s for the agent to start. • Room uniqueness: continue using unique room names per session. Minimal code snippet adjusted to your imports (matches your pattern)
Copy code
from livekit.agents import AgentSession, JobContext, WorkerOptions, cli
from livekit.agents.worker import ServerType

def cli_entry() -> None:
    cli.run_app(
        WorkerOptions(
            entrypoint_fnc=entrypoint,
            _worker_type=ServerType.ROOM,
            # DO NOT set agent_name here for automatic token-based dispatch
        )
    )

async def entrypoint(ctx: JobContext) -> None:
    logger.info(f"Agent job received: room={ctx.job.room_name}, metadata={ctx.job.metadata}")
    await ctx.connect()  # join the room
    logger.info("Connected to LiveKit room")
    # ... rest of agent logic ...
If after this you still don't see the "Agent job received" log line when the participant connects, paste the agent logs for that timeframe and I’ll help interpret them. Would you like that?
m
LiveKit Debug Client
Copy code
[DebugClient] Requesting token from /api/connect-debug
[DebugClient] Token endpoint response: {
  "token": "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiRW5nbGlzaCBUZWFjaGVyIFN0dWRlbnQiLCJ2aWRlbyI6eyJyb29tIjoiZW5nbGlzaC10ZWFjaGVyLTE3NjQ3MjY4Mzc0NDQtZW5paGNqdiIsInJvb21Kb2luIjp0cnVlLCJjYW5QdWJsaXNoIjp0cnVlLCJjYW5TdWJzY3JpYmUiOnRydWUsImNhblB1Ymxpc2hEYXRhIjp0cnVlfSwicm9vbUNvbmZpZyI6eyJhZ2VudHMiOlt7ImFnZW50TmFtZSI6IkNBXzRUMmN2cWJMNkp3SCIsIm1ldGFkYXRhIjoie1wic2NlbmFyaW9cIjpcImRlYnVnXCIsXCJsZXZlbFwiOlwiZGVidWdcIixcInZvaWNlX3Byb3ZpZGVyXCI6XCJsaXZla2l0XCIsXCJ2b2ljZVwiOlwiZGVmYXVsdFwifSJ9XX0sImlzcyI6IkFQSUxGSzY0V3JWTmVXTCIsImV4cCI6MTc2NDcyNzQzNywibmJmIjowLCJzdWIiOiJ1c2VyLTE3NjQ3MjY4Mzc5NDgifQ.bCmgZbSMywp6M6AYV9cJ_dctcslWk61V_ejjXjDL0WQ",
  "url": "wss://englishlive-3qjapr2j.livekit.cloud",
  "room": "english-teacher-1764726837444-enihcjv",
  "metadata": {
    "scenario": "debug",
    "level": "debug",
    "voice_provider": "livekit",
    "voice": "default"
  },
  "dispatchId": null,
  "agentName": "CA_4T2cvqbL6JwH",
  "token_debug": {
    "name": "English Teacher Student",
    "video": {
      "room": "english-teacher-1764726837444-enihcjv",
      "roomJoin": true,
      "canPublish": true,
      "canSubscribe": true,
      "canPublishData": true
    },
    "roomConfig": {
      "agents": [
        {
          "agentName": "CA_4T2cvqbL6JwH",
          "metadata": "{\"scenario\":\"debug\",\"level\":\"debug\",\"voice_provider\":\"livekit\",\"voice\":\"default\"}"
        }
      ]
    },
    "iss": "APILFK64WrVNeWL",
    "exp": 1764727437,
    "nbf": 0,
    "sub": "user-1764726837948"
  }
}
[DebugClient] Decoded token payload: {
  "name": "English Teacher Student",
  "video": {
    "room": "english-teacher-1764726837444-enihcjv",
    "roomJoin": true,
    "canPublish": true,
    "canSubscribe": true,
    "canPublishData": true
  },
  "roomConfig": {
    "agents": [
      {
        "agentName": "CA_4T2cvqbL6JwH",
        "metadata": "{\"scenario\":\"debug\",\"level\":\"debug\",\"voice_provider\":\"livekit\",\"voice\":\"default\"}"
      }
    ]
  },
  "iss": "APILFK64WrVNeWL",
  "exp": 1764727437,
  "nbf": 0,
  "sub": "user-1764726837948"
}
[DebugClient] Connecting to wss://englishlive-3qjapr2j.livekit.cloud
[DebugClient] Connected. Local participant identity: user-1764726837948
[DebugClient] Published local audio track
[DebugClient] Staying connected for 30000ms to allow agent dispatch
[DebugClient] connectionQualityChanged excellent user-1764726837948
t
You're set up correctly for automatic token-based dispatch—the debug client shows a token with
roomConfig.agents
containing
agentName: "CA_4T2cvqbL6JwH"
, and your worker is launched without
agent_name
in WorkerOptions. To find why the agent still isn't joining, please do the following checks and paste any relevant agent logs: Checklist (run now) • Confirm the agent process is running and connected to LiveKit control plane at the time the participant connects. • Inspect agent logs around the participant connect time for any of these messages: ◦ "Agent job received: room=..." (dispatch received) ◦ "Connected to LiveKit room" (after
await ctx.connect()
) ◦ Any errors, tracebacks, or warnings. • If you see no "Agent job received" line, verify the agent can reach the control plane and that there are no network/firewall issues blocking outbound connections. • Confirm the worker is not accidentally setting
agent_name
from an environment variable or default (print
WorkerOptions()
at startup to verify it’s unset). • If on Build or with autoscaling, allow ~10–20s for cold-start and watch logs during that window. • Confirm room name in the token matches the room the debug client joined. If you paste the agent log lines for the exact timestamp when the debug client connected, I’ll analyze them and tell you the exact next step. Would you like me to look at those logs now?