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 method
    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 { ... }
}
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

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§