Agent System Technical Reference
Complete technical reference for crocbot’s agent orchestration system. Covers configuration, system prompts, model selection, execution flow, sub-agents, memory, and tool policies.Table of Contents
- Architecture Overview
- Configuration Schema
- System Prompts
- Model Selection
- Execution Pipeline
- Sub-Agents
- Tool Policies
- Memory & Context
- Agent Types
- Key Functions Reference
- Extending the Agent System
Architecture Overview
Source File Map
Configuration Schema
Agent List (config.agents.list[])
Model Configuration
Agent Defaults (config.agents.defaults)
Agent Bindings (config.bindings[])
Routes channels/chats to specific agents:
JSON Config Example
System Prompts
Main System Prompt
File:src/agents/system-prompt.ts
Function: buildAgentSystemPrompt(params)
The system prompt is assembled from multiple sections based on promptMode:
Prompt Sections
Sub-Agent System Prompt
File:src/agents/subagent-announce.ts
Function: buildSubagentSystemPrompt(params)
Sub-agents get a minimal, task-focused prompt:
Injected Context Files
These files are loaded from the workspace and injected into the system prompt:Model Selection
Defaults
File:src/agents/defaults.ts
Resolution Hierarchy
File:src/agents/model-selection.ts
- Per-agent override:
config.agents.list[i].model.primary - Global default:
config.agents.defaults.model.primary - Fallback:
DEFAULT_MODELconstant
Model Reference Format
Model Aliases
Configure shortcuts inconfig.agents.defaults.models:
/model opus resolves to anthropic/claude-opus-4-5
Fallback Chain
File:src/agents/model-fallback.ts
When a model fails (auth error, rate limit, timeout), the system tries the next model in the fallback chain:
Auth Profile Store
File:src/agents/model-auth.ts
Location: ~/.crocbot/agents/{agentId}/auth-profiles.json
ensureAuthProfileStore(agentDir)- Load/create storeresolveAuthProfileOrder(params)- Determine profile evaluation ordermarkAuthProfileUsed(store, profileId)- Update last-used timestampmarkAuthProfileFailure(store, profileId, reason)- Mark failed with cooldownisProfileInCooldown(store, profileId)- Check cooldown statusgetApiKeyForModel(provider, modelId, store)- Retrieve API key
Execution Pipeline
Main Entry Point
File:src/agents/pi-embedded-runner/run.ts
Function: runEmbeddedPiAgent(params)
Execution Flow
Concurrency Control
File:src/agents/pi-embedded-runner/lanes.ts
Context Window Guard
File:src/agents/context-window-guard.ts
Compaction
File:src/agents/compaction.ts
When context overflows, old turns are summarized:
Sub-Agents
Spawning via sessions_spawn Tool
File: src/agents/tools/sessions-spawn-tool.ts
Spawn Flow
Sub-Agent Announce Flow
File:src/agents/subagent-announce.ts
When a sub-agent completes, results are announced to the requester:
Sub-Agent Registry
File:src/agents/subagent-registry.ts
Tool Policies
Default Sub-Agent Deny List
File:src/agents/pi-tools.policy.ts
Policy Resolution
Tool Filtering
Tool Groups
Expand viaexpandToolGroups():
Memory & Context
Session Transcript
Location:~/.crocbot/sessions/{sessionId}.jsonl
Each line is a JSON-serialized message:
Session Store
File:src/config/sessions.ts
Memory Search
File:src/agents/memory-search.ts
memory_search- Semantic search across MEMORY.md + memory/memory_get- Retrieve specific lines by path
Context Pruning
File:src/config/types.agent-defaults.ts
Agent Types
Main Agent
- Bound to channels via
config.bindings - Full system prompt (
promptMode: "full") - All tools available (subject to policy)
- Persistent across sessions
- Can spawn sub-agents
Sub-Agents
- Spawned by main agent via
sessions_spawn - Minimal system prompt (
promptMode: "minimal") - Reduced tool set (no session/admin/memory tools)
- Ephemeral (may be cleaned up after task)
- Cannot spawn further sub-agents
Cron/Isolated Agents
File:src/cron/isolated-agent/run.ts
- Triggered by cron scheduler
- Isolated session (
{agentId}:cron:{jobId}) - Scoped to agent workspace
CLI Agents
File:src/agents/cli-runner.ts
- Text-only fallback (no tools)
- Uses external CLI backends (e.g.,
claude-cli) - Configured via
config.agents.defaults.cliBackends
Key Functions Reference
Agent Configuration
System Prompts
Model Selection
Execution
Tool Policies
Sub-Agents
Extending the Agent System
Adding a New Agent Type
-
Define Config Type in
src/config/types.agents.ts: -
Add System Prompt Builder in
src/agents/: -
Create Execution Function:
Adding Custom Tool Policies
-
Define Policy in config:
-
Apply in Code:
Adding Model Providers
-
Register Provider in
src/agents/models-config.providers.ts: -
Add Auth Resolution in
src/agents/model-auth.ts -
Configure in JSON:
Modifying System Prompts
-
Add Section Builder in
src/agents/system-prompt.ts: -
Include in Main Builder:
Quick Reference
Environment Variables
File Locations
Config Paths
Last updated: 2026-02-01
