I'm delivering a message to the receiver using the...
# ask-ai
c
I'm delivering a message to the receiver using the self.session.say method. There is an other parallel operation that runs and based on the operation's output, I want to stop the agent's "say" at that point and start reading a different text. is this possible? If yes, how can I do it?
t
Thanks for reaching out, Bharath. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to help you with this! Yes, the
self.session.say
method can indeed be interrupted programmatically if you want to start reading a different text. You can do this by using the
interrupt()
method on the session or on the handle returned by
say()
. Let me show you how: Python Example:
Copy code
# Interrupt the current speech
self.session.interrupt()
# Start reading different text
self.session.say("I'm sorry, that will take too long to say.")
Node.js Example:
Copy code
const handle = session.say('Hello world');
handle.interrupt();
// or from the session
session.interrupt();
Also, you have control over whether a
say()
operation can be interrupted by setting the
allow_interruptions
parameter. Here's an example:
Copy code
# Python
await session.say(
    "Hello. How can I help you today?",
    allow_interruptions=False,
)

// Node.js
await session.say(
    'Hello. How can I help you today?',
    {
        allowInterruptions: false,
    }
);
Just so you know, even if
allow_interruptions
is set to
False
, you can still explicitly interrupt the agent using the
interrupt()
method. If you have any more questions or need further clarification, feel free to ask—I’m here to help! Sources: Turn detection and interruptions | LiveKit Docs | basics/say_in_voice.py | Agent speech and audio | LiveKit docs
b
2025-11-18 174620,648 - INFO voice-assistant - error while interruped the intro e - This generation handle does not allow interruptions {"pid": 1672766, "job_id": "AJ_V5pAVBsqnoGV"} getting this
t
I'm here to help you understand the error "This generation handle does not allow interruptions." This usually happens when the
allow_interruptions
flag is set to
False
for the speech generation handle. No worries though, you have a couple of straightforward options to fix this: 1. Make Sure Interruptions Are Allowed:
Copy code
# When scheduling speech, set allow_interruptions to True
handle = session.generate_reply("Your message", allow_interruptions=True)
2. Use the
force
Parameter:
If you want to override the
allow_interruptions
setting, you can use the
force
parameter with the
interrupt()
method like this:
Copy code
# Python
self.session.interrupt(force=True)

# Or for a specific handle
handle.interrupt(force=True)
Copy code
// Node.js
session.interrupt(true);

// Or for a specific handle
handle.interrupt(true);
By using
force=True
, you’re making sure the interruption happens even if
allow_interruptions
is set to
False
. If you have any more questions or need further assistance, feel free to ask—I’m here to support you! Sources: plugins/google/src/beta/realtime/realtime_api.ts | Turn detection and interruptions | LiveKit Docs | livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/... | pipeline-llm/interrupt_user.py
b
at any moment how do i check if the agent is in speaking state first before calling session.interrupt
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!