how can I edit my agent messages that are interrup...
# ask-ai
n
how can I edit my agent messages that are interrupted to append an ellipses or other marker?
t
Thanks for reaching out, Martin. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
🙌 1
I'm glad you're exploring how to handle interrupted agent messages in LiveKit! To add an ellipsis or any other marker to these messages, you can use some custom application logic. LiveKit thoughtfully sets the
interrupted: true
flag on the
ChatMessage
object and truncates the message to show exactly what was said before the interruption. Here’s a friendly step-by-step to help you customize this: 1. Keep an eye on conversation events or use helpful hooks like
on_user_turn_completed
. 2. Check if the message carries the
interrupted: true
flag. 3. If it does, simply add your preferred marker (like "...") to the message content. 4. Make sure the updated message is nicely inserted back into the chat context. By following this approach, you can beautifully tailor how interrupted messages look while keeping the content accurate. If you have any questions along the way, I’m here to help! Sources: livekit-agents/livekit/agents/voice/agent_activity.py | Pipeline nodes and hooks | LiveKit Docs | agents/src/voice/agent_activity.ts
n
is on_user_turn_completed for both the agent and the human?
t
Just to clarify, the
on_user_turn_completed
callback is designed specifically for the human (user) side and doesn’t apply to the agent. It gets triggered right when the user's turn wraps up, just before the agent starts crafting its response. If you're looking to keep an eye on when the agent finishes speaking or generating a reply, you might want to explore other options like state change events or setting up some custom instrumentation within different lifecycle methods. I hope this helps you move forward smoothly! Sources: Pipeline nodes and hooks | LiveKit Docs | External data and RAG | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.py | Logs, metrics, and telemetry | LiveKit Docs
n
Got it. So what is the turn_ctx param?
t
Thanks for your question! The
turn_ctx
parameter in
on_user_turn_completed
is actually a mutable copy of the full
ChatContext
up to, but not including, your latest message. This means you can tweak the chat history or context before the agent crafts its response, which is pretty handy. Once the callback finishes, your latest message gets added to this context, and then the agent generates its reply based on the updated information. Just a heads-up: any changes you make to
turn_ctx
only affect the current response and won’t stick around unless you decide to manage that explicitly. I hope this helps clarify things! Sources: Pipeline nodes and hooks | LiveKit Docs | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | agents/src/voice/agent_activity.ts | External data and RAG | LiveKit Docs
n
So what's the best way to mark interruptions/ editing it in the chat context? since it seems that the message in
on_user_turn_completed
it'd be the user's message, not the agent's (and so would never be interrupted)
t
In LiveKit, when an agent's message gets interrupted, it’s automatically marked with
interrupted: true
and shortened to include only the part spoken before the interruption. This is managed by the framework to keep the conversation context clear and accurate. If you'd like to tailor this behavior to better fit your needs, here are some options you can explore: 1. You can control interruption permissions for each message using options like
allow_interruptions
. 2. It’s possible to modify message content during processing callbacks, such as
onUserTurnCompleted
, though this mainly applies to user messages rather than agent messages. 3. Session-level configuration parameters are available to adjust how interruptions behave overall. 4. You can also trigger interruptions programmatically using the
interrupt()
method. While directly editing interrupted agent messages once they’re part of the chat context isn’t supported, you do have some flexibility to influence interruption handling and customize the chat context during processing. If you’d like, I’m here to help you implement any specific customization you have in mind—just let me know! Sources: agents/src/voice/agent_activity.ts | livekit-agents/livekit/agents/voice/speech_handle.py | Turn detection and interruptions | LiveKit Docs | Agent Session & Activity Management | livekit/livekit_composite | DeepWiki