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
| Category | Files | Purpose |
|---|---|---|
| Config Types | src/config/types.agents.ts | AgentConfig, AgentsConfig, AgentBinding |
| Config Types | src/config/types.agent-defaults.ts | AgentDefaultsConfig, CliBackendConfig |
| Agent Scope | src/agents/agent-scope.ts | resolveAgentConfig(), resolveDefaultAgentId() |
| System Prompts | src/agents/system-prompt.ts | buildAgentSystemPrompt() |
| System Prompts | src/agents/subagent-announce.ts | buildSubagentSystemPrompt() |
| Model Selection | src/agents/model-selection.ts | resolveDefaultModelForAgent(), parseModelRef() |
| Model Fallback | src/agents/model-fallback.ts | runWithModelFallback() |
| Model Auth | src/agents/model-auth.ts | Auth profile store, API key resolution |
| Main Execution | src/agents/pi-embedded-runner/run.ts | runEmbeddedPiAgent() |
| Model Discovery | src/agents/pi-embedded-runner/model.ts | resolveModel() |
| Tool Policies | src/agents/pi-tools.policy.ts | resolveSubagentToolPolicy(), filterToolsByPolicy() |
| Defaults | src/agents/defaults.ts | DEFAULT_PROVIDER, DEFAULT_MODEL, DEFAULT_CONTEXT_TOKENS |
| Sub-Agent Spawn | src/agents/tools/sessions-spawn-tool.ts | createSessionsSpawnTool() |
| Sub-Agent Registry | src/agents/subagent-registry.ts | registerSubagentRun() |
| Context Guard | src/agents/context-window-guard.ts | evaluateContextWindowGuard() |
| Compaction | src/agents/compaction.ts | compactEmbeddedPiSessionDirect() |
| Cron Agent | src/cron/isolated-agent/run.ts | runCronIsolatedAgentTurn() |
| CLI Agent | src/agents/cli-runner.ts | runCliAgent() |
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:
| Mode | Description | Use Case |
|---|---|---|
"full" | All sections | Main agent |
"minimal" | Reduced sections (tooling, workspace, runtime) | Sub-agents |
"none" | Basic identity line only | Minimal contexts |
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:| File | Purpose |
|---|---|
SOUL.md | Agent persona and tone |
CLAUDE.md | Codebase instructions |
BOOTSTRAP.md | Auto-generated during onboarding |
MEMORY.md | Persistent memory notes |
HEARTBEAT.md | Heartbeat-specific instructions |
TOOLS.md | Tool usage guidance |
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():
| Group | Tools |
|---|---|
group:file | read, write, edit, ls, find |
group:exec | exec, process |
group:web | web_search, web_fetch, browser |
group:sessions | sessions_list, sessions_history, sessions_send, sessions_spawn |
group:admin | gateway, agents_list, cron |
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
| Function | File | Purpose |
|---|---|---|
resolveAgentConfig(cfg, agentId) | agent-scope.ts | Get config for specific agent |
resolveDefaultAgentId(cfg) | agent-scope.ts | Get default agent ID |
resolveAgentModelPrimary(cfg, agentId) | agent-scope.ts | Get agent’s primary model |
listAgentEntries(cfg) | agents.config.ts | List all agents |
applyAgentConfig(cfg, params) | agents.config.ts | Update agent config |
System Prompts
| Function | File | Purpose |
|---|---|---|
buildAgentSystemPrompt(params) | system-prompt.ts | Build main agent prompt |
buildSubagentSystemPrompt(params) | subagent-announce.ts | Build sub-agent prompt |
buildRuntimeLine(info) | system-prompt.ts | Build runtime info line |
Model Selection
| Function | File | Purpose |
|---|---|---|
resolveDefaultModelForAgent(params) | model-selection.ts | Get agent’s model |
parseModelRef(raw, defaultProvider) | model-selection.ts | Parse “provider/model” |
resolveModelRefFromString(params) | model-selection.ts | Resolve with alias lookup |
buildModelAliasIndex(params) | model-selection.ts | Build alias→ref map |
Execution
| Function | File | Purpose |
|---|---|---|
runEmbeddedPiAgent(params) | pi-embedded-runner/run.ts | Main execution entry |
runEmbeddedAttempt(params) | pi-embedded-runner/run/attempt.ts | Single run attempt |
resolveModel(provider, model, agentDir, cfg) | pi-embedded-runner/model.ts | Resolve model info |
evaluateContextWindowGuard(params) | context-window-guard.ts | Check context limits |
compactEmbeddedPiSessionDirect(params) | compaction.ts | Compact on overflow |
Tool Policies
| Function | File | Purpose |
|---|---|---|
resolveSubagentToolPolicy(cfg) | pi-tools.policy.ts | Get sub-agent policy |
filterToolsByPolicy(tools, policy) | pi-tools.policy.ts | Apply allow/deny |
resolveEffectiveToolPolicy(params) | pi-tools.policy.ts | Get effective policy |
isToolAllowedByPolicyName(name, policy) | pi-tools.policy.ts | Check single tool |
Sub-Agents
| Function | File | Purpose |
|---|---|---|
createSessionsSpawnTool(opts) | sessions-spawn-tool.ts | Create spawn tool |
registerSubagentRun(record) | subagent-registry.ts | Register sub-agent |
runSubagentAnnounceFlow(params) | subagent-announce.ts | Announce completion |
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
| Variable | Purpose |
|---|---|
ANTHROPIC_API_KEY | Anthropic API key |
OPENAI_API_KEY | OpenAI API key |
GOOGLE_API_KEY | Google AI API key |
BRAVE_API_KEY | Brave Search API key |
File Locations
| Path | Purpose |
|---|---|
~/.crocbot/crocbot.json | Main config |
~/.crocbot/agents/{agentId}/ | Per-agent state |
~/.crocbot/agents/{agentId}/auth-profiles.json | Auth profiles |
~/.crocbot/sessions/ | Session transcripts |
~/croc/ | Default workspace |
~/croc/SOUL.md | Agent persona |
~/croc/MEMORY.md | Persistent memory |
Config Paths
| Path | Type | Description |
|---|---|---|
agents.defaults.model.primary | string | Default model |
agents.defaults.model.fallbacks | string[] | Fallback chain |
agents.defaults.models.{key}.alias | string | Model alias |
agents.defaults.workspace | string | Default workspace |
agents.defaults.userTimezone | string | IANA timezone |
agents.defaults.maxConcurrent | number | Concurrency limit |
agents.defaults.subagents.maxConcurrent | number | Sub-agent concurrency |
agents.list[i].id | string | Agent ID |
agents.list[i].model | string/object | Per-agent model |
agents.list[i].tools.allow | string[] | Tool allowlist |
agents.list[i].tools.deny | string[] | Tool denylist |
bindings[i].agentId | string | Bound agent |
bindings[i].match.channel | string | Channel match |
Last updated: 2026-02-01
