Skip to main content

Tool

Trait Tool 

Source
pub trait Tool: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn execute<'life0, 'async_trait>(
        &'life0 self,
        args: Value,
    ) -> Pin<Box<dyn Future<Output = Result<Value, AgentError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Trait for defining executable tools.

Tools are the primary way for AI agents to interact with the world. Each tool has a name and an async execute method that takes JSON arguments and returns a JSON result.

§Thread Safety

All tools must be Send + Sync because they may be executed concurrently across multiple threads.

Required Methods§

Source

fn name(&self) -> &str

Returns the unique name of this tool.

Tool names should be descriptive and follow a consistent naming convention (e.g., snake_case).

Source

fn execute<'life0, 'async_trait>( &'life0 self, args: Value, ) -> Pin<Box<dyn Future<Output = Result<Value, AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Executes the tool with the given arguments.

§Arguments
  • args - JSON value containing the tool parameters. The structure depends on the tool’s parameter schema.
§Returns

A JSON value containing the tool’s output, or an error if execution failed.

§Errors

Returns AgentError::ToolError if the tool execution fails.

Implementors§