- Author(s): @michelTho, @nemtecl
- Champion: @benbrandt
Elevator pitch
Add amessageId field to agent_message_chunk, user_message_chunk, agent_thought_chunk session updates to uniquely identify individual messages within a conversation. Only agents generate message IDs, and the IDs are opaque strings. This enables clients to distinguish between different messages beyond changes in update type and lays the groundwork for future capabilities like message editing and session deduplication.
Status quo
Currently, when an Agent sends message chunks viasession/update notifications, there is no explicit identifier for the message being streamed:
-
Ambiguous message boundaries - When the Agent sends multiple messages in sequence (e.g., alternating between agent and user messages, or multiple agent messages), Clients can only infer message boundaries by detecting a change in the
sessionUpdatetype. If an Agent sends consecutive messages of the same type, Clients cannot distinguish where one message ends and another begins. -
Non-standard workarounds - Currently, implementations rely on the
_metafield to work around this limitation. While functional, this approach is not standardized and each implementation may use different conventions. -
Limited future capabilities - Without stable message identifiers, it’s difficult to build features like:
- Message editing or updates
- Message-specific metadata or annotations
- Message threading or references
- Undo/redo functionality
What we propose to do about it
Add amessageId field to AgentMessageChunk, UserMessageChunk, and AgentThoughtChunk session updates. This field would:
- Provide stable message identification - Each message gets a unique identifier that remains constant across all chunks of that message.
-
Enable reliable message boundary detection - Clients can definitively determine when a new message starts by observing a change in
messageId. - Create an extension point for future features - Message IDs can be referenced in future protocol enhancements.
Proposed Structure
Thesession/prompt response does not include a message ID. In v1, there won’t be a message ID for user-submitted messages. In v2, the agent will replay the message and attach the appropriate message ID to the user message.
If the Agent sends user_message_chunk updates (e.g., during session/load), it uses the user message ID:
messageId:
messageId field would be:
- Optional in v1 on
agent_message_chunk,user_message_chunk, andagent_thought_chunkupdates. An omittedmessageIdand an explicitnullare equivalent and both mean the Agent did not provide a message ID for that chunk. - Required in v2 on
agent_message_chunk,user_message_chunk, andagent_thought_chunkupdates. The field MUST be present and MUST be a non-null string. - Agent-generated - the Agent is the only participant that creates protocol message IDs
- Unique per message within a session
- Stable across chunks - all chunks belonging to the same message share the same
messageId - Opaque - Implementations treat it as an identifier without parsing its structure
session/update, it SHOULD include messageId on that user message update. In v2, every streamed user, agent, and thought message chunk MUST include a messageId.
Shiny future
Once this feature exists:- Clear message boundaries - Clients can reliably render distinct message bubbles in the UI, even when multiple messages of the same type are sent consecutively.
- Better streaming UX - Clients know exactly which message element to append chunks to, enabling smoother visual updates.
-
Foundation for editing - With stable message identifiers, future protocol versions could add:
message/edit- Agent updates the content of a previously sent messagemessage/delete- Agent removes a message from the conversationmessage/replace- Agent replaces an entire message with new content
-
Message metadata - Future capabilities could reference messages by ID:
- Annotations or reactions to specific messages
- Citation or cross-reference between messages
- Tool calls that reference which message triggered them
- Enhanced debugging - Implementations can trace message flow more easily with explicit IDs in logs and debugging tools.
Implementation details and plan
Phase 1: Core Protocol Changes
-
Update schema (
schema/schema.json):- Add optional
messageIdfield (type:string) to v1ContentChunk(used byAgentMessageChunk,UserMessageChunk,AgentThoughtChunk) - Add required
messageIdfield (type:string) to v2ContentChunk
- Add optional
-
Update Rust SDK (
rust/client.rsandrust/agent.rs):- Add a dedicated
MessageIdnewtype - Add
message_id: Option<MessageId>field to the v1ContentChunkstruct - Add
message_id: MessageIdfield to the v2ContentChunkstruct - Update serialization to include
messageIdin JSON output when present for v1 and always for v2
- Add a dedicated
-
Update TypeScript SDK (if applicable):
- Add
messageIdfield to corresponding session update types
- Add
-
Update documentation (
docs/protocol/prompt-turn.mdx):- Document the
messageIdfield and its semantics - Add examples showing message boundaries
- Explain that
messageIdchanges indicate new messages
- Document the
Phase 2: Reference Implementation
-
Update example agents:
- Modify example agents to generate and include
messageIdin chunks - Demonstrate consistent IDs across chunks of the same message
- Modify example agents to generate and include
-
Update example clients:
- Update clients to consume
messageIdfield - Use IDs to properly group chunks into messages
- Demonstrate clear message boundary rendering
- Update clients to consume
Backward Compatibility
ThemessageId field is optional in v1 to ensure this is a non-breaking change. Agents SHOULD include the messageId field on message chunks they can identify, but it is not required for v1 compatibility. Features that rely on messageId (such as future message editing capabilities) will implicitly require the field to be present - Agents that don’t provide it simply won’t support those features.
The field is required in v2, where breaking protocol changes are allowed. v2 agents MUST include messageId on every streamed message chunk, and v2 clients can reject chunks where the field is omitted or null.
Frequently asked questions
What alternative approaches did you consider, and why did you settle on this one?
-
Continue using
_metafield - This is the current workaround but:- Not standardized across implementations
- Doesn’t signal semantic importance
- Easy to overlook or implement inconsistently
-
Detect message boundaries heuristically - Clients could infer boundaries from timing, content types, or session state:
- Unreliable and fragile
- Doesn’t work for all scenarios (e.g., consecutive same-type messages)
- Creates inconsistent behavior across implementations
-
Use explicit “message start/end” markers - Wrap messages with begin/end notifications:
- More complex protocol interaction
- Requires additional notifications
- More state to track on both sides
-
Client-generated prompt IDs - Let Clients generate IDs for
session/promptrequests:- Creates two sources of truth for protocol IDs
- Requires agreement on uniqueness across clients and agents
- Conflicts with the Agent’s role as owner of the session history
messageId is:
- Simple - Just one new field with clear semantics
- Flexible - Enables future capabilities without further protocol changes
- Practical - IDs come from the same side that owns and emits session history
- Format-agnostic - Agents can use identifiers that fit their own storage model
Who generates message IDs?
Only the Agent generates protocol message IDs.- For user messages: The Client sends a prompt without a message ID. If the Agent emits that accepted or replayed user message as a
session/update, the Agent generates the message ID and includes it in that notification. - For agent messages and thoughts: The Agent generates the ID when creating the message or thought and includes it in session update chunks.
sessionId, terminalId, toolCallId) which are agent-generated, and provides practical benefits:
- Single source of truth - The Agent owns session persistence and message ordering
- No format coordination - The protocol does not need to standardize UUIDs or another shared ID format
- Adapter-friendly - Adapters for agents that don’t support message IDs can simply omit them
Should this field be required or optional?
The field is optional for v1 to ensure backward compatibility. Agents SHOULD includemessageId, but it is not required. In v1, omitting messageId and sending null are equivalent and both mean no message ID was provided.
The field is required for v2. The key MUST be present and its value MUST be a non-null string.
What format should message IDs use?
Message IDs are opaque strings generated by the Agent. Clients MUST compare message IDs as opaque strings and MUST NOT parse or infer meaning from their structure. Because IDs only come from the Agent, collision avoidance is the Agent’s responsibility within the session.What about message IDs across session loads?
When a session is loaded viasession/load, the Agent may:
- Preserve original message IDs if replaying the conversation history
- Generate new message IDs if only exposing current state
Does this apply to other session updates like tool calls or plan updates?
This RFD addressesagent_message_chunk, user_message_chunk, and agent_thought_chunk updates.
Other session update types (like tool_call, plan) already have their own identification mechanisms:
- Tool calls use
toolCallId - Plan entries can be tracked by their position in the
entriesarray
messageId to other update types if use cases emerge.
Revision history
- 2026-06-03: Moved the RFD out of the v2 Draft group while keeping v2-specific behavior; added a dedicated
MessageIdtype, and made v2 require message IDs on streamed message chunks while v1 keeps optional message IDs for compatibility - 2026-06-02: Updated the proposal so message IDs are Agent-generated only, removed client-provided prompt IDs and prompt response acknowledgments, and removed the UUID requirement in favor of opaque strings
- 2026-02-17: Added “Message ID Acknowledgment” section to clarify that presence/absence of
userMessageIdin response indicates whether the Agent recorded the ID; clarified that UUID format is MUST (not SHOULD) since both sides generate IDs; renamed response field touserMessageIdfor clarity (request keepsmessageId) - 2026-01-29: Updated to allow both clients and agents to generate message IDs using UUID format
- 2025-11-09: Initial draft