#[non_exhaustive]pub enum MultiTurnStreamItem {
StreamAssistantItem(Item<StreamEvent>),
ToolCall {
tool_call: ToolCall,
},
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
ToolExecutionCommitted
Confirmation that Rig executed and committed a tool call. This is not
a real-time start notification: it is surfaced together with its
ToolResult only after the whole batch settles successfully. Use tool
hooks for live host-side start/result observation.
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.
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.
Implementations§
Source§impl MultiTurnStreamItem
impl MultiTurnStreamItem
Sourcepub fn final_response(
content: Vec<AssistantContent>,
aggregated_usage: Usage,
) -> Self
pub fn final_response( content: Vec<AssistantContent>, aggregated_usage: Usage, ) -> Self
Build a final response from structured content and aggregate usage. Concatenates text for output; completion details and history remain empty.