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§
Sourcefn 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,
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§
Sourcefn matches_kind(&self, payload: &ToolPayload) -> bool
fn matches_kind(&self, payload: &ToolPayload) -> bool
Check if the handler can process the given payload type
Sourcefn 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,
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".