Skip to main content

Tool

Trait Tool 

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

    // Provided method
    fn ephemeral(&self) -> EphemeralConfig { ... }
}
Expand description

Trait for defining tools that can be called by an LLM

Required Methods§

Source

fn name(&self) -> &str

Get the tool name

Source

fn description(&self) -> &str

Get the tool description

Source

fn definition(&self) -> ToolDefinition

Get the tool definition (JSON Schema)

Source

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

Execute the tool with given arguments

Provided Methods§

Source

fn ephemeral(&self) -> EphemeralConfig

Whether tool outputs should be ephemeral (removed from context after use)

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<F> Tool for SimpleTool<F>
where F: Fn() -> Pin<Box<dyn Future<Output = Result<String>> + Send>> + Send + Sync,

Source§

impl<T, F> Tool for FunctionTool<T, F>
where T: DeserializeOwned + Send + Sync + 'static, F: Fn(T) -> Pin<Box<dyn Future<Output = Result<String>> + Send>> + Send + Sync,