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§
Sourcefn description(&self) -> &str
fn description(&self) -> &str
One-line human-readable description shown to the model.
Sourcefn parameters_schema(&self) -> Value
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"]
}Sourcefn execute(&self, args: &Value) -> Result<ToolResult, AgentError>
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§
Sourcefn requires_permission(&self) -> bool
fn requires_permission(&self) -> bool
Whether this tool requires user permission before execution.
Defaults to true for safety.
Sourcefn is_dangerous(&self, _args: &Value) -> bool
fn is_dangerous(&self, _args: &Value) -> bool
Whether this tool is considered dangerous (shown as a warning).