pub trait ToolExecutor: Send + Sync {
// Required method
fn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
tool_call: &'life1 ToolCall,
tool_def: &'life2 ToolDefinition,
) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
// Provided methods
fn execute_with_context<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
tool_call: &'life1 ToolCall,
tool_def: &'life2 ToolDefinition,
_context: &'life3 ToolContext,
) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait { ... }
fn execute_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
tool_calls: &'life1 [ToolCall],
tool_defs: &'life2 [ToolDefinition],
) -> Pin<Box<dyn Future<Output = Result<Vec<ToolResult>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn execute_parallel<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
tool_calls: &'life1 [ToolCall],
tool_defs: &'life2 [ToolDefinition],
) -> Pin<Box<dyn Future<Output = Result<Vec<ToolResult>>> + Send + 'async_trait>>
where Self: Sized + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
}Expand description
Trait for executing tool calls
Implementations handle the actual tool execution:
- Webhook calls
- Built-in function execution
- Mock execution for testing
Required Methods§
Sourcefn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
tool_call: &'life1 ToolCall,
tool_def: &'life2 ToolDefinition,
) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
tool_call: &'life1 ToolCall,
tool_def: &'life2 ToolDefinition,
) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Execute a single tool call (without context)
This is the legacy method that doesn’t provide context to tools.
Use execute_with_context when context is available.
Provided Methods§
Sourcefn execute_with_context<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
tool_call: &'life1 ToolCall,
tool_def: &'life2 ToolDefinition,
_context: &'life3 ToolContext,
) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn execute_with_context<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
tool_call: &'life1 ToolCall,
tool_def: &'life2 ToolDefinition,
_context: &'life3 ToolContext,
) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Execute a single tool call with context
This method provides runtime context to tools that need it (like filesystem tools).
The default implementation delegates to execute().
Sourcefn execute_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
tool_calls: &'life1 [ToolCall],
tool_defs: &'life2 [ToolDefinition],
) -> Pin<Box<dyn Future<Output = Result<Vec<ToolResult>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn execute_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
tool_calls: &'life1 [ToolCall],
tool_defs: &'life2 [ToolDefinition],
) -> Pin<Box<dyn Future<Output = Result<Vec<ToolResult>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Execute multiple tool calls (default: sequential)
Sourcefn execute_parallel<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
tool_calls: &'life1 [ToolCall],
tool_defs: &'life2 [ToolDefinition],
) -> Pin<Box<dyn Future<Output = Result<Vec<ToolResult>>> + Send + 'async_trait>>where
Self: Sized + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn execute_parallel<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
tool_calls: &'life1 [ToolCall],
tool_defs: &'life2 [ToolDefinition],
) -> Pin<Box<dyn Future<Output = Result<Vec<ToolResult>>> + Send + 'async_trait>>where
Self: Sized + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Execute multiple tool calls in parallel
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl ToolExecutor for Arc<dyn ToolExecutor>
Delegating impl so callers can hold a ToolExecutor as a trait object
(e.g. to choose between a plain registry and an MCP-routing composite at
runtime without monomorphizing the consumer).
impl ToolExecutor for Arc<dyn ToolExecutor>
Delegating impl so callers can hold a ToolExecutor as a trait object
(e.g. to choose between a plain registry and an MCP-routing composite at
runtime without monomorphizing the consumer).