Skip to main content

Module tool

Module tool 

Source
Expand description

Tool trait and type-erased tool dispatch.

A Tool is a typed async function the model can invoke. Define the schema via ToolDefinition and implement Tool::call with your logic.

ToolSet holds a collection of type-erased tools keyed by name. The Agent uses it to dispatch model-requested tool calls.

§Example

use irig::tool::{Tool, ToolDefinition, ToolSet};
use serde::Deserialize;
use serde_json::json;

#[derive(Deserialize)]
struct AddArgs { x: f64, y: f64 }

struct Adder;

impl Tool for Adder {
    const NAME: &'static str = "add";
    type Error = std::convert::Infallible;
    type Args  = AddArgs;
    type Output = f64;

    fn definition(&self) -> ToolDefinition {
        ToolDefinition {
            name: "add".into(),
            description: "Add two numbers.".into(),
            parameters: json!({
                "type": "object",
                "properties": {
                    "x": { "type": "number" },
                    "y": { "type": "number" }
                },
                "required": ["x", "y"]
            }),
        }
    }

    async fn call(&self, args: AddArgs) -> Result<f64, std::convert::Infallible> {
        Ok(args.x + args.y)
    }
}

let mut tools = ToolSet::new();
tools.add(Adder);

Structs§

ToolDefinition
Describes a tool to the LLM.
ToolSet

Enums§

ToolError
Errors that can occur when dispatching a tool call.

Traits§

Tool
A typed, async tool that an Agent can call.