Skip to main content
Tools are functions that the LLM can call during agent runs. OpenClaw plugins can register custom tools to extend agent capabilities with domain-specific actions, integrations, and workflows.

Tool Structure

A tool has three core components:
  1. name - Unique identifier (e.g., "send_email", "create_ticket")
  2. description - Natural language description of what the tool does
  3. input - TypeBox schema defining expected parameters
  4. execute - Async function that performs the action

Registering Tools

Register tools via the Plugin API:

Tool Options

boolean
default:false
Mark the tool as optional, requiring explicit allowlisting in agent config.
Then allowlist in config.json:
string
Override the tool name (useful for tool factories).
string[]
Register multiple names for the same tool (for tool factories that generate multiple tools).

TypeBox Schemas

OpenClaw uses @sinclair/typebox for tool input schemas. TypeBox generates JSON Schema and provides TypeScript type inference.

Basic Types

Arrays

Objects

Enums (String Literals)

Important: Do not use Type.Union with enum-like values. Use the stringEnum helper from the plugin SDK:
The stringEnum helper uses Type.Unsafe to generate a schema compatible with all LLM providers.

Nested Schemas

Tool Execution

The execute function receives validated parameters and returns a result:

Return Values

Tools should return an object with:
  • result - Status string ("success", "error", "pending", etc.)
  • details - Additional data (optional)
  • error - Error message (for failures)

Async Operations

Tool execution can be async:

Error Handling

Tool Context

Tools can access context via closures:

Tool Factories

Tool factories generate tools dynamically based on context:
Factories can return:
  • A single tool
  • An array of tools
  • null or undefined (to skip registration)

Example: HTTP Request Tool

Example: Database Query Tool

Tool Hooks

You can intercept tool calls with hooks:
See Hooks for details.

Best Practices

1. Clear Descriptions

Write clear, actionable descriptions that help the LLM understand when to use the tool:

2. Validate Input

Use TypeBox constraints to validate input:

3. Handle Errors Gracefully

Always catch errors and return structured error responses:

4. Use Optional Tools for Sensitive Operations

Mark destructive or sensitive tools as optional:

5. Log Tool Activity

Use the plugin logger for diagnostics:

Next Steps

  • Hooks - Intercept tool execution
  • Channels - Build channel integrations
  • Examples - Real-world plugin examples