late-businessperson-58140
12/10/2025, 9:28 AMtall-airline-16756
12/10/2025, 9:28 AMtall-airline-16756
12/10/2025, 9:29 AMswitch_language calls session.interrupt() because the AgentSession isn't running. I can help diagnose and fix this.
To narrow it down, please tell me:
1. Do you call await session.start(...) before switch_language?
2. Has the session been closed earlier (e.g., session.aclose()), or did any prior errors occur in the logs before this traceback?
3. Is switch_language triggered while the session is idle, or during active audio/agent activity (what user action triggers it)?
4. Which LiveKit Agents SDK version are you running and which runtime (Python 3.11 shown) or deployment environment?
While you gather that, try these quick checks:
• Confirm session.start() completed successfully before calling interrupt().
• Wrap session.interrupt() in a try/except to handle the RuntimeError and log session state.
• If you need to change language mid-run, stop and recreate the AgentSession with new language settings instead of calling interrupt() when the session may be stopped.
Tell me the answers to the questions above and any additional log lines around this error and I’ll provide specific code examples or next steps.
Sources: Events and error handling | LiveKit docs | Agent speech and audio | LiveKit docs | Building a Moviefone-style Theater Assistant | LiveKit docs | Models | LiveKit Docsripe-arm-36009
12/11/2025, 6:20 AMtall-airline-16756
12/11/2025, 6:21 AMAgentSession and where switch_language is called.
2. Whether switch_language can be invoked by multiple concurrent triggers (user actions, timeouts, or other tasks).
3. Any earlier log lines showing session start, disconnects, or aclose() calls before the error.
4. Which real-time model and LiveKit Agents SDK version you’re using.
5. Whether this happens more when network conditions are poor or when many users are connected.
If you prefer a quick mitigation while we debug, add a guarded call around `interrupt()`:
try:
session.interrupt()
except RuntimeError:
# session not running — recreate or restart session here
...
Send the code/log snippets and answers above and I’ll propose a precise fix or a session-restart pattern that fits your flow.ripe-arm-36009
12/11/2025, 6:23 AMtall-airline-16756
12/11/2025, 6:24 AMsession.interrupt() or other session methods running when the session has already closed or hasn't finished starting.
What to change (short, actionable):
1. Guard session calls with session.is_running
• Before any session.interrupt(), session.say(), or similar, check:
if session.is_running:
session.interrupt()
1. Register event handlers safely
• Register or at least guard event handlers so they don't call session methods after close. Either:
◦ Register handlers after await session.start(...), or
◦ In handlers, check session.is_running before calling session methods.
1. Wrap critical calls in try/except
• Catch RuntimeError to avoid uncaught tasks:
try:
session.interrupt()
except RuntimeError:
logger.warning("Session not running; skipping interrupt")
1. Do not reuse a closed AgentSession
• If you need to change language or fully reinitialize, create a new AgentSession instance and await session.start(...) again. Do not call start/restart on a session that has closed.
1. Add a close listener and set a local flag
• On "close" event set a flag (or update your current_state.json) so other tasks know the session is no longer valid and won’t attempt actions.
Quick places to apply these in your code:
• In your @session.on("error") handler: check session.is_running before session.say() / session.interrupt().
• Wherever switch_language runs: check session.is_running or catch RuntimeError and recreate the session with new language settings.
• Surround await session.start(...) with try/except and log startup success before any other session usage.
If you want, paste your switch_language function or the exact spot where you call session.interrupt() and I’ll give a minimal patched snippet that fits your flow.
Sources: Agent session | LiveKit docs | Voice AI quickstart | LiveKit docs | Agents (Node.js) | livekit/livekit_composite | DeepWiki | Events and error handling | LiveKit docs | Job lifecycle | LiveKit docs