Skip to main content

ToolHandler

Trait ToolHandler 

Source
pub trait ToolHandler: Send + Sync {
    // Required methods
    fn kind(&self) -> ToolKind;
    fn handle<'life0, 'async_trait>(
        &'life0 self,
        invocation: ToolInvocation,
    ) -> Pin<Box<dyn Future<Output = Result<ToolOutput, ToolCallError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn matches_kind(&self, payload: &ToolPayload) -> bool { ... }
    fn is_mutating<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _invocation: &'life1 ToolInvocation,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Core trait for tool handlers (from Codex)

This trait provides a modular approach to tool execution, separating concerns like kind matching, mutation detection, and actual execution.

Required Methods§

Source

fn kind(&self) -> ToolKind

Get the kind of tool this handler supports

Source

fn handle<'life0, 'async_trait>( &'life0 self, invocation: ToolInvocation, ) -> Pin<Box<dyn Future<Output = Result<ToolOutput, ToolCallError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute the tool and return the output

Provided Methods§

Source

fn matches_kind(&self, payload: &ToolPayload) -> bool

Check if the handler can process the given payload type

Source

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

Check if this invocation would mutate state

Used for approval policies - read-only tools can often be auto-approved

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§