Skip to main content

MultiTurnStreamItem

Enum MultiTurnStreamItem 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

§tool_call: ToolCall

The call as the model emitted it. Its id is equal on its execution commit and its result.

§

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

§tool_call: ToolCall

The call as the model emitted it, before any hook rewrite. Its id is the one its ToolCall, execution commit and result carry.

§

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: ToolResult

This item’s content, with the call id, name and error flag of the result the batch commits for the call.

§index: usize

The item’s position in the output, from zero.

§count: usize

How many items the output has.

§

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: ToolCall

The 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: ToolResult

The 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.

Fields

§turn: usize

One-based model-call index of the rejected turn.

§

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.

Trait Implementations§

Source§

impl Clone for MultiTurnStreamItem

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MultiTurnStreamItem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for MultiTurnStreamItem

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for MultiTurnStreamItem

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoToolOutput for T
where T: Serialize + 'static,

Source§

fn into_tool_output(self) -> Result<ToolOutput, ToolExecutionError>

Convert this value without routing structured data through a string.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more