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
impl HookStack
Sourcepub fn push<H: AgentHook + 'static>(&mut self, hook: H)
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.
Trait Implementations§
Source§impl AgentHook for HookStack
impl AgentHook for HookStack
Source§async fn on_run_start(
&self,
ctx: &HookContext,
event: RunStart<'_>,
) -> RunStartAction
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<'_>)
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
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
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
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
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
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
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>
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
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 moreSource§async fn on_outcome(
&self,
ctx: &HookContext,
event: OutcomeEvent<'_>,
) -> OutcomeAction
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
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.
Auto Trait Implementations§
impl !RefUnwindSafe for HookStack
impl !UnwindSafe for HookStack
impl Freeze for HookStack
impl Send for HookStack
impl Sync for HookStack
impl Unpin for HookStack
impl UnsafeUnpin for HookStack
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more