Skip to main content

ToolBackend

Trait ToolBackend 

Source
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§

Source

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,

Execute a tool call in this backend’s environment

§Arguments
  • tool_call - The tool call containing name, parameters, and ID
  • context - Execution context with session info, cancellation, etc.
§Returns

The typed tool result on success, or a ToolError on failure

Source

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.

Source

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.

Source

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§

Source

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.

Source

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

Implementors§