Skip to main content

Module tools

Module tools 

Source
Expand description

Tool abstraction layer: trait definitions, built-in tools, and the runtime executor that routes LLM tool calls to the correct handler.

§Built-in tools

Three tools are registered by default via SystemToolExecutor::register_builtins:

NameDescription
execute_commandRun a shell command (sh -c on Unix, cmd /C on Windows)
read_fileRead a file from disk
write_fileWrite a file to disk, creating parent directories as needed

Additional tools are loaded from MCP servers and registered under the {server_name}__{tool_name} namespace.

§Implementing a custom tool

use async_trait::async_trait;
use serde_json::json;

struct GreetTool;

#[async_trait]
impl ToolHandler for GreetTool {
    fn definition(&self) -> Tool {
        Tool {
            tool_type: "function".to_string(),
            function: FunctionDefinition {
                name: "greet".to_string(),
                description: "Greet someone by name.".to_string(),
                parameters: json!({
                    "type": "object",
                    "properties": { "name": { "type": "string" } },
                    "required": ["name"]
                }),
            },
        }
    }

    async fn execute(&self, args: &str) -> Result<String> {
        let v: serde_json::Value = serde_json::from_str(args)?;
        let name = v["name"].as_str().unwrap_or("world");
        Ok(format!("Hello, {name}!"))
    }
}

Structs§

SystemToolExecutor
The default tool executor used by the agent runtime.

Traits§

ToolExecutor
Routes LLM tool-call requests to the correct ToolHandler.
ToolHandler