Skip to main content

BaseTool

Trait BaseTool 

Source
pub trait BaseTool: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn run<'life0, 'async_trait>(
        &'life0 self,
        input: String,
    ) -> Pin<Box<dyn Future<Output = Result<String, ToolError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn args_schema(&self) -> Option<Value> { ... }
    fn return_direct(&self) -> bool { ... }
    fn handle_error<'life0, 'async_trait>(
        &'life0 self,
        error: ToolError,
    ) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Base tool trait (object-safe version).

This is the base interface for tool registries and Agents. Uses string input/output to simplify LLM calls.

All tools must implement this interface to be used by Agents.

Required Methods§

Source

fn name(&self) -> &str

Returns the tool name.

Name should be unique and clearly express the tool’s purpose.

Source

fn description(&self) -> &str

Returns the tool description.

Description should detail the tool’s purpose, input format, and output format.

Source

fn run<'life0, 'async_trait>( &'life0 self, input: String, ) -> Pin<Box<dyn Future<Output = Result<String, ToolError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute the tool (string version).

This is the primary interface called by Agents. Input is typically a JSON string, output is the execution result.

§Arguments
  • input - Tool input (typically JSON-formatted string).
§Returns

String representation of execution result.

Provided Methods§

Source

fn args_schema(&self) -> Option<Value>

Returns the input JSON Schema.

Used to describe the tool’s input format to the LLM.

Source

fn return_direct(&self) -> bool

Whether to return result directly to user.

If true, tool output is returned directly to user, not passed to Agent.

Source

fn handle_error<'life0, 'async_trait>( &'life0 self, error: ToolError, ) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle execution error.

Returns a friendly error message when tool execution fails.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§