Tool trait defines the interface for all agent capabilities in ZeroClaw. Implement this trait to expose new functions to the LLM for execution during agent loops.
Trait Definition
Required Methods
name
Return the tool name used in LLM function calling.
&str
Stable lowercase identifier (e.g., “shell”, “file_read”, “memory_recall”)
description
Return a human-readable description for the LLM.
&str
Clear description of what the tool does, used by the LLM to decide when to call it
"Execute a shell command in the workspace directory"
parameters_schema
Return JSON Schema for tool parameters.
serde_json::Value
JSON Schema object defining required and optional parameters
execute
Execute the tool with provided arguments.
serde_json::Value
required
Tool arguments as JSON value. Validate against your schema before execution.
anyhow::Result<ToolResult>
- Validate all inputs before execution
- Never panic - return errors via
ToolResult::error - Keep execution time reasonable (use timeouts)
- Return structured output when possible
Provided Methods
spec
Get the full tool specification for LLM registration.
ToolSpec
name(), description(), and parameters_schema().
Types
ToolResult
- Set
success: truefor successful execution - Put result data in
outputas string (JSON if structured) - Set
success: falseand populateerrorfor failures - The LLM receives this result and can continue reasoning
ToolSpec
Implementation Example
Here’s a complete shell tool implementation with security:Factory Registration
Register your tool in the agent’s tool registry:Security Best Practices
Timeouts: Implement reasonable timeouts to prevent resource exhaustion from long-running operations.
Output Size: Limit output size to prevent memory issues. Truncate large outputs with clear indicators.
Parameter Extraction Patterns
String Parameter
Optional String Parameter
Number Parameter
Boolean Parameter
Object Parameter
Testing
Related
- Provider Trait - LLMs that call your tools
- Memory Trait - Persistent storage for tool results
- Security Reference - Security policies for tool execution