What is an Agent?
An agent in PicoClaw is an autonomous AI assistant instance with its own:- Identity: Name, personality, and role
- Workspace: Isolated file storage and session history
- Model: LLM provider and fallback chain
- Tools: Available capabilities (filesystem, web, shell, etc.)
- Skills: Loaded skill packages
- Context: System prompt, memory, and conversation history
Agent Instance
Defined inpkg/agent/instance.go:
Agent Configuration
Default Agent
Every PicoClaw instance has a default agent configured inconfig.json:
| Field | Type | Default | Description |
|---|---|---|---|
workspace | string | ~/.picoclaw/workspace | Agent workspace directory |
model | string | - | Primary model name (must exist in model_list) |
max_tokens | int | 8192 | Maximum tokens per request |
temperature | float | 0.7 | Sampling temperature (0.0-1.0) |
max_tool_iterations | int | 20 | Max LLM→tool→LLM loops |
restrict_to_workspace | bool | true | Sandbox file/shell tools to workspace |
allow_read_outside_workspace | bool | false | Allow reading outside workspace |
model_fallbacks | []string | - | Fallback models (deprecated, use model_list) |
Multi-Agent Setup
Define multiple agents with different capabilities:| Field | Type | Description |
|---|---|---|
id | string | Unique agent identifier |
name | string | Display name |
default | bool | Mark as default agent |
workspace | string | Override default workspace |
model | object | Model config with primary/fallbacks |
skills | []string | Limit to specific skills (nil = all) |
subagents | object | Subagent spawn permissions |
Agent Workspace
Each agent has an isolated workspace directory:Workspace Files
AGENTS.md
Behavior guidelines and instructions for the agent.SOUL.md
Agent’s core personality, values, and communication style.IDENTITY.md
Agent’s role, name, and background.USER.md
User preferences, context, and historical information.TOOLS.md
Custom tool usage guidelines and examples.HEARTBEAT.md
Periodic tasks executed every 30 minutes (configurable):MEMORY.md
Long-term memory for facts, decisions, and important context.Agent Sessions
Conversations are tracked in session files:Session Manager
Manages conversation history and summarization:Session Key Routing
Session keys are derived from:- Channel + Peer:
telegram-123456(private chat) - Channel + Guild/Team:
discord-guild-789(server) - Agent ID:
agent:worker(agent-scoped) - Custom: Specified in API calls
Context Compression
When conversation history exceeds 75% ofmax_tokens, automatic summarization triggers:
- Keep last 4 messages for continuity
- Summarize older messages via LLM
- Replace history with summary + recent messages
- Save compressed session
- Drop oldest 50% of messages
- Append compression note to system prompt
- Retry request
Agent Context
The full context sent to the LLM consists of:1. System Prompt
Built byContextBuilder from workspace files:
2. Summary (if exists)
Condensed conversation history from previous summarization.3. History
Recent messages:4. Current User Message
The active request being processed.Agent Loop
The agent processing loop (pkg/agent/loop.go) handles:
- Message Routing: Route inbound messages to correct agent
- Context Building: Assemble system + history + user message
- LLM Iteration: Call LLM → Execute Tools → Repeat
- Session Management: Save history, trigger summarization
- Response Delivery: Send result via message bus
LLM Iteration Loop
max_tool_iterations is reached:
Subagents
Agents can spawn subagents for background tasks:Spawn Tool
- Independent context (no shared history)
- Access to all tools (message, web_search, etc.)
- Communicates results via
messagetool - Non-blocking (main agent continues)
Subagent Permissions
Control which agents can spawn which subagents:Agent Routing
Messages are routed to agents based on:- Channel: Different channels can use different agents
- Guild/Team ID: Discord servers, Telegram groups
- Peer: Direct messages vs. group chats
- Parent Peer: Reply threads
- Account ID: Multi-account support
Best Practices
1. Agent Specialization
Create agents for specific tasks:- Main: General assistance, scheduling, reminders
- Researcher: Web search, fact-checking, analysis
- Coder: Code generation, debugging, git operations
- Writer: Content creation, editing, summarization
2. Workspace Organization
Keep agent workspaces isolated:3. Model Selection
Choose models based on task:- Fast models (Groq, Cerebras): Quick responses, simple tasks
- Smart models (GPT-4, Claude): Complex reasoning, coding
- Cheap models (Gemini, DeepSeek): High-volume tasks
4. Fallback Configuration
Always configure fallbacks for reliability:5. Iteration Limits
Balance capability vs. cost:- Simple tasks: 5-10 iterations
- Complex tasks: 20-30 iterations
- Research tasks: 30-50 iterations
6. Context Management
Keep context files concise:- AGENTS.md: <500 words
- SOUL.md: <300 words
- IDENTITY.md: <200 words
- USER.md: <500 words