tool

Attribute Macro tool 

Source
#[tool]
Expand description

The #[tool] attribute macro for defining tools.

This macro transforms a regular Rust function into a tool that can be used with the mistral.rs agentic loop. It generates:

  • {fn_name}_tool() - Returns the Tool definition
  • {fn_name}_callback() - Returns an Arc<ToolCallback> that wraps the function
  • {fn_name}_tool_with_callback() - Returns both as a tuple

§Attributes

  • description (required): A description of what the tool does
  • name (optional): Override the tool name (defaults to function name)

§Parameter Attributes

  • #[description = "..."]: Description of the parameter
  • #[default = value]: Default value if parameter is optional

§Requirements

  • All parameter types must implement serde::Deserialize and schemars::JsonSchema
  • The return type must be Result<T> or anyhow::Result<T> where T: Serialize
  • For async functions, ensure a tokio runtime is available