icy-nightfall-64225
07/21/2025, 4:50 PMraise RuntimeError("This generation handle does not allow interruptions") on the following code
self.session.commit_user_turn(
transcript_timeout=20
)
if self.session.current_speech:
self.session._activity._current_speech.allow_interruptions = True
self.session.interrupt()
await self.session.generate_reply(
user_input=NOT_GIVEN, # no user input in cascaded model to work correctly
instructions="Generate an interruption script because the user is speaking too long. ",
tool_choice=tool_choice,
allow_interruptions=False, # has to be False for cascaded API to work correctly
)
Note, I was trying to force the model to generate some speech, even while the user is still speaking (maybe the user is speaking for too long, so we want to stop them.tall-airline-16756
07/21/2025, 4:50 PMtall-airline-16756
07/21/2025, 4:51 PMraise RuntimeError("This generation handle does not allow interruptions") occurs when you attempt to interrupt a speech generation that was created with allow_interruptions=False. In your code, this happens because you set allow_interruptions=False when calling generate_reply, but then try to interrupt the current speech handle, which is not permitted.
Key points to consider:
• Speech handles created with allow_interruptions=False cannot be interrupted. Attempting to do so will always raise this error.
• With cascaded models (such as RealtimeModel with server-side turn detection), allow_interruptions=False is not supported. The system will log a warning and override this setting, but if you force it, you may encounter unexpected behavior.
To generate speech while the user is still speaking or to force an interruption:
1. Set allow_interruptions=True (the default) when generating speech if you want to allow interruptions.
2. If you want to stop the user and generate a response, you can manually call interrupt() on the session, but only if the current speech handle allows interruptions.
3. If you need to prevent interruptions, ensure you do not attempt to interrupt speech handles created with allow_interruptions=False.
For cascaded models, rely on the server-side turn detection and avoid setting allow_interruptions=False. If you need to discard user audio while non-interruptible speech is playing, consider using the discard_audio_if_uninterruptible option in your session configuration.
Adjust your code to ensure that interruptions are only attempted on speech handles that allow them, and avoid forcing allow_interruptions=False with cascaded models.
Sources: livekit-agents/livekit/agents/voice/events.py | basics/interrupts_user.pyicy-nightfall-64225
07/21/2025, 4:56 PMcommit_user_turn immediately generates a reply, and I actually want to interrupt that replytall-airline-16756
07/21/2025, 4:57 PMon_user_turn_completed and raise StopResponse
Think of this like a gentle "pause" button. You can stop the automatic reply by implementing this method and raising StopResponse. Here's how it looks:
async def on_user_turn_completed(self, turn_ctx, new_message):
# Add your condition here
raise StopResponse()
This approach is like having a smooth, clean way to hit the brakes on reply generation.
2. Manual interruption with session.interrupt()
Sometimes you just need to say "hold up!" - and that's exactly what await session.interrupt() does. It'll cancel any current or pending replies in a snap.
3. Manual turn control
Want more hands-on control? You can manually manage turn detection, only calling commit_user_turn when you want a reply. Or use clear_user_turn() to skip generating a reply altogether.
Pro tip: I'd recommend using the on_user_turn_completed hook with StopResponse. It gives you the most flexibility and feels super smooth to implement!
Sources: Turn detection and interruptions | LiveKit Docs | Pipeline nodes and hooks | LiveKit Docs | livekit-agents/livekit/agents/llm/realtime.py