Skip to main content

Tool

Derive Macro Tool 

Source
#[derive(Tool)]
{
    // Attributes available to this derive:
    #[tool]
    #[tool_param]
}
Expand description

Derive macro that generates a complete Tool trait implementation from a struct definition.

§Struct Attributes

  • #[tool(name = "...", description = "...")] — required
  • #[tool(risk_level = "ReadOnly|Standard|Dangerous")] — optional
  • #[tool(permissions = [Read, Write, ...])] — optional

§Field Attributes

  • #[tool_param(skip)] — internal state, not exposed to LLM
  • #[tool_param(description = "...")] — parameter description (also reads doc comments)

§Example

use echo_agent::prelude::*;

#[derive(Tool)]
#[tool(name = "read_file", description = "Read file contents")]
struct ReadFileTool {
    #[tool_param(skip)]
    base_dir: PathBuf,
    #[tool_param(description = "File path")]
    path: String,
}

impl ToolRunner<ReadFileToolParams> for ReadFileTool {
    async fn run(&self, params: ReadFileToolParams) -> Result<ToolResult> {
        let content = std::fs::read_to_string(&params.path)?;
        Ok(ToolResult::success(content))
    }
}