Trait rig::tool::Tool

source ·
pub trait Tool: Sized + Send + Sync {
    type Error: Error + Send + Sync + 'static;
    type Args: for<'a> Deserialize<'a> + Send + Sync;
    type Output: Serialize;

    const NAME: &'static str;

    // Required methods
    fn definition(
        &self,
        _prompt: String,
    ) -> impl Future<Output = ToolDefinition> + Send + Sync;
    fn call(
        &self,
        args: Self::Args,
    ) -> impl Future<Output = Result<Self::Output, Self::Error>> + Send + Sync;

    // Provided method
    fn name(&self) -> String { ... }
}
Expand description

Trait that represents a simple LLM tool

Required Associated Types§

source

type Error: Error + Send + Sync + 'static

source

type Args: for<'a> Deserialize<'a> + Send + Sync

source

type Output: Serialize

Required Associated Constants§

source

const NAME: &'static str

The name of the tool. This name should be unique.

Required Methods§

source

fn definition( &self, _prompt: String, ) -> impl Future<Output = ToolDefinition> + Send + Sync

A method returning the tool definition. The user prompt can be used to tailor the definition to the specific use case.

source

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

The tool execution method. Both the arguments and return value are a String since these values are meant to be the output and input of LLM models (respectively)

Provided Methods§

source

fn name(&self) -> String

A method returning the name of the tool.

Object Safety§

This trait is not object safe.

Implementors§