Skip to main content

LlmTool

Trait LlmTool 

Source
pub trait LlmTool: Send + Sync {
    // Required methods
    fn run<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        args: &'life1 HashMap<String, Value>,
        ctx: &'life2 ToolRunCtx,
    ) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn descriptor(&self) -> ToolDescriptor;
    fn clone_box(&self) -> Box<dyn LlmTool>;

    // Provided method
    fn matches(&self, name: &str) -> bool { ... }
}
Expand description

Trait for LLM tools.

2.0 change: run is now async and accepts an optional ToolRunCtx. Existing tools that previously implemented sync run(&self, args) need to be ported to the new signature. The minimal migration is to wrap the body in async {} and add an unused _ctx parameter; see book/src/migration.md.

Required Methods§

Source

fn run<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, args: &'life1 HashMap<String, Value>, ctx: &'life2 ToolRunCtx, ) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Execute the tool with given arguments.

Source

fn descriptor(&self) -> ToolDescriptor

Get tool descriptor for LLM

Source

fn clone_box(&self) -> Box<dyn LlmTool>

Clone the tool into a Box

This method is required to support cloning trait objects. Implementations should return Box::new(self.clone()).

Provided Methods§

Source

fn matches(&self, name: &str) -> bool

Check if this tool matches the given name

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§