is there a way to indicate in the chat context tha...
# ask-ai
w
is there a way to indicate in the chat context that the agent got interrupted while saying a certain word? So that the LLM on the next call knows what it did not say to the caller?
t
Thanks for reaching out, Drew. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you asked! LiveKit thoughtfully provides a way to indicate when an agent is interrupted mid-utterance in the chat context. This is done by setting the
interrupted
flag to
true
on the relevant
ChatMessage
object. Doing so helps the LLM on the next call understand that the agent didn’t get to finish their message. When an interruption happens, the system captures the part of the text that was spoken before it was cut off and stores it in the chat context with the
interrupted
flag. This approach works consistently across both Python and Node.js implementations of the LiveKit Agents framework, so you can rely on it no matter which you’re using. Here’s a quick example in Python:
Copy code
msg = llm.ChatMessage(
    role="assistant",
    content=[forwarded_text],
    id=msg_gen.message_id,
    interrupted=True
)
self._agent._chat_ctx.items.append(msg)
And in Node.js, it looks like this:
Copy code
const message = ChatMessage.create({
    role: 'assistant',
    content: forwardedText,
    id: msgId,
    interrupted: true
});
this.agent._chatCtx.insert(message);
This way, the system keeps everything clear and continuous for downstream LLMs by preserving exactly what the agent said before the interruption. If you have any more questions or want to dive deeper, I’m here to help! Sources: agents/src/llm/__snapshots__/chat_context.test.ts.snap | examples/voice_agents/session_close_callback.py | Working with the MultimodalAgent class | LiveKit Docs | VoicePipelineAgent | LiveKit Docs | Turn detection and interruptions | LiveKit Docs
w
what is forward_text here
t
Thanks for reaching out! Could you please help me understand a bit more about what you mean by "forward_text"? Are you talking about the content of the message that got interrupted, or is there something else specific related to LiveKit's ChatMessage handling that you'd like to clarify? I'm here to help!
w
yes, what is forward_text in this example: msg = llm.ChatMessage( role="assistant", content=[forwarded_text], id=msg_gen.message_id, interrupted=True ) self._agent._chat_ctx.items.append(msg)
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!