Skip to main content

ToolDispatchHook

Trait ToolDispatchHook 

Source
pub trait ToolDispatchHook: Send + Sync {
    // Provided methods
    fn before_invocation<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _invocation: &'life1 ToolInvocation,
    ) -> Pin<Box<dyn Future<Output = Result<ToolDispatchAction, KernelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn after_invocation<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _result: &'life1 ToolInvocationResult,
    ) -> Pin<Box<dyn Future<Output = Result<(), KernelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn after_invocation_with_outcome<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        result: &'life1 ToolInvocationResult,
        _outcome: &'life2 ToolInvocationOutcome,
    ) -> Pin<Box<dyn Future<Output = Result<(), KernelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_invocation_error<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _invocation: &'life1 ToolInvocation,
        _error: &'life2 KernelError,
    ) -> Pin<Box<dyn Future<Output = Result<(), KernelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

Hook for policy, accounting, and tracing around normalized tool dispatch.

Hooks are intentionally provider-neutral: they see only the normalized ToolInvocation and the resulting ToolInvocationResult. Concrete policy engines, approval systems, and trace exporters should live in downstream crates and plug into this small kernel surface.

Provided Methods§

Source

fn before_invocation<'life0, 'life1, 'async_trait>( &'life0 self, _invocation: &'life1 ToolInvocation, ) -> Pin<Box<dyn Future<Output = Result<ToolDispatchAction, KernelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called before each invocation. Return ToolDispatchAction::Continue to invoke the tool, ToolDispatchAction::Skip to synthesize a result, or ToolDispatchAction::Terminate to stop the dispatch loop.

Source

fn after_invocation<'life0, 'life1, 'async_trait>( &'life0 self, _result: &'life1 ToolInvocationResult, ) -> Pin<Box<dyn Future<Output = Result<(), KernelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called after a tool invocation or hook-provided skip result is recorded.

Source

fn after_invocation_with_outcome<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, result: &'life1 ToolInvocationResult, _outcome: &'life2 ToolInvocationOutcome, ) -> Pin<Box<dyn Future<Output = Result<(), KernelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called after a dispatch result is recorded, including whether it came from real tool execution or a hook-provided skip.

The default implementation preserves compatibility for hooks that only care about the result payload.

Source

fn on_invocation_error<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _invocation: &'life1 ToolInvocation, _error: &'life2 KernelError, ) -> Pin<Box<dyn Future<Output = Result<(), KernelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called when dispatch stops after this hook may have observed the invocation in Self::before_invocation. Hooks that reserve resources before dispatch should release them here.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§