#[non_exhaustive]pub enum MultiTurnStreamItem {
StreamAssistantItem(Item<StreamEvent>),
ToolCall {
tool_call: ToolCall,
},
ToolExecutionStarted {
tool_call: ToolCall,
},
ToolResultItem {
tool_result: ToolResult,
index: usize,
count: usize,
},
ToolExecutionCommitted {
tool_call: ToolCall,
},
ToolResult {
tool_result: ToolResult,
},
CompletionCall(CompletionCall),
ModelTurnRetried {
turn: usize,
},
FinalResponse(PromptResponse),
}Expand description
One item of a streamed run: a provider stream event, a committed tool
call, a lifecycle marker, or the run’s final response. An item reads back
from its serialized form on its own, without checking its order against
the items around it; StreamRecord::parse
checks a run’s provider stream items.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
StreamAssistantItem(Item<StreamEvent>)
A provider stream item containing model-emitted content: part
starts and ends, text and reasoning fragments, a tool call’s
argument fragments as they stream (a call to a tool the turn does not
allow is held for its resolution), and unmodeled passthrough
payloads. A call’s end carries the validated call; the same call id
is reported again as ToolCall once history holds it.
ToolCall
A tool call committed to the run’s history, in commit order.
The stream’s tool items are a projection of committed history
(project): every call history holds is
reported, and later answered by a ToolResult,
whether it ran, a hook skipped it, or invalid-call recovery or an
output reprompt answered it; a run resumed mid-batch reports the batch’s
calls again (projection_start).
It is not an execution-lifecycle event
(see ToolExecutionCommitted). A
structured-output Tool-mode output-tool call that finalizes the run is
committed as text, so it is reported in the
FinalResponse instead.
Fields
ToolExecutionStarted
A tool call starts: Rig dispatches it now, before its dispatch
hooks and its body run. The call goes on only once the stream’s
consumer has taken this item, so a slow consumer delays the call. A
RunEvents feed takes it into its buffer, so there the call may run
before the feed’s reader sees it.
One item per dispatched call, after the turn’s
ToolCall items and before the batch’s commits and
results: in call order when calls run one at a time, in start order
under tool_concurrency. A call a dispatch hook skips still starts.
A call answered by invalid-call recovery, or dropped because a
sibling ended the run, never starts. A start is not a commit: a
batch that fails surfaces its starts but no commits or results.
Fields
ToolResultItem
One item of a tool’s accepted output, reported as soon as the
call’s outcome hooks accept it, without waiting for the rest of the
batch. The call goes on only once the stream’s consumer has taken the
item, as for ToolExecutionStarted.
An output that is exactly one JSON array is reported one element at a
time, each as one JSON block (an empty array reports nothing); any
other output is one item holding all its blocks. Text is never
reparsed as JSON. Items come in completion order under
tool_concurrency, so items of different calls may interleave: group
them by tool_result.call. Every started call that answers reports its items,
a hook-skipped one included; a call answered by invalid-call recovery
reports none. An item is not a commit: items stay reported when a
sibling later fails the batch, a call already running when a sibling
fails still reports its items as it finishes, and the committed
ToolResult still follows a batch that settles.
Show these for progress; record only the ToolResult.
Fields
tool_result: ToolResultThis item’s content, with the call id, name and error flag of the result the batch commits for the call.
ToolExecutionCommitted
Confirmation that Rig executed and committed a tool call. It is
surfaced together with its ToolResult only after the whole batch
settles successfully; the live start is
ToolExecutionStarted.
This item is emitted only for a tool whose body actually ran (it passed
its ToolCall hook checks), never for a call dropped by a sibling’s
termination, skipped by a hook, or resolved by invalid-call recovery.
Correlate it with the model call and result through the call’s id.
Fields
tool_call: ToolCallThe tool call as executed: the model’s call with any
DispatchAction::Patch hook rewrite
applied (so a redaction rewrite is reflected here, not leaked). The
model’s original call is reported via
StreamAssistantItem.
ToolResult
A tool result committed to the run’s history, answering a reported
ToolCall. The tool
batch commits and surfaces atomically at every tool_concurrency
(including the sequential default): results are surfaced in call order
only after the whole batch settles successfully; a run that terminates
mid-batch surfaces no successful tool results. The live output is
ToolResultItem.
Fields
tool_result: ToolResultThe result; tool_result.call is the id of the call it answers.
CompletionCall(CompletionCall)
Details for one successfully completed completion request made by this agent stream.
This is emitted when a provider call finishes. Usage is the provider’s final usage for that completion request when available; it is not incremental per streamed token.
use rig_agent::agent::MultiTurnStreamItem;
fn input_tokens(item: &MultiTurnStreamItem) -> Option<u64> {
match item {
MultiTurnStreamItem::CompletionCall(call) => call.usage.input_tokens,
_ => None,
}
}ModelTurnRetried
The completed model turn was rejected by a hook for retry.
Text and reasoning deltas emitted for this turn were provisional. A
consumer should discard or visually reset output associated with turn.
A subsequent attempt is made only if the run’s total model-call budget
permits it.
FinalResponse(PromptResponse)
The final result from the stream: the unified PromptResponse shared
with the blocking surface.
Terminal for the run: no retry, further turn, or tool execution follows.
This item is the stream-side
counterpart of the on_run_settled hook’s success outcome. Error
termination surfaces as the stream’s Err item instead, which is
equally terminal.