Skip to main content

Overview

Tools extend agent capabilities by providing interfaces to external systems, APIs, and operations. PicoClaw’s tool system is designed for safety, extensibility, and minimal overhead.

Tool Interface

All tools implement the Tool interface (pkg/tools/types.go):

Optional Interfaces

ContextualTool

Tools that need channel/chat context:
Examples: message, spawn, cron

AsyncTool

Tools that run in background:
Examples: spawn

Tool Registry

Central registry for all available tools (pkg/tools/registry.go):
Features:
  • Thread-safe registration and execution
  • Automatic conversion to LLM tool definitions
  • Deterministic ordering (sorted alphabetically) for cache stability
  • Context injection for contextual tools
  • Async callback support

Available Tools

Filesystem Tools

read_file

Read file contents. Parameters:
Restrictions:
  • Restricted to workspace if restrict_to_workspace: true
  • Respects allow_read_paths patterns
  • Symlink escape prevention
Implementation: pkg/tools/filesystem.go

write_file

Write content to file. Parameters:
Features:
  • Atomic write with sync (flash-safe)
  • Creates parent directories automatically
  • Uses secure permissions (0o600)
Restrictions:
  • Restricted to workspace if restrict_to_workspace: true
  • Respects allow_write_paths patterns

list_dir

List directory contents. Parameters:
Returns:

edit_file

Search and replace in files. Parameters:
Implementation: pkg/tools/edit.go

append_file

Append content to file. Parameters:

Shell Tools

exec

Execute shell commands with safety guards. Parameters:
Safety Features:
  1. Dangerous Pattern Blocking:
    • rm -rf, del /f, rmdir /s
    • format, mkfs, diskpart
    • dd if=, writes to /dev/sd*
    • shutdown, reboot, poweroff
    • Fork bombs
    • Command substitution ($(...), `...`)
    • Pipe to shell (| sh, | bash)
    • sudo, chmod, chown
    • Package managers (apt, yum, npm -g)
    • docker run/exec
    • git push/force
    • eval, source
  2. Workspace Restriction:
    • Absolute paths validated against workspace
    • Path traversal blocked (../)
    • Safe paths allowed (/dev/null, /dev/urandom, etc.)
  3. Custom Patterns:
  4. Timeout: Default 60s, configurable
Implementation: pkg/tools/shell.go Security Notes:
  • Even with restrict_to_workspace: false, dangerous commands are blocked
  • Use custom_allow_patterns to override specific blocks

Web Tools

Search the web for information. Parameters:
Supported Providers (priority order):
  1. Perplexity (LLM-enhanced search)
  2. Brave Search (fast, high-quality)
  3. Tavily (AI-optimized)
  4. DuckDuckGo (free, no API key)
Configuration:
Returns:
Implementation: pkg/tools/web.go

web_fetch

Fetch and extract content from URLs. Parameters:
Features:
  • HTML to text conversion
  • JSON formatting
  • Redirect following (max 5)
  • Size limit (default 10MB)
  • Timeout: 60s
Returns:

Communication Tools

message

Send message to user on a chat channel. Parameters:
Use Cases:
  • Subagent → User communication
  • Multi-channel messaging
  • Background task notifications
Behavior:
  • Returns Silent: true (user already received message)
  • Tracks sends per round to prevent duplicates
Implementation: pkg/tools/message.go

Scheduling Tools

cron

Schedule reminders, tasks, or commands. Actions:
add
Create new scheduled task. One-time reminder:
Recurring task:
Cron expression:
Shell command:
list
List all scheduled jobs.
remove
Delete a job.
enable/disable
Toggle job execution.
Job Execution:
  • deliver: true: Send message directly to channel
  • deliver: false: Process through agent (for complex tasks)
  • command: Execute shell command, report output
Implementation: pkg/tools/cron.go

Agent Spawning Tools

spawn

Spawn subagent for background tasks. Parameters:
Behavior:
  • Creates independent subagent with fresh context
  • Subagent has access to all tools (message, web, etc.)
  • Non-blocking (main agent continues)
  • Subagent communicates via message tool
Permissions: Controlled via subagents.allowlist config:
Use Cases:
  • Long-running research tasks
  • Web scraping and analysis
  • Background monitoring
  • Parallel task execution
Implementation: pkg/tools/spawn.go

Hardware Tools (Linux only)

i2c

I2C bus communication. Parameters:
Availability: Linux only, returns error on other platforms Implementation: pkg/tools/i2c.go

spi

SPI bus communication. Parameters:
Availability: Linux only Implementation: pkg/tools/spi.go

Skill Management Tools

find_skills

Search skill registries. Parameters:
Implementation: pkg/tools/skills_search.go

install_skill

Install skill from registry. Parameters:
Implementation: pkg/tools/skills_install.go

MCP Tools

Dynamic tools loaded from MCP (Model Context Protocol) servers. Configuration:
Features:
  • Auto-registers tools from connected MCP servers
  • Tool names prefixed with server name (e.g., filesystem_read)
  • Supports all MCP tool types
Implementation: pkg/tools/mcp_tool.go

Tool Execution Flow

Tool Safety

Workspace Sandboxing

When restrict_to_workspace: true (default): File Tools:
  • All paths resolved relative to workspace
  • Absolute paths validated
  • Symlink escape prevention
  • Path traversal blocked
Shell Tool:
  • Absolute paths in commands validated
  • Workspace boundary enforced
  • Dangerous commands blocked
Example:

Path Whitelisting

Allow specific paths outside workspace:
Pattern Syntax: Regular expressions

Exec Safety Guards

Multi-layer protection for shell commands:
  1. Deny Patterns: Block dangerous commands
  2. Allow Patterns: Override blocks for specific cases
  3. Workspace Restriction: Path validation
  4. Timeout: Prevent infinite execution
Disable All Deny Patterns (dangerous):

Tool Result Patterns

Standard Result

Silent Result

Error Result

Async Result

Media Result

Creating Custom Tools

1. Implement Tool Interface

2. Register Tool

Modify pkg/agent/loop.go:

3. Rebuild and Test

Best Practices

1. Tool Naming

  • Use lowercase with underscores: read_file, web_search
  • Be descriptive and action-oriented
  • Avoid conflicts with existing tools

2. Parameter Validation

  • Always validate required parameters
  • Provide clear error messages
  • Use JSON Schema for type safety

3. Error Handling

  • Return ErrorResult() for user-facing errors
  • Include original error in Err field
  • Keep error messages concise and actionable

4. Performance

  • Set appropriate timeouts
  • Avoid blocking operations in Execute()
  • Use Async pattern for long tasks

5. Security

  • Validate all user inputs
  • Sanitize file paths
  • Use workspace restrictions
  • Follow principle of least privilege