Skip to main content

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

  1. Architecture Overview
  2. Configuration Schema
  3. System Prompts
  4. Model Selection
  5. Execution Pipeline
  6. Sub-Agents
  7. Tool Policies
  8. Memory & Context
  9. Agent Types
  10. Key Functions Reference
  11. 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
  1. Per-agent override: config.agents.list[i].model.primary
  2. Global default: config.agents.defaults.model.primary
  3. Fallback: DEFAULT_MODEL constant

Model Reference Format

Model Aliases

Configure shortcuts in config.agents.defaults.models:
Usage: /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
Key Functions:
  • ensureAuthProfileStore(agentDir) - Load/create store
  • resolveAuthProfileOrder(params) - Determine profile evaluation order
  • markAuthProfileUsed(store, profileId) - Update last-used timestamp
  • markAuthProfileFailure(store, profileId, reason) - Mark failed with cooldown
  • isProfileInCooldown(store, profileId) - Check cooldown status
  • getApiKeyForModel(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 via expandToolGroups():

Memory & Context

Session Transcript

Location: ~/.crocbot/sessions/{sessionId}.jsonl Each line is a JSON-serialized message:

Session Store

File: src/config/sessions.ts
File: src/agents/memory-search.ts
Tools:
  • 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

  1. Define Config Type in src/config/types.agents.ts:
  2. Add System Prompt Builder in src/agents/:
  3. Create Execution Function:

Adding Custom Tool Policies

  1. Define Policy in config:
  2. Apply in Code:

Adding Model Providers

  1. Register Provider in src/agents/models-config.providers.ts:
  2. Add Auth Resolution in src/agents/model-auth.ts
  3. Configure in JSON:

Modifying System Prompts

  1. Add Section Builder in src/agents/system-prompt.ts:
  2. Include in Main Builder:

Quick Reference

Environment Variables

File Locations

Config Paths


Last updated: 2026-02-01