I see 12 cuncurrent agents sessions on livekit das...
# ask-ai
q
I see 12 cuncurrent agents sessions on livekit dashboard. And one agent is online. Why so much ?
t
Thanks for reaching out, Heorhi. 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 the dashboard showing 12 concurrent agent sessions while you see only one agent online. This is expected behavior. “Concurrent agent sessions” counts active conversations (sessions) being handled at the same time, not the number of deployed agent processes. A single agent deployment can handle many sessions simultaneously, so if 12 users (or test connections/health checks/bots) are interacting with that agent at once, the dashboard will show 12 concurrent sessions even though only one agent process is online. If you want to confirm why those sessions exist, check: • your agent logs/metrics for active session counts, • any automated tests, bots, or health checks that might open connections, • client-side code for unintended reconnects or multiple connections per user. Would you like steps to inspect logs or a quick checklist to find unintended connections? Sources: Agent server | LiveKit docs | LiveKit Pricing | Deploying to production | LiveKit Docs
q
How to close session on call end ?
t
Responding about closing the agent session when a call ends. You can close sessions two ways depending on whether you want to end just the agent’s session or end the whole call for everyone: • To gracefully end only the agent session: call the agent shutdown method so the session disconnects and any in‑flight work finishes. ◦ Python:
session.shutdown(drain=True)
or
await session.aclose()
◦ Node.js:
ctx.shutdown('Session ended')
◦ Listen for the session
close
event to run cleanup. • To end the call for all participants (ensures no lingering sessions): delete the room via the server API which triggers session close events for everyone. ◦ Use the Room service client to call
deleteRoom(...)
(Node/Python examples in the docs). Which language or SDK are you using so I can provide a short code snippet you can drop into your hangup logic? Sources: Job lifecycle | LiveKit docs | Events and error handling | LiveKit docs
q
Got this kind of error: Error at entry (/vsa/apps/allocated-agent/src/outbound-agent.ts10817) at process.processTicksAndRejections (nodeinternal/process/task queues105:5) at async <anonymous> (/vsa/node_modules/@livekit/agents/dist/ipc/job_proc_lazy_main.js725) I catch error in catch block, but no message appear, so this is call stack at least
t
You're seeing an unhelpful stack because the thrown value has no readable message or it isn't being logged. I’ll help you capture the real error and ensure the session closes cleanly. What I’m responding to: your stack trace from
outbound-agent.ts
and that your catch block shows no message. Quick checklist to debug and fix (Node.js): 1. Log the raw error object • Update your catch to log the full error and its properties:
Copy code
catch (err) {
  console.error('Agent entry error - raw:', err);
  console.error('Error name:', err?.name, 'message:', err?.message, 'stack:', err?.stack);
  await ctx?.shutdown?.('Agent error');
}
1. Handle non-Error throws and undefined • Normalize thrown values so you always see text:
Copy code
function formatErr(e: unknown) {
  if (e instanceof Error) return e;
  return new Error(typeof e === 'string' ? e : JSON.stringify(e));
}
catch (e) {
  const err = formatErr(e);
  console.error(err);
  await ctx?.shutdown?.('Agent error');
}
1. Add global rejection handlers (temporary for debugging)
Copy code
process.on('unhandledRejection', (reason) => {
  console.error('unhandledRejection:', reason);
});
process.on('uncaughtException', (err) => {
  console.error('uncaughtException:', err);
});
1. Inspect line 108 in outbound-agent.ts • Look for any awaited call there (external API,
delete_room
,
createSIPParticipant
,
hangup_call
, etc.). Wrap it in try/catch and log inputs/outputs so you can reproduce the error. 1. Ensure you await shutdown/delete operations • If closing the call, either: ◦ Gracefully end the agent session:
await ctx.shutdown('reason')
or
await session.aclose()
(depending on your code) ◦ Or delete the room to end call for all: call your RoomServiceClient
deleteRoom(...)
and then
await ctx.shutdown(...)
• Always await these calls so the process doesn’t exit before cleanup. 1. If the error happens during cleanup (hangup) • Wrap hangup logic separately and swallow only expected errors while logging unexpected ones:
Copy code
try {
  await deleteRoom(...);
} catch (e) {
  console.error('deleteRoom failed:', e);
}
await ctx.shutdown('hangup');
If you’d like, paste the code around line 100–120 of
outbound-agent.ts
(the
entry
function) and I’ll point to the exact lines to change. Which LiveKit Agents SDK version and Node version are you running? Sources: Job lifecycle | LiveKit docs | Streamline Troubleshooting with Agent Observability