Overview
PicoClaw is an ultra-lightweight AI assistant CLI tool written in Go, designed to run on minimal hardware (<10MB RAM) while providing full-featured AI agent capabilities. The architecture prioritizes efficiency, simplicity, and modularity.Core Components
1. Agent System
The agent system forms the heart of PicoClaw, responsible for managing AI interactions and tool execution.AgentInstance (pkg/agent/instance.go)
Each agent is represented by an AgentInstance struct:
- Independent workspace per agent
- Configurable model fallback chain
- Isolated session management
- Tool registry with sandboxing
- Skill-based capability filtering
AgentLoop (pkg/agent/loop.go)
The main processing loop that handles message routing and LLM interactions:
- Message routing based on channel/peer/guild
- Tool call execution with context injection
- Automatic context compression on overflow
- Fallback chain for provider resilience
- Async tool support for long-running tasks
2. Provider System
Providers abstract LLM API interactions, supporting multiple backends.Provider Interface (pkg/providers/types.go)
Supported Providers
- HTTP-compatible: OpenAI, Anthropic, Zhipu, DeepSeek, Gemini, Groq, Moonshot, Qwen, NVIDIA, Ollama, OpenRouter, LiteLLM, VLLM, Cerebras
- OAuth/Token: Codex CLI, Claude CLI
- gRPC: GitHub Copilot
Fallback Chain
Automatic failover across models/providers:auth: Retry next candidaterate_limit: Retry next candidate with cooldownbilling: Retry next candidatetimeout: Retry same or next candidateformat: Skip (not retriable)overloaded: Retry next candidate
3. Tool System
Tools extend agent capabilities through a unified interface.Tool Registry (pkg/tools/registry.go)
- Filesystem:
read_file,write_file,list_dir,edit_file,append_file - Shell:
exec(with safety guards) - Web:
web_search,web_fetch - Communication:
message(send to channels) - Scheduling:
cron(reminders, recurring tasks) - Agent Spawning:
spawn(background tasks) - Hardware:
i2c,spi(Linux only) - Skills:
find_skills,install_skill - MCP: Dynamic tools from MCP servers
4. Session Management
Conversation history and context management.Session Structure
- Per-channel conversation isolation
- Automatic summarization when context exceeds threshold
- Emergency compression on context overflow
- Message history with role (user/assistant/tool)
5. Message Bus
Asynchronous communication between components.Bus Architecture
InboundMessage: User → AgentOutboundMessage: Agent → UserOutboundMediaMessage: Media attachments
6. Context Building
System prompt and message assembly.Context Builder (pkg/agent/context.go)
Builds the full message array for LLM:
- System Prompt: AGENTS.md + SOUL.md + IDENTITY.md + USER.md + skills + tool descriptions
- Summary: Condensed conversation history (if exists)
- History: Recent messages
- User Message: Current input
AGENTS.md: Agent behavior guideSOUL.md: Agent personality/valuesIDENTITY.md: Agent identity/roleUSER.md: User preferencesTOOLS.md: Tool usage guidelinesHEARTBEAT.md: Periodic tasksMEMORY.md: Long-term memory
Data Flow
Complete Request Flow
Security Architecture
Sandbox Protection
All file and command operations are restricted to the configured workspace by default. Workspace Restriction:read_file,write_file,list_dir: Restricted to workspaceexec: Command paths validated, dangerous patterns blockededit_file,append_file: Restricted to workspace
- Path traversal prevention (
../blocked) - Symlink escape prevention
- Dangerous command blocking (rm -rf, format, shutdown, etc.)
- Absolute path validation
Path Whitelisting
Optional allowlist for specific paths outside workspace:Memory Optimization
PicoClaw achieves <10MB RAM through:- No runtime dependencies: Single static binary
- Efficient data structures: Minimal allocations
- Streaming processing: No large buffers
- Lazy loading: Skills loaded on demand
- Context compression: Automatic history summarization
- Go’s efficiency: Native compilation, small runtime
Concurrency Model
- Message processing: Single goroutine per agent loop
- Tool execution: Synchronous with context timeout
- Async tools: Spawn tool creates independent subagent goroutines
- Heartbeat: Separate goroutine for periodic tasks
- Summarization: Background goroutine when threshold exceeded
Configuration System
Hierarchical configuration with environment variable overrides:- Config:
~/.picoclaw/config.jsonor$PICOCLAW_CONFIG - Home:
~/.picoclawor$PICOCLAW_HOME - Workspace:
~/.picoclaw/workspace(configurable per agent)
Extension Points
Adding New Providers
- Implement
LLMProviderinterface - Add to
resolveProviderSelection()inpkg/providers/factory.go - Add config structure in
pkg/config/config.go
Adding New Tools
- Implement
Toolinterface: - Register in
registerSharedTools()inpkg/agent/loop.go
Adding New Channels
- Implement channel handler (see
pkg/channels/) - Connect to
MessageBus - Add config in
channelssection
Performance Characteristics
- Startup time: <1s on 0.6GHz single core
- Memory footprint: <10MB baseline (may increase to 10-20MB with recent features)
- Context compression: Automatic at 75% of max tokens
- LLM caching: Provider-specific prompt caching support
- Tool execution: Timeout configurable, default 60s