My agent can be spoken to and it also receives sta...
# ask-ai
t
My agent can be spoken to and it also receives status updates (sent with room.localParticipant.sendText(someJson, {topic: ‘lk.chat’})). With the default setting, if the user starts speaking while the agent speaks, the agent stops talking abruptly. This is good. But it also stops abruptly when I use sendText. This is not good. Can I change this somehow such that sendText does not interrupt the agent?
t
Thanks for reaching out, Christian. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I completely understand how important it is to have smooth and uninterrupted agent speech. To help with that, you can prevent the agent's speech from being interrupted by
sendText
by setting the
allow_interruptions
parameter to
False
when you call
session.say()
. This way, the agent’s speech won’t stop abruptly when new text messages come in, making the experience much more pleasant. Here’s a simple example to guide you: Python:
Copy code
await session.say(
    "Hello. How can I help you today?",
    allow_interruptions=False,
)
Node.js:
Copy code
await session.say(
    'Hello. How can I help you today?',
    {
        allowInterruptions: false,
    }
);
And if you’d like even more control, such as setting a minimum duration or word count before interruptions can happen, you can easily configure
min_interruption_duration
and
min_interruption_words
right in the
AgentSession
constructor. Sources: Agent speech and audio | LiveKit Docs | Agent speech and audio | LiveKit Docs | Text and transcriptions | LiveKit Docs | Text and transcriptions | LiveKit Docs | Turn detection and interruptions | LiveKit Docs
t
I don’t know in advance when my user might start talking or when sendText is called, so this solution isn’t good. Tell me more about topics - when my user talks, does that also arrive at the agents under the lk.chat topic? If so, could we set up another topic for these textual updates and configure the interruption behavior different for each topic?
t
Thanks for reaching out! I’d love to help clarify how LiveKit handles different input types. LiveKit uses different topics like
lk.chat
for text messages and
lk.transcription
for speech transcriptions, which is pretty neat. However, when it comes to interruption behavior, it’s managed at the session level and applies to all input sources together. So, unfortunately, you can’t set separate interruption behaviors for user speech and
sendText
updates based on their topics. If you’re looking to have distinct interruption logic for these inputs, a good approach would be to handle that within your application. For instance, you might route
sendText
updates to a custom topic and then manage them differently in your app’s logic—this way, you can make sure they don’t trigger interruptions. I hope this helps! Feel free to ask if you want to dive deeper into this. Sources: livekit-agents/livekit/agents/voice/agent_activity.py | Text and transcriptions | LiveKit Docs | Docs::Agents | Turn detection and interruptions | LiveKit Docs