Skip to main content

ToolExecutor

Trait ToolExecutor 

Source
pub trait ToolExecutor: Send + Sync {
    // Required methods
    fn execute<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        tool_use: &'life1 ToolUse,
        context: &'life2 ToolContext,
    ) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn available_tools(&self) -> Vec<Tool>;
}
Expand description

Trait for executing tools in an agent context.

Implement this on your tool executor to integrate with framework agents like TaskAgent. The trait is object-safe and can be used as Arc<dyn ToolExecutor>.

§Example

use brainwires_tool_system::ToolExecutor;
use brainwires_core::{Tool, ToolContext, ToolResult, ToolUse};
use async_trait::async_trait;

struct MyExecutor;

#[async_trait]
impl ToolExecutor for MyExecutor {
    async fn execute(&self, tool_use: &ToolUse, context: &ToolContext) -> anyhow::Result<ToolResult> {
        Ok(ToolResult::success(tool_use.id.clone(), "done".to_string()))
    }

    fn available_tools(&self) -> Vec<Tool> {
        vec![]
    }
}

Required Methods§

Source

fn execute<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, tool_use: &'life1 ToolUse, context: &'life2 ToolContext, ) -> 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 tool and return its result.

The tool_use contains the tool name and input parameters. The context provides working directory and execution metadata.

Source

fn available_tools(&self) -> Vec<Tool>

Return the list of tools available for the AI to invoke.

Implementors§