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 theTool interface (pkg/tools/types.go):
Optional Interfaces
ContextualTool
Tools that need channel/chat context:message, spawn, cron
AsyncTool
Tools that run in background:spawn
Tool Registry
Central registry for all available tools (pkg/tools/registry.go):
- 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:- Restricted to workspace if
restrict_to_workspace: true - Respects
allow_read_pathspatterns - Symlink escape prevention
pkg/tools/filesystem.go
write_file
Write content to file. Parameters:- Atomic write with sync (flash-safe)
- Creates parent directories automatically
- Uses secure permissions (0o600)
- Restricted to workspace if
restrict_to_workspace: true - Respects
allow_write_pathspatterns
list_dir
List directory contents. Parameters:edit_file
Search and replace in files. Parameters:pkg/tools/edit.go
append_file
Append content to file. Parameters:Shell Tools
exec
Execute shell commands with safety guards. Parameters:-
Dangerous Pattern Blocking:
rm -rf,del /f,rmdir /sformat,mkfs,diskpartdd 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/execgit push/forceeval,source
-
Workspace Restriction:
- Absolute paths validated against workspace
- Path traversal blocked (
../) - Safe paths allowed (
/dev/null,/dev/urandom, etc.)
-
Custom Patterns:
- Timeout: Default 60s, configurable
pkg/tools/shell.go
Security Notes:
- Even with
restrict_to_workspace: false, dangerous commands are blocked - Use
custom_allow_patternsto override specific blocks
Web Tools
web_search
Search the web for information. Parameters:- Perplexity (LLM-enhanced search)
- Brave Search (fast, high-quality)
- Tavily (AI-optimized)
- DuckDuckGo (free, no API key)
pkg/tools/web.go
web_fetch
Fetch and extract content from URLs. Parameters:- HTML to text conversion
- JSON formatting
- Redirect following (max 5)
- Size limit (default 10MB)
- Timeout: 60s
Communication Tools
message
Send message to user on a chat channel. Parameters:- Subagent → User communication
- Multi-channel messaging
- Background task notifications
- Returns
Silent: true(user already received message) - Tracks sends per round to prevent duplicates
pkg/tools/message.go
Scheduling Tools
cron
Schedule reminders, tasks, or commands. Actions:add
Create new scheduled task. One-time reminder:list
List all scheduled jobs.remove
Delete a job.enable/disable
Toggle job execution.deliver: true: Send message directly to channeldeliver: false: Process through agent (for complex tasks)command: Execute shell command, report output
pkg/tools/cron.go
Agent Spawning Tools
spawn
Spawn subagent for background tasks. Parameters:- Creates independent subagent with fresh context
- Subagent has access to all tools (message, web, etc.)
- Non-blocking (main agent continues)
- Subagent communicates via
messagetool
subagents.allowlist config:
- Long-running research tasks
- Web scraping and analysis
- Background monitoring
- Parallel task execution
pkg/tools/spawn.go
Hardware Tools (Linux only)
i2c
I2C bus communication. Parameters:pkg/tools/i2c.go
spi
SPI bus communication. Parameters:pkg/tools/spi.go
Skill Management Tools
find_skills
Search skill registries. Parameters:pkg/tools/skills_search.go
install_skill
Install skill from registry. Parameters:pkg/tools/skills_install.go
MCP Tools
Dynamic tools loaded from MCP (Model Context Protocol) servers. Configuration:- Auto-registers tools from connected MCP servers
- Tool names prefixed with server name (e.g.,
filesystem_read) - Supports all MCP tool types
pkg/tools/mcp_tool.go
Tool Execution Flow
Tool Safety
Workspace Sandboxing
Whenrestrict_to_workspace: true (default):
File Tools:
- All paths resolved relative to workspace
- Absolute paths validated
- Symlink escape prevention
- Path traversal blocked
- Absolute paths in commands validated
- Workspace boundary enforced
- Dangerous commands blocked
Path Whitelisting
Allow specific paths outside workspace:Exec Safety Guards
Multi-layer protection for shell commands:- Deny Patterns: Block dangerous commands
- Allow Patterns: Override blocks for specific cases
- Workspace Restriction: Path validation
- Timeout: Prevent infinite execution
Tool Result Patterns
Standard Result
Silent Result
Error Result
Async Result
Media Result
Creating Custom Tools
1. Implement Tool Interface
2. Register Tool
Modifypkg/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
Errfield - 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