Skip to main content

Tool

Trait Tool 

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

    // Provided methods
    fn implementation_version(&self) -> &str { ... }
    fn meta(&self) -> ToolMeta { ... }
    fn call_with_context<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _context: &'life1 ToolExecutionContext,
        args: Value,
    ) -> Pin<Box<dyn Future<Output = Result<Value, String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

A callable tool. parameters is a JSON-Schema object describing the args.

Required Methods§

Source

fn name(&self) -> &str

Stable internal name.

Source

fn description(&self) -> &str

Model-facing description.

Source

fn parameters(&self) -> Value

JSON Schema for the arguments.

Source

fn output_schema(&self) -> Value

JSON Schema for the result.

Source

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

Run the tool. On success return a JSON value; on failure return a short error string (surfaced back to the model as {"error": ...} so it can recover) — mirrors the Python “success → dict / failure → {error}” rule.

Provided Methods§

Source

fn implementation_version(&self) -> &str

Implementation version pinned by Profile revisions.

Source

fn meta(&self) -> ToolMeta

Execution metadata.

Source

fn call_with_context<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 ToolExecutionContext, args: Value, ) -> Pin<Box<dyn Future<Output = Result<Value, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Like call with the execution context; the default ignores the context.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§