Overview
TheToolRegistry manages all available tools in an OneClaw system. It provides tool registration, discovery, parameter validation, and secure execution with event emission.
Source: /home/daytona/workspace/source/crates/oneclaw-core/src/tool/registry.rs:14
Security Model
Before executing any tool, the registry performs:- Existence check: Tool must be registered
- Parameter validation: All required parameters must be present
- Event emission: Execution results are published to the event bus
Struct Definition
Methods
new()
Creates an empty tool registry. Returns:ToolRegistry
Usage:
register()
Registers a tool, making it available for execution. Parameters:tool:Box<dyn Tool>- The tool implementation to register
list_tools()
Returns metadata for all registered tools, suitable for LLM function calling. Returns:Vec<ToolInfo> - List of tool metadata
Usage:
get_tool_info()
Retrieves metadata for a specific tool by name. Parameters:name:&str- The tool name
Option<ToolInfo> - Tool metadata if found
Usage:
execute()
Executes a tool with parameter validation and event emission. Parameters:tool_name:&str- Name of the tool to executeparams:&HashMap<String, String>- Parameter key-value pairsevent_bus:Option<&dyn EventBus>- Optional event bus for execution events
Result<ToolResult> - Tool execution result or error
Errors:
OneClawError::Tool- Tool not found or missing required parameters
- Topic:
tool.<tool_name> - Source:
tool-registry - Data:
tool: Tool namesuccess: “true” or “false”output_len: Length of output string
- Priority:
Highfor failures,Normalfor success
count()
Returns the number of registered tools. Returns:usize
Usage:
Validation Flow
Whenexecute() is called:
- Tool lookup: Verify tool exists in registry
- Parameter validation: Check all required parameters are present
- Execution: Call the tool’s
execute()method - Event emission: Publish execution result to event bus
- Return: Return
ToolResultto caller
Discovery Pattern
Tools can be discovered and introspected before execution:Example: Complete Setup
Thread Safety
ToolRegistry is Send but not Sync. To share across threads, wrap in Arc<Mutex<ToolRegistry>>:
See Also
- Tool Trait - Implementing custom tools
- Built-in Tools - Standard tool implementations
- EventBus - Event emission system