Skip to main content

tiny_loop/tool/
args.rs

1use crate::types::{Parameters, ToolDefinition, ToolFunction};
2use schemars::JsonSchema;
3use serde::Deserialize;
4
5/// Provides tool name, description, and definitions for tools generated by the [`#[tool]`](crate::tool::tool) macro.
6pub trait ToolArgs: JsonSchema + for<'a> Deserialize<'a> {
7    const TOOL_NAME: &'static str;
8    const TOOL_DESCRIPTION: &'static str;
9
10    /// Generates the tool definition with name, description, and parameter schema.
11    fn definition() -> ToolDefinition {
12        ToolDefinition {
13            tool_type: "function".to_string(),
14            function: ToolFunction {
15                name: Self::TOOL_NAME.to_string(),
16                description: Self::TOOL_DESCRIPTION.to_string(),
17                parameters: Parameters::from_type::<Self>(),
18            },
19        }
20    }
21}