Skip to main content

StepEvent

Enum StepEvent 

Source
#[non_exhaustive]
pub enum StepEvent<'a, M: CompletionModel> { CompletionCall { prompt: &'a Message, history: &'a [Message], turn: usize, }, CompletionResponse { prompt: &'a Message, response: &'a CompletionResponse<M::Response>, }, ModelTurnFinished { turn: usize, content: &'a OneOrMany<AssistantContent>, usage: Usage, }, InvalidToolCall(&'a InvalidToolCallContext), ToolCall { tool_name: &'a str, tool_call_id: Option<&'a str>, internal_call_id: &'a str, args: &'a str, }, ToolResult { tool_name: &'a str, tool_call_id: Option<&'a str>, internal_call_id: &'a str, args: &'a str, result: &'a str, outcome: &'a ToolOutcome, extensions: &'a ToolResultExtensions, }, TextDelta { delta: &'a str, aggregated: &'a str, }, ToolCallDelta { tool_call_id: &'a str, internal_call_id: &'a str, tool_name: Option<&'a str>, delta: &'a str, }, StreamResponseFinish { prompt: &'a Message, response: &'a M::StreamingResponse, }, }
Expand description

An observable point in an agent run, passed to AgentHook::on_event.

StepEvent borrows everything it carries (it is Copy), so a hook may inspect the event without taking ownership and a HookStack can forward the same event to each hook in turn.

The streaming-only variants (TextDelta, ToolCallDelta and StreamResponseFinish) are emitted only by AgentRunner::stream.

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

CompletionCall

Before a completion request is sent to the model. Honors Flow::Continue, Flow::PatchRequest (patch this turn’s request) and Flow::Terminate. Across a HookStack, every hook’s PatchRequest is merged (see the module docs).

Fields

§prompt: &'a Message

The prompt message for this turn.

§history: &'a [Message]

The chat history preceding prompt.

§turn: usize

One-based index of this model call within the run.

§

CompletionResponse

After a non-streaming completion response is received. Suppressed for turns recovered by invalid tool-call repair, skip, or retry. Honors Flow::Continue and Flow::Terminate. The medium-specific (non-streaming) counterpart of ModelTurnFinished, carrying the raw provider response.

Fields

§prompt: &'a Message

The prompt message for this turn.

§response: &'a CompletionResponse<M::Response>

The model’s completion response.

§

ModelTurnFinished

After a model turn is accepted into the run, on both surfaces, regardless of whether the turn produced text, tool calls, reasoning, or mixed content. This is the normalized, medium-neutral counterpart of CompletionResponse (non-streaming) and StreamResponseFinish (streaming) — use it for telemetry that must fire once per turn everywhere, including a streamed tool-only turn that fires no StreamResponseFinish. Suppressed for turns recovered by invalid tool-call repair, skip, or retry, and fired after the medium-specific raw event when one fires. Observe-only: honors Flow::Continue and Flow::Terminate.

Fields

§turn: usize

One-based index of this model call within the run.

§content: &'a OneOrMany<AssistantContent>

The model’s assistant content for this turn — the canonical committed model output. For an ordinary turn this is exactly what is recorded into the run. On a structured-output Tool-mode turn that finalizes by calling the output tool, this is the model-emitted content including that output-tool call; the run then persists the turn as assistant text (the structured output) with the tool call dropped, so the persisted message differs from this content.

§usage: Usage

Token usage for this turn (zeroed if the provider reported none).

§

