The documentation says > To explicitly interru...
# ask-ai
q
The documentation says
To explicitly interrupt the agent, call the
interrupt()
method on the handle or session at any time. This can be performed even when
allow_interruptions
is set to
False
.
However, after running
interrupt()
with
allow_interruptions=False
, I got the following error
This generation handle does not allow interruptions
How to disable interruptions from the user while allowing programmatic interruptions?
t
Thanks for reaching out, Miguel. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to guide you through how to disable user interruptions while still allowing programmatic interruptions. Here's how you can set it up: • Disable User Interruptions Globally: When you initialize the
Agent
class, just set
allow_interruptions=False
. This way, user interruptions won’t disrupt the process, but you’ll still be able to interrupt programmatically using
session.interrupt()
. • Disable Interruptions for Specific Speech: If you want to prevent interruptions for particular speech segments, use
allow_interruptions=False
in methods like
say()
or
generate_reply()
. For example:
speech_handle = session.say("This will not be interrupted by the user.", allow_interruptions=False)
• Allow Programmatic Interruptions: You can still call
interrupt()
on the session or speech handle to interrupt programmatically, even when
allow_interruptions
is set to
False
. For example:
await session.interrupt()
By setting things up this way, you can comfortably disable user interruptions while keeping full control through your programmatic logic. If you have any questions or need further help, feel free to ask! Sources: agents/src/voice/speech_handle.ts | Tool definition and use | LiveKit Docs | Turn detection and interruptions | LiveKit Docs | pipeline-llm/interrupt_user.py | livekit-agents/livekit/agents/voice/agent.py
q
Then why did I got this error?
This generation handle does not allow interruptions
t
It looks like you're encountering the error "This generation handle does not allow interruptions" because you're trying to interrupt a
SpeechHandle
that was created with
allow_interruptions=False
, and the
interrupt()
method is being called without the
force=True
parameter. I completely understand how this can be a bit confusing! Here are some friendly suggestions to help you work around this: • Use `force=True`: You can call
speech_handle.interrupt(force=True)
to forcibly interrupt the speech, which will bypass the
allow_interruptions
restriction. • Modify Interruptions Setting: Another option is to enable interruptions dynamically by setting
speech_handle.allow_interruptions = True
before calling
interrupt()
. This gives you more flexibility. • Session-Level Interruption: If you want to interrupt all speech regardless of individual handle settings, try using
session.interrupt(force=True)
. By trying these approaches, you should be able to smoothly interrupt speech even when user interruptions are disabled. If you have any questions or need a hand with this, feel free to ask—I'm here to help! Sources: livekit-agents/livekit/agents/voice/agent_activity.py | pipeline-llm/interrupt_user.py | Turn detection and interruptions | LiveKit Docs | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki | agents/src/voice/speech_handle.ts