fix(voice): propagate ChatMessage.interrupted through proto serializer#5824
Merged
Conversation
The `_chat_item_to_proto` helper in `voice/remote_session.py` constructs the proto `ChatMessage` without copying `item.interrupted`, so the field is always false on the wire even when the model has it set. The JS framework's serializer at `agents-js/agents/src/voice/remote_session.ts` already passes it through; this aligns Python with that behaviour. Repro: send a turn that causes the agent to start speaking, then send another turn before the first finishes. The first message ends up in chat context with `interrupted=True` (model-side) but the proto `conversation_item_added` event emits `interrupted=false` to anything subscribing on the wire (e.g. external test drivers, replay tools). Fix: pass `interrupted=item.interrupted` into the `ChatMessage` proto constructor. Single field; no API change.
davidzhao
approved these changes
May 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_chat_item_to_protoinlivekit-agents/livekit/agents/voice/remote_session.pyomits theinterruptedfield when convertingllm.ChatMessageto its proto form. The model has the field (interrupted: bool = Falseinlivekit-agents/livekit/agents/llm/chat_context.py:320) and the proto schema has it (ChatMessage.interruptedat field 4 inlivekit_agent_session.proto), but the serializer drops it on the floor. Result: everyconversation_item_addedevent on the wire reportsinterrupted=false, even for messages whose model copy was committed withinterrupted=True.Repro
Drive the agent into a partial-speech-then-interrupt scenario — e.g. ask for a long story, then send a new
runInputafter ~2 s of speaking. Subscribe toAgentSessionMessage.eventover thelk.agent.sessionbyte-stream topic. The framework'sAgentActivitycommits the partial assistant message withinterrupted=True(model-side), but the emitted proto event hasitem.message.interrupted=falseon the wire.After this PR:
Fix
pb_msg = agent_pb.ChatMessage( id=item.id, role=pb_role, content=content, + interrupted=item.interrupted, metrics=_metrics_to_proto(item.metrics), )Single field added to the
ChatMessageconstructor. No API change, no behaviour change for the model — only the wire serialization is affected.Test plan
examples/voice_agents/basic_agent.pywith an external proto consumer. Before the fix, all messages hadinterrupted=false. After the fix, the partial assistant message that was interrupted mid-speech showsinterrupted=true, matching the JS framework's behaviour.make check(ruff lint + mypy) passes.