Skip to main content

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 in pkg/agent/instance.go:

Agent Configuration

Default Agent

Every PicoClaw instance has a default agent configured in config.json:
Configuration Fields:

Multi-Agent Setup

Define multiple agents with different capabilities:
Agent-Specific Fields:

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:
  1. Channel + Peer: telegram-123456 (private chat)
  2. Channel + Guild/Team: discord-guild-789 (server)
  3. Agent ID: agent:worker (agent-scoped)
  4. Custom: Specified in API calls

Context Compression

When conversation history exceeds 75% of max_tokens, automatic summarization triggers:
  1. Keep last 4 messages for continuity
  2. Summarize older messages via LLM
  3. Replace history with summary + recent messages
  4. Save compressed session
Emergency Compression: If LLM returns “context_length_exceeded” error:
  1. Drop oldest 50% of messages
  2. Append compression note to system prompt
  3. Retry request

Agent Context

The full context sent to the LLM consists of:

1. System Prompt

Built by ContextBuilder 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:
  1. Message Routing: Route inbound messages to correct agent
  2. Context Building: Assemble system + history + user message
  3. LLM Iteration: Call LLM → Execute Tools → Repeat
  4. Session Management: Save history, trigger summarization
  5. Response Delivery: Send result via message bus

LLM Iteration Loop

Iteration Limit: Prevents infinite loops. If max_tool_iterations is reached:

Subagents

Agents can spawn subagents for background tasks:

Spawn Tool

Subagent Features:
  • Independent context (no shared history)
  • Access to all tools (message, web_search, etc.)
  • Communicates results via message tool
  • Non-blocking (main agent continues)

Subagent Permissions

Control which agents can spawn which subagents:

Agent Routing

Messages are routed to agents based on:
  1. Channel: Different channels can use different agents
  2. Guild/Team ID: Discord servers, Telegram groups
  3. Peer: Direct messages vs. group chats
  4. Parent Peer: Reply threads
  5. Account ID: Multi-account support
Example routing config:

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