Skip to main content

HookStack

Struct HookStack 

Source
pub struct HookStack { /* private fields */ }
Expand description

Ordered composable hook stack.

Model selections chain in registration order: each hook sees the candidate selected by earlier hooks, the last selection wins, and a stop is terminal. Nested stacks preserve the same composition semantics.

Implementations§

Source§

impl HookStack

Source

pub fn new() -> Self

Creates an empty hook stack.

Source

pub fn with<H: AgentHook + 'static>(hook: H) -> Self

Creates a hook stack containing hook.

Source

pub fn push<H: AgentHook + 'static>(&mut self, hook: H)

Append a hook. Its recorded name is AgentHook::name or its type name without the module path; nested stacks contribute flattened names.

Source

pub fn names(&self) -> Vec<String>

Recorded hook names in registration order, with nested stacks flattened.

Source

pub fn is_empty(&self) -> bool

Returns true when the stack contains no hooks.

Source

pub fn len(&self) -> usize

Returns the number of hooks in the stack.

Trait Implementations§

Source§

impl AgentHook for HookStack

Source§

async fn on_run_start( &self, ctx: &HookContext, event: RunStart<'_>, ) -> RunStartAction

Runs once before the run’s first model call, seeing the initial prompt. Read more
Source§

async fn on_run_settled(&self, ctx: &HookContext, event: RunSettled<'_>)

Observe the final response or terminal error without scheduling more work. Existing entries are visible, but entries appended here are not transferred into the finished run.
Source§

fn on_model_select( &self, ctx: &HookContext, event: ModelSelection<'_>, ) -> ModelSelectionAction

Selects the model for the pending model-call boundary. Read more
Source§

async fn on_completion_call( &self, ctx: &HookContext, event: CompletionCallEvent<'_>, ) -> CompletionCallAction

Runs before a completion request is sent. Read more
Source§

async fn on_model_turn_finished( &self, ctx: &HookContext, event: ModelTurnFinished<'_>, ) -> ModelTurnAction

Observes or rejects the content produced at the end of a model turn. Read more
Source§

async fn on_text_delta( &self, ctx: &HookContext, event: TextDelta<'_>, ) -> ObservationAction

Observes a text delta from a streaming response. Read more
Source§

async fn on_reasoning_delta( &self, ctx: &HookContext, event: ReasoningDelta<'_>, ) -> ObservationAction

Observes a reasoning delta from a streaming response. Read more
Source§

async fn on_tool_call_delta( &self, ctx: &HookContext, event: ToolCallDelta<'_>, ) -> ObservationAction

Observes an argument fragment of a streaming tool call, before the fragment reaches the stream. A stop cancels the run before the call executes. Like all streamed deltas, it remains provisional until the model turn is accepted. Read more
Source§

async fn on_invalid_tool_call( &self, ctx: &HookContext, event: &InvalidToolCallContext, ) -> Option<InvalidToolCallAction>

Resolves a model-emitted tool call that cannot be dispatched as written. Read more
Source§

async fn on_dispatch( &self, ctx: &HookContext, event: DispatchEvent<'_>, ) -> DispatchAction

An effect is about to be dispatched through the agent’s handlers. Runs for every family; Memory, Retrieve, Embed, Rerank and Custom dispatches are observe-only unless the hook opts in through AgentHook::observes for their StepEventKind. Read more
Source§

async fn on_outcome( &self, ctx: &HookContext, event: OutcomeEvent<'_>, ) -> OutcomeAction

An effect resolved through the agent’s handlers. Gated by AgentHook::observes like AgentHook::on_dispatch. Each dispatched id gets at most one outcome; a denied one gets none. A completion’s outcome fires after the run validated an accepted turn, where a replacement applies. Every other attempt closes observe-only and a replacement is ignored. It is Err when no whole answer arrived: the provider call failed, a hook stopped the run mid-reply (Cancelled), or the run failed a streamed reply before it ended. It is Ok with the provider’s response when the answer arrived and the run rejected, retried, recovered, abandoned or failed it, so an Ok completion outcome is not proof that the turn was accepted.
Source§

fn observes(&self, kind: StepEventKind) -> bool

Declare event interest. Memory, retrieval, embedding, reranking, and custom dispatches default to false; all other kinds default to true. For dispatch events, false prevents both boundary callbacks and therefore prevents this hook from steering that family.
Source§

fn name(&self) -> Option<String>

Replay identity recorded by the hook stack. None uses the unqualified type name; include decision-affecting configuration in an explicit name.
Source§

impl Clone for HookStack

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 HookStack

Source§

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

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

impl Default for HookStack

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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> 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