Skip to main content

ReactLoopGuard

Trait ReactLoopGuard 

Source
pub trait ReactLoopGuard: Send + Sync {
    // Required method
    fn on_turn<'life0, 'life1, 'async_trait>(
        &'life0 self,
        ctx: &'life1 GuardCtx,
    ) -> Pin<Box<dyn Future<Output = GuardDecision> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn on_tool_call<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _ctx: &'life1 GuardCtx,
    ) -> Pin<Box<dyn Future<Output = GuardDecision> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn set_notice(&self, _handle: NoticeHandle) { ... }
}
Expand description

React Loop Guard trait — single unified entry point.

Runtime builds GuardCtx (with scene hints), guard decides what to do. The guard has full control: it can trust the hints or re-detect.

Required Methods§

Source

fn on_turn<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 GuardCtx, ) -> Pin<Box<dyn Future<Output = GuardDecision> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Unified entry point — guard judges the scene and returns a decision.

Provided Methods§

Source

fn on_tool_call<'life0, 'life1, 'async_trait>( &'life0 self, _ctx: &'life1 GuardCtx, ) -> Pin<Box<dyn Future<Output = GuardDecision> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Callback when model calls a tool (new)

Default implementation: returns Complete (let other logic continue)

Usage:

  • DefaultGuard can return RestoreThinking here
  • Other guards can record tool call history

Note: This callback is called before tool execution, Guard cannot prevent tool execution

Source

fn set_notice(&self, _handle: NoticeHandle)

Receive the engine’s notice handle (Batch E). Called once by the runtime when the guard is registered, before any run starts. Guards that want to surface display-only notices (e.g. judge degradation) store the handle; the default implementation ignores it, so existing implementers are unaffected.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§