Skip to main content

ToolInterceptor

Trait ToolInterceptor 

Source
pub trait ToolInterceptor:
    Send
    + Sync
    + 'static {
    // Required methods
    fn pre_execute(
        &self,
        tool_call: &ToolCall,
        state: &Value,
    ) -> BoxFuture<'_, Result<(), ToolError>>;
    fn post_execute(
        &self,
        tool_call: &ToolCall,
        result: &Result<String, ToolError>,
    ) -> BoxFuture<'_, Result<String, ToolError>>;
}
Expand description

Tool call interceptor trait

Allows injecting custom logic before and after tool execution.

Note: This trait does not implement Debug as it’s an async trait intended for dynamic dispatch via trait objects.

Required Methods§

Source

fn pre_execute( &self, tool_call: &ToolCall, state: &Value, ) -> BoxFuture<'_, Result<(), ToolError>>

Called before tool execution

Return Err to cancel tool execution with error message.

Source

fn post_execute( &self, tool_call: &ToolCall, result: &Result<String, ToolError>, ) -> BoxFuture<'_, Result<String, ToolError>>

Called after tool execution

Can modify the tool result.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§