purple-barista-60143
11/14/2025, 8:04 AMtall-airline-16756
11/14/2025, 8:04 AMtall-airline-16756
11/14/2025, 8:04 AMspeech_handle utilities, which can help cancel long-running tasks when needed.
If you want to prevent interruptions for certain tool calls, you can do so by using run_ctx.disallow_interruptions() right at the start of the tool execution. Plus, there are session-level settings like allow_interruptions and min_interruption_duration that give you even more control over how interruptions behave.
If you’d like, I’m here to provide more details or examples—just let me know!
Sources: Tool definition and use | LiveKit docs | examples/voice_agents/README.mdpurple-barista-60143
11/14/2025, 8:07 AMtall-airline-16756
11/14/2025, 8:07 AMrun_ctx.disallow_interruptions() right at the start of your function. Here’s a little example to help you see how it works:
from livekit.agents import Agent, RunContext
from livekit.plugins import openai
class MyAgent(Agent):
@openai.function_tool
async def critical_operation(self, run_ctx: RunContext) -> str:
# Disable interruptions for this function call
run_ctx.disallow_interruptions()
# Simulate a long-running, non-interruptible task
await asyncio.sleep(10)
return "Operation completed successfully"
In this example, by calling run_ctx.disallow_interruptions() inside the critical_operation tool, we ensure the task runs all the way through without any interruptions. This is especially handy for important tasks that need to finish completely.
If you’d like me to walk you through more examples or if anything isn’t clear, just let me know—I’m here to help!
Sources: Tool definition and use | LiveKit docs | Turn detection and interruptions | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.pypurple-barista-60143
11/14/2025, 8:09 AMtall-airline-16756
11/14/2025, 8:11 AMrun_ctx.disallow_interruptions(), so the tool will run without being stopped by user speech.
• False Interruptions: If no real user speech is detected, the agent will simply continue its task after a short timeout (default: 2 seconds).
For example, if a tool is about to run but the user speaks, the system checks if that speech qualifies as an interruption. If it does, the tool execution is canceled. But if interruptions are turned off, the tool will carry on no matter what.
Please feel free to ask if you’d like me to explain anything further or provide some examples—I’m here to help!
Sources: Tool definition and use | LiveKit docs | agents/src/voice/agent_activity.ts | livekit-agents/livekit/agents/voice/agent_activity.py | Turn detection and interruptions | LiveKit Docs | Agent Session Management & Turn Detection | livekit/livekit_composite | Dee...purple-barista-60143
11/14/2025, 8:12 AMtall-airline-16756
11/14/2025, 8:13 AMllm_node. By default, the ongoing task gets canceled. This happens because the system uses the speech_handle utility to keep an eye out for any interruptions. If it detects one, it gently stops the llm_node execution and discards any partial results to keep everything clean.
If you'd prefer to keep things running without interruptions during llm_node execution, you have the option to set the agent to disallow interruptions. You can do this by adjusting the allow_interruptions parameter or by explicitly calling run_ctx.disallow_interruptions() in your tool logic.
Please feel free to reach out if you'd like me to walk you through it further or provide some examples—I'm here to help!
Sources: Tool definition and use | LiveKit docs | livekit-agents/livekit/agents/voice/agent.pypurple-barista-60143
11/14/2025, 8:14 AMtall-airline-16756
11/14/2025, 8:15 AMrun_ctx.disallow_interruptions() to the tool definition, it means that any user speech won’t interrupt the tool while it’s running. This is a great way to make sure your task finishes smoothly without any interruptions.
If you’d like, I’m here to help with more details or examples—just let me know!
Sources: livekit-agents/livekit/agents/voice/agent_activity.pypurple-barista-60143
11/14/2025, 8:16 AMtall-airline-16756
11/14/2025, 8:17 AMllm_node execution can be a bit tricky! When a user interrupts, the following log line (or any code after the llm_node call) doesn’t run by default because the interruption cancels the ongoing task, and that cancellation skips the rest of the code.
To make sure your log line still executes even if there’s an interruption, a great approach is to use a try/finally block. This way, you can handle any cleanup or logging smoothly:
try:
async for chunk in Agent.default.llm_node(self, chat_ctx, tools, model_settings):
yield chunk
except asyncio.CancelledError:
logger.info("LLM node was interrupted")
raise
finally:
logger.info(f"✅ [GENERATE_RESPONSE] User: {user_id} - Response generation completed")
With this setup, the log line inside the finally block will always run, even if the task gets interrupted.
If you’d like, I’m here to help clarify anything further—just let me know!
Sources: Tool definition and use | LiveKit docs | livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/...