Skip to main content

AgentTool

Trait AgentTool 

Source
pub trait AgentTool: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn label(&self) -> &str;
    fn description(&self) -> &str;
    fn parameters_schema(&self) -> Value;
    fn execute<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        tool_call_id: &'life1 str,
        params: Value,
        signal: Option<Receiver<()>>,
        ctx: &'life2 ToolContext,
    ) -> Pin<Box<dyn Future<Output = Result<AgentToolResult, String>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn essential(&self) -> bool { ... }
    fn on_progress(&self, _callback: Arc<dyn Fn(String) + Send + Sync>) { ... }
    fn to_definition(&self) -> ToolDefinition { ... }
}
Expand description

Core trait for all agent tools

Required Methods§

Source

fn name(&self) -> &str

Tool name (used in function calls)

Source

fn label(&self) -> &str

Human-readable label

Source

fn description(&self) -> &str

Description for the model

Source

fn parameters_schema(&self) -> Value

JSON Schema for parameters

Source

fn execute<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, tool_call_id: &'life1 str, params: Value, signal: Option<Receiver<()>>, ctx: &'life2 ToolContext, ) -> Pin<Box<dyn Future<Output = Result<AgentToolResult, String>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Execute the tool with the given tool call ID and parameters.

The ctx parameter provides workspace information. File tools should use ctx.root() to get the effective directory. Custom tools can use ctx.workspace_dir for workspace-relative operations.

§Examples
use oxi_agent::{AgentTool, AgentToolResult, ToolContext};
use serde_json::json;
use async_trait::async_trait;

struct MyTool;

#[async_trait]
impl AgentTool for MyTool {
    fn name(&self) -> &str { "my_tool" }
    fn label(&self) -> &str { "My Tool" }
    fn description(&self) -> &str { "A custom tool" }
    fn parameters_schema(&self) -> Value { json!({
        "type": "object",
        "properties": {}
    }) }

    async fn execute(&self, tool_call_id: &str, params: Value, _signal: Option<oneshot::Receiver<()>>, ctx: &ToolContext) -> Result<AgentToolResult, String> {
        println!("Tool '{}' called with params: {:?}, workspace: {:?}", tool_call_id, params, ctx.workspace_dir);
        Ok(AgentToolResult::success("Done!"))
    }
}

Provided Methods§

Source

fn essential(&self) -> bool

Whether this tool is essential (cannot be disabled). Essential tools: read, write, edit, bash, grep, find, ls Optional tools: web_search, github, subagent, etc.

Source

fn on_progress(&self, _callback: Arc<dyn Fn(String) + Send + Sync>)

Called with progress updates during execution. Tools can override this to emit streaming updates.

Source

fn to_definition(&self) -> ToolDefinition

Convert to ToolDefinition

Implementations on Foreign Types§

Source§

impl AgentTool for ClosureTool

Source§

fn name(&self) -> &str

Source§

fn label(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn parameters_schema(&self) -> Value

Source§

fn execute<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _tool_call_id: &'life1 str, params: Value, _signal: Option<Receiver<()>>, ctx: &'life2 ToolContext, ) -> Pin<Box<dyn Future<Output = Result<AgentToolResult, String>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, ClosureTool: 'async_trait,

Implementors§