Skip to main content

Hook

Trait Hook 

Source
pub trait Hook: Send + Sync {
    // Provided methods
    fn pre_step<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _context: &'life1 StepContext,
    ) -> Pin<Box<dyn Future<Output = PreStepDecision> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn request<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _context: &'life1 StepContext,
        _policy: &'life2 mut ModelRequestPolicy,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn request_error<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _context: &'life1 StepContext,
        _failure: &'life2 ModelFailure,
    ) -> Pin<Box<dyn Future<Output = RequestErrorAction> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn turn_stopping<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _context: &'life1 StepContext,
    ) -> Pin<Box<dyn Future<Output = TurnStopDecision> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn before_tool<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        _context: &'life1 ToolExecutionContext,
        _tool: &'life2 str,
        _arguments: &'life3 Value,
    ) -> Pin<Box<dyn Future<Output = HookDecision> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn around_tool<'a>(
        &'a self,
        _context: &'a ToolExecutionContext,
        _tool: &'a str,
        _arguments: &'a Value,
        next: ToolExecutionFuture<'a>,
    ) -> ToolExecutionFuture<'a> { ... }
    fn after_tool<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
        &'life0 self,
        _context: &'life1 ToolExecutionContext,
        _tool: &'life2 str,
        _arguments: &'life3 Value,
        _result: &'life4 Value,
    ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             'life4: 'async_trait { ... }
}
Expand description

Interception points around the loop; every method has a no-op default.

Provided Methods§

Source

fn pre_step<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 StepContext, ) -> Pin<Box<dyn Future<Output = PreStepDecision> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Runs before a step opens. The first Reject across hooks wins.

Source

fn request<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _context: &'life1 StepContext, _policy: &'life2 mut ModelRequestPolicy, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Runs before each model request is frozen; hooks apply in mount order.

Source

fn request_error<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _context: &'life1 StepContext, _failure: &'life2 ModelFailure, ) -> Pin<Box<dyn Future<Output = RequestErrorAction> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Runs after each failed model attempt. The first non-Default action wins.

Source

fn turn_stopping<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 StepContext, ) -> Pin<Box<dyn Future<Output = TurnStopDecision> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Runs when the model owes nothing more. The first Steer across hooks wins.

Source

fn before_tool<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _context: &'life1 ToolExecutionContext, _tool: &'life2 str, _arguments: &'life3 Value, ) -> Pin<Box<dyn Future<Output = HookDecision> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Runs before a tool executes; may deny it or park the Run on an interaction.

Source

fn around_tool<'a>( &'a self, _context: &'a ToolExecutionContext, _tool: &'a str, _arguments: &'a Value, next: ToolExecutionFuture<'a>, ) -> ToolExecutionFuture<'a>

Wrap the actual tool execution; call next to run it.

Source

fn after_tool<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, _context: &'life1 ToolExecutionContext, _tool: &'life2 str, _arguments: &'life3 Value, _result: &'life4 Value, ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Runs after a tool result is committed; an error is recorded but cannot replace the result.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§