Skip to main content

Tool

Trait Tool 

Source
pub trait Tool: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn parameters_schema(&self) -> Value;
    fn execute(&self, args: &Value) -> Result<ToolResult, AgentError>;

    // Provided methods
    fn requires_permission(&self) -> bool { ... }
    fn is_dangerous(&self, _args: &Value) -> bool { ... }
}
Expand description

A tool that the agent can invoke.

Implement this trait to create custom tools. Built-in tools (bash, read, write, edit, glob) already ship with the crate.

Required Methods§

Source

fn name(&self) -> &str

Unique name used by the model to invoke this tool (e.g. "bash").

Source

fn description(&self) -> &str

One-line human-readable description shown to the model.

Source

fn parameters_schema(&self) -> Value

JSON Schema description of the parameters object. Must be a valid JSON object schema, e.g.:

{
    "type": "object",
    "properties": {
        "command": { "type": "string", "description": "Shell command" }
    },
    "required": ["command"]
}
Source

fn execute(&self, args: &Value) -> Result<ToolResult, AgentError>

Execute the tool with the given JSON arguments. Returns the tool output as a string (will be injected back into the conversation as the tool result).

Provided Methods§

Source

fn requires_permission(&self) -> bool

Whether this tool requires user permission before execution. Defaults to true for safety.

Source

fn is_dangerous(&self, _args: &Value) -> bool

Whether this tool is considered dangerous (shown as a warning).

Implementors§