Skip to main content

Tool

Trait Tool 

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

    // Provided methods
    fn definition(&self) -> ToolDefinition { ... }
    fn requires_store(&self) -> bool { ... }
    fn invoke_with_store<'a>(
        &'a self,
        input: Value,
        _store: &'a dyn Store,
    ) -> BoxFuture<'a, Result<String, ToolError>>
       where Self: 'a { ... }
}
Expand description

Unified tool trait

All tools must implement this trait to be used with ToolNode.

Note: This trait does not implement Debug as it’s an async trait intended for dynamic dispatch via trait objects.

Required Methods§

Source

fn name(&self) -> &str

Get tool name

Source

fn description(&self) -> &str

Get tool description

Source

fn schema(&self) -> Value

Get JSON Schema for tool parameters

Source

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

Execute the tool

§Arguments
  • input - Tool input as JSON value (validated against schema)
§Returns

Tool output as string

Provided Methods§

Source

fn definition(&self) -> ToolDefinition

Get tool definition

Source

fn requires_store(&self) -> bool

Check if this tool requires Store access

Tools that need persistent cross-thread storage should return true. The default implementation returns false.

§Returns

true if the tool requires Store access, false otherwise

Source

fn invoke_with_store<'a>( &'a self, input: Value, _store: &'a dyn Store, ) -> BoxFuture<'a, Result<String, ToolError>>
where Self: 'a,

Execute the tool with Store access

This method is called instead of invoke() when requires_store() returns true. The default implementation delegates to invoke(), ignoring the Store parameter.

§Arguments
  • input - Tool input as JSON value (validated against schema)
  • store - Store for cross-thread persistent data access
§Returns

Tool output as string

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§