Overview
TheTool trait is the foundation of Layer 4 (Tools) in OneClaw. It defines the interface for executable actions that agents can perform in the world. All tools must implement this trait to be registered and executed through the ToolRegistry.
Source: /home/daytona/workspace/source/crates/oneclaw-core/src/tool/traits.rs:59
Trait Definition
Core Types
ToolInfo
Describes the tool’s metadata for discovery and LLM function calling.ToolParam
Defines a single parameter that the tool accepts.ToolResult
Represents the outcome of tool execution.Builder Methods
Methods
info()
Returns the tool’s metadata for registration and discovery. Returns:ToolInfo containing the tool’s name, description, parameters, and category.
Usage:
execute()
Executes the tool with the provided parameters. Parameters:params:&HashMap<String, String>- Key-value pairs of parameter names and values
Result<ToolResult> - Success with output or error
Security: Parameter validation and security checks are performed by ToolRegistry BEFORE calling execute().
Usage:
Parameter Validation
TheToolRegistry automatically validates required parameters before calling execute(). However, tools should still validate parameter values and types:
Categories
Tools are organized into categories:io: File and data operations (e.g.,file_write)network: Network requests and external communicationsystem: System information and control (e.g.,system_info)notify: Notifications and alerts (e.g.,notify)
Example: NoopTool
A minimal tool implementation for testing:Thread Safety
Tools must beSend + Sync to allow concurrent execution across threads. Ensure any internal state is properly synchronized:
See Also
- ToolRegistry - Tool registration and execution
- Built-in Tools - Standard tool implementations