pub trait ToolBackend: Send + Sync {
// Required methods
fn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
tool_call: &'life1 ToolCall,
context: &'life2 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn supported_tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Vec<String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn get_tool_schemas<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Vec<ToolSchema>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn metadata(&self) -> BackendMetadata;
// Provided methods
fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn requires_approval<'life0, 'life1, 'async_trait>(
&'life0 self,
_tool_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, ToolError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
Simple trait for tool execution backends
This trait abstracts different execution environments for tools, allowing tools to run locally, on remote machines, in containers, or through proxy services.
Required Methods§
Sourcefn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
tool_call: &'life1 ToolCall,
context: &'life2 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + 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,
context: &'life2 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Sourcefn supported_tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Vec<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn supported_tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Vec<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
List the tools this backend can handle
Returns a vector of tool names that this backend supports. The backend registry uses this to map tools to backends.
Sourcefn get_tool_schemas<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Vec<ToolSchema>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_tool_schemas<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Vec<ToolSchema>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Get API tool descriptions for this backend
Returns a vector of ToolSchema objects containing name, description, and input schema for each tool this backend supports.
Sourcefn metadata(&self) -> BackendMetadata
fn metadata(&self) -> BackendMetadata
Backend metadata for debugging and monitoring
Override this method to provide additional information about the backend for observability and troubleshooting.
Provided Methods§
Sourcefn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Check if the backend is healthy and ready to execute tools
This method can be used for health checks and load balancing. Default implementation returns true.
Sourcefn requires_approval<'life0, 'life1, 'async_trait>(
&'life0 self,
_tool_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, ToolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn requires_approval<'life0, 'life1, 'async_trait>(
&'life0 self,
_tool_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, ToolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Check if a tool requires approval before execution
Returns true if the tool requires user approval before it can be executed. Default implementation returns true for safety.
§Arguments
tool_name- The name of the tool to check
§Returns
Ok(true) if approval is required, Ok(false) if not, or an error if the tool is unknown