InvalidToolCall(&'a InvalidToolCallContext)

The model emitted a tool call that is unknown or disallowed for this turn. Honors Flow::Fail (the default), Flow::Retry, Flow::Repair, Flow::Skip and Flow::Terminate; Flow::Continue is treated as Flow::Fail.

§

ToolCall

Before a tool is executed. Honors Flow::Continue, Flow::RewriteArgs (execute the tool with rewritten arguments), Flow::Skip (return reason as the tool result without executing) and Flow::Terminate. Across a HookStack, RewriteArgs is chained: args reflects prior hooks’ rewrites (see the module docs).

Fields

§tool_name: &'a str

Name of the tool about to be called.

§tool_call_id: Option<&'a str>

Provider-supplied tool call ID, when available.

§internal_call_id: &'a str

Internal Rig call ID correlating this call’s events.

§args: &'a str

JSON arguments for the call.

§

ToolResult

After a tool has produced a result (or a ToolCall hook skipped it). Honors Flow::Continue, Flow::RewriteResult (substitute the result the model sees) and Flow::Terminate.

result is the model-visible output, and outcome / extensions are the structured execution result — the machine-visible half a hook inspects without parsing result. outcome distinguishes success from a classified ToolFailure (timeout, not-found, …), a Skipped call, or a Denied one; extensions carries provider/application metadata the tool attached that is never sent to the model.

For the first hook, result is the tool’s actual output and outcome its raw structured outcome; across a HookStack, RewriteResult is chained so a later hook sees the prior hook’s replacement in result. A rewrite changes only result (the model-visible text) — outcome and extensions are the tool’s raw structured result throughout, so a redaction hook cannot mask the true outcome from a later policy hook (see the module docs).

Fields

§tool_name: &'a str

Name of the tool that was called.

§tool_call_id: Option<&'a str>

Provider-supplied tool call ID, when available.

§internal_call_id: &'a str

Internal Rig call ID correlating this call’s events.

§args: &'a str

JSON arguments for the call.

§result: &'a str

The model-visible tool result. Reflects any earlier hook’s RewriteResult; the first hook sees the tool’s actual output.

§outcome: &'a ToolOutcome

The structured outcome of the execution (success / classified error / skipped / denied). The raw outcome, unaffected by RewriteResult.

§extensions: &'a ToolResultExtensions

Metadata the tool attached to its result, never sent to the model.

§

TextDelta

Streaming only: a text delta was received. aggregated is the full text accumulated for the turn so far. Honors Flow::Continue and Flow::Terminate.

Fields

§delta: &'a str

The newly received text fragment.

§aggregated: &'a str

All text accumulated for the turn so far.

§

ToolCallDelta

Streaming only: a tool-call delta was received. tool_name is Some on the first delta for a tool call and None on subsequent deltas. Honors Flow::Continue and Flow::Terminate.

Fields

§tool_call_id: &'a str

Provider-supplied tool call ID.

§internal_call_id: &'a str

Internal Rig call ID correlating this call’s events.

§tool_name: Option<&'a str>

Tool name, present on the first delta only.

§delta: &'a str

The newly received argument fragment.

§

StreamResponseFinish

Streaming only: the provider finished streaming a completion response. This is the streaming counterpart of CompletionResponse and, like it, is suppressed for turns recovered by invalid tool-call repair, skip, or retry. Note one medium-specific difference from CompletionResponse: it fires only on turns that streamed assistant text — a turn that emits only a tool call (or only reasoning) does not fire it. For a per-turn event that fires on every turn on both surfaces, use ModelTurnFinished. Honors Flow::Continue and Flow::Terminate.

Fields

§prompt: &'a Message

The prompt message for this turn.

§response: &'a M::StreamingResponse

The provider’s final streaming response.

Implementations§

Source§

impl<M: CompletionModel> StepEvent<'_, M>

Source

pub fn kind(&self) -> StepEventKind

The StepEventKind discriminant of this event.

Trait Implementations§

Source§

impl<M: CompletionModel> Clone for StepEvent<'_, M>

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<M: CompletionModel> Copy for StepEvent<'_, M>

Auto Trait Implementations§

§

impl<'a, M> !RefUnwindSafe for StepEvent<'a, M>

§

impl<'a, M> !UnwindSafe for StepEvent<'a, M>

§

impl<'a, M> Freeze for StepEvent<'a, M>

§

impl<'a, M> Send for StepEvent<'a, M>

§

impl<'a, M> Sync for StepEvent<'a, M>

§

impl<'a, M> Unpin for StepEvent<'a, M>

§

impl<'a, M> UnsafeUnpin for StepEvent<'a, M>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> CloneableStorage for T
where T: Any + Send + Sync + Clone,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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