MessageDelta accumulates partial outputs (text chunks, tool-call fragments, IDs, signatures, etc.) until they can be materialized as a full [Message].
It implements [Delta] to support accumulation.
Accumulation Rules
role: merging two distinct roles fails.
thinking: concatenated in arrival order.
contents/tool_calls: last element is accumulated with the incoming delta when both are compatible (e.g., Text+Text, Function+Function with matching ID policy), otherwise appended as a new fragment.
id/signature: last-writer-wins.
Finalization
finish() converts the accumulated deltas into a fully-formed [Message].
Fails if required fields (e.g., role) are missing or inner deltas cannot be finalized.
A streaming, incremental update to a [
Message].MessageDeltaaccumulates partial outputs (text chunks, tool-call fragments, IDs, signatures, etc.) until they can be materialized as a full [Message]. It implements [Delta] to support accumulation.Accumulation Rules
role: merging two distinct roles fails.thinking: concatenated in arrival order.contents/tool_calls: last element is accumulated with the incoming delta when both are compatible (e.g., Text+Text, Function+Function with matching ID policy), otherwise appended as a new fragment.id/signature: last-writer-wins.Finalization
finish()converts the accumulated deltas into a fully-formed [Message]. Fails if required fields (e.g.,role) are missing or inner deltas cannot be finalized.Examples