Skip to main content
The 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”)
Note: This name is used by the LLM to invoke the tool. Keep it stable across versions.

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
Example: "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
Example:

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>
Important:
  • 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
Default: Combines name(), description(), and parameters_schema().

Types

ToolResult

Usage:
  • Set success: true for successful execution
  • Put result data in output as string (JSON if structured)
  • Set success: false and populate error for 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

Input Validation: Always validate and sanitize inputs. Never trust LLM-generated arguments blindly.
Command Injection: For shell tools, validate commands against blocklists and use proper escaping. Never concatenate user input directly into shell commands.
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.
Error Messages: Return helpful error messages in ToolResult.error so the LLM can understand what went wrong and retry intelligently.

Parameter Extraction Patterns

String Parameter

Optional String Parameter

Number Parameter

Boolean Parameter

Object Parameter

Testing