Skip to main content

ObserverHost

Struct ObserverHost 

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

Holds registered observers and dispatches notifications to each.

Observers run in registration order. All observers are always notified — there is no short-circuiting (use the hook system, requires hooks feature, for flow control).

An empty host (no observers registered) is effectively zero-cost: each notification call iterates an empty Vec.

Implementations§

Source§

impl ObserverHost

Source

pub fn new() -> Self

Create an empty observer host.

Equivalent to ObserverHost::default but more explicit.

Source

pub fn register(&mut self, observer: Arc<dyn LoopObserver>)

Register an observer.

Observers are called in registration order at each lifecycle point. Registering the same observer twice will result in duplicate notifications.

Source

pub fn len(&self) -> usize

Number of observers currently registered.

Cheap (O(1)) read of the observer vector length. Returns 0 for a freshly constructed host, in which case every dispatch method is effectively a no-op (it iterates an empty Vec).

Source

pub fn is_empty(&self) -> bool

Whether no observers are registered.

true when len is 0. When true, every dispatch call short-circuits through an empty loop, so an observerless host adds negligible overhead to the agent loop.

Source

pub fn reset_all(&self)

Reset all observers for a new session.

Calls LoopObserver::reset on every registered observer, allowing them to clear per-session accumulators.

Source

pub fn on_run_start(&self, ctx: &RunStartContext)

Dispatch LoopObserver::on_run_start to all observers.

Fired at the start of each run() call, before the first turn begins. Iterates registered observers in registration order; use it to initialize per-run observer state.

Source

pub fn on_run_end(&self, ctx: &RunEndContext)

Dispatch LoopObserver::on_run_end to all observers.

Fired at the end of each run() call, after the loop has terminated. Iterates registered observers in registration order; check RunEndContext::success in each observer to distinguish a normal exit from a failure.

Source

pub fn on_turn_start(&self, ctx: &TurnStartContext)

Dispatch LoopObserver::on_turn_start to all observers.

Fired before the model is called for the turn. Iterates registered observers in registration order.

Source

pub fn on_turn_end(&self, ctx: &TurnEndContext)

Dispatch LoopObserver::on_turn_end to all observers.

Fired after the turn’s model call and any tool dispatch have completed. Iterates registered observers in registration order; check TurnEndContext::success to detect turn-level failures.

Source

pub fn on_stream_success(&self, ctx: &StreamContext)

Dispatch LoopObserver::on_stream_success to all observers.

Fired when a streaming model call completes successfully. Iterates registered observers in registration order. Not fired when the stream fails — see on_stream_failure.

Source

pub fn on_stream_failure(&self, ctx: &StreamFailureContext)

Dispatch LoopObserver::on_stream_failure to all observers.

Fired when a streaming model call fails (timeout, transport error, rate limit). Iterates registered observers in registration order; the loop may retry or fall back to another model after this notification.

Source

pub fn on_response(&self, ctx: &ResponseContext)

Dispatch LoopObserver::on_response to all observers.

Fired once the full model response is assembled — the committed assistant text plus any tool calls, before the framework resolves tool results. Iterates registered observers in registration order.

Source

pub fn on_text_delta(&self, ctx: &TextDeltaContext)

Dispatch LoopObserver::on_text_delta to all observers.

Iterates registered observers in registration order. Called once per streamed text delta, so each observer’s on_text_delta must be cheap.

Source

pub fn on_thinking_delta(&self, ctx: &ThinkingDeltaContext)

Dispatch LoopObserver::on_thinking_delta to all observers.

Iterates registered observers in registration order. Called once per streamed reasoning delta, so each observer’s on_thinking_delta must be cheap.

Source

pub fn on_tool_pre(&self, ctx: &ToolPreContext)

Dispatch LoopObserver::on_tool_pre to all observers.

Fired before a tool is dispatched, carrying the call’s name and input. Iterates registered observers in registration order. Notification-only — use the hook system (requires the hooks feature) for flow control.

Source

pub fn on_tool_call_received(&self, ctx: &ToolCallReceivedContext)

Dispatch LoopObserver::on_tool_call_received to all observers.

Fired when the framework receives a tool call from the model response, before it is dispatched. Iterates registered observers in registration order; useful for pending-call tracking.

Source

pub fn on_tool_post(&self, ctx: &ToolPostContext)

Dispatch LoopObserver::on_tool_post to all observers.

Fired after a tool completes, carrying its output and timing. Iterates registered observers in registration order; useful for loop-detection correlation.

Source

pub fn on_compaction(&self, ctx: &CompactedContext)

Dispatch LoopObserver::on_compaction to all observers.

Fired after the context manager reduces the history, carrying the before/after token counts. Iterates registered observers in registration order; fired only when compaction actually occurred, not on no-action passes.

Source

pub fn on_fallback(&self, ctx: &FallbackContext)

Dispatch LoopObserver::on_fallback to all observers.

Fired when the fallback manager activates a fallback model, carrying the reason and the selected model. Iterates registered observers in registration order; the fallback model will be used for subsequent requests.

Source

pub fn on_model_switched(&self, ctx: &ModelSwitchedContext)

Dispatch LoopObserver::on_model_switched to all observers.

Fired after an explicit model switch is accepted by the client, carrying the old and new model names. Iterates registered observers in registration order.

Source

pub fn on_loop_detected(&self, ctx: &LoopDetectedContext)

Dispatch LoopObserver::on_loop_detected to all observers.

Fired when the loop detector observes the same operation repeatedly, exceeding the configured threshold. Iterates registered observers in registration order.

Source

pub fn on_convergence_detected(&self, ctx: &ConvergenceDetectedContext)

Dispatch LoopObserver::on_convergence_detected to all observers.

Fired when the convergence detector observes semantically similar assistant responses, as determined by the convergence detection policy. Iterates registered observers in registration order.

Trait Implementations§

Source§

impl Default for ObserverHost

Source§

fn default() -> ObserverHost

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<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> 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, 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> 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, 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, <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<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