Skip to main content

Tool

Trait Tool 

Source
pub trait Tool: Send + Sync {
    type Input: DeserializeOwned + JsonSchema + Send + Sync + 'static;
    type Output: Serialize + Send + Sync;

    // Required method
    fn invoke<'life0, 'async_trait>(
        &'life0 self,
        input: Self::Input,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Output, ToolError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;

    // Provided method
    fn args_schema(&self) -> Option<Value> { ... }
}
Expand description

Generic tool trait (type-safe version).

For scenarios requiring type-safe input/output. Tools implementing this trait can be automatically wrapped as BaseTool.

Required Associated Types§

Source

type Input: DeserializeOwned + JsonSchema + Send + Sync + 'static

Input type (must support deserialization and JSON Schema).

Source

type Output: Serialize + Send + Sync

Output type (must support serialization).

Required Methods§

Source

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

Execute the tool.

§Arguments
  • input - Tool input.
§Returns

Tool output.

Provided Methods§

Source

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

Returns the input JSON Schema.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§