Skip to main content

Tool

Trait Tool 

Source
pub trait Tool {
    type Error: Error + 'static;
    type Args: DeserializeOwned;
    type Output: Serialize;

    const NAME: &'static str;

    // Required methods
    fn definition(&self) -> ToolDefinition;
    fn call(
        &self,
        args: Self::Args,
    ) -> impl Future<Output = Result<Self::Output, Self::Error>>;
}
Expand description

A typed, async tool that an Agent can call.

Implement this trait to create tools. Register them with a ToolSet.

Required Associated Constants§

Source

const NAME: &'static str

Must match ToolDefinition::name exactly.

Required Associated Types§

Source

type Error: Error + 'static

Error type returned if the tool fails.

Source

type Args: DeserializeOwned

Deserialised argument type. Must match the parameters schema.

Source

type Output: Serialize

Serialisable output type.

Required Methods§

Source

fn definition(&self) -> ToolDefinition

Schema + description sent to the model before each completion call.

Source

fn call( &self, args: Self::Args, ) -> impl Future<Output = Result<Self::Output, Self::Error>>

Execute the tool with the deserialised arguments.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§