{"repo": "adolfousier/opencrabs.com", "files": {"docs/book/features/multi-agent.html": {"efb1d5504338f9e52945c85c2e47d2a3cdaed1f1": {"t": 1786068556.958938, "n": 37278, "h": "77d786aed0650c1a", "c": "\n\n \n \n \n Multi-Agent Orchestration - OpenCrabs\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n \n \n \n\n \n \n \n\n \n \n \n \n \n \n\n \n \n\n \n \n \n \n\n \n \n\n\n \n \n \n \n \n \n
\n
\n

Keyboard shortcuts

\n
\n

Press ← or → to navigate between chapters

\n

Press S or / to search in the book

\n

Press ? to show this help

\n

Press Esc to hide this help

\n
\n
\n
\n
\n \n \n\n \n \n\n \n\n \n \n\n \n\n
\n\n
\n
\n
\n
\n \n \n
    \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
\n \n
\n\n

OpenCrabs

\n\n
\n \n \n \n \n \n \n\n
\n
\n\n
\n
\n
\n \n
\n \n
\n
\n
\n
\n
\n
    \n
\n
\n
\n\n \n \n\n
\n
\n

Multi-Agent Orchestration

\n

OpenCrabs supports spawning specialized sub-agents that run autonomously in isolated sessions. Each child agent gets its own context, tool registry, and cancel token. Introduced in v0.2.97 with a typed agent system and team orchestration.

\n

Agent Types

\n

When spawning an agent, an agent_type parameter selects a specialized role with a curated tool set:

\n
\n\n\n\n\n\n\n\n\n\n\n\n
TypeRoleTools
generalFull-capability agent (default)All parent tools minus recursive/dangerous
exploreFast codebase navigation (read-only)read_file, glob, grep, ls
planArchitecture planning (read + analysis)read_file, glob, grep, ls, bash
codeImplementation (full write access)All parent tools minus recursive/dangerous
researchWeb search + documentation lookupread_file, glob, grep, ls, web_search, http_request
\n
\n

Each type receives a role-specific system prompt that shapes its behavior. Explore agents are fast and lightweight – they only read files. Code agents can modify anything. Research agents can search the web but not touch your filesystem.

\n

Safety: ALWAYS_EXCLUDED Tools

\n

No agent type has access to these tools, preventing dangerous or recursive operations:

\n
    \n
  • spawn_agent – no spawning agents from agents
  • \n
  • resume_agent, wait_agent, send_input, close_agent – no managing siblings
  • \n
  • rebuild – no building from source
  • \n
  • evolve – no self-updating
  • \n
\n

Five Orchestration Tools

\n
\n\n\n\n\n\n\n\n\n\n\n\n
ToolDescription
spawn_agentCreate a typed child agent to handle a sub-task autonomously in the background
wait_agentWait for a spawned agent to complete and return its output (configurable timeout)
send_inputSend follow-up instructions to a running agent (multi-turn conversation)
close_agentTerminate a running agent and clean up its resources
resume_agentResume a completed or failed agent with a new prompt (preserves prior context)
\n
\n

Spawn an Agent

\n
spawn_agent(\n  label: \"refactor-auth\",      # Human-readable label\n  agent_type: \"code\",          # general | explore | plan | code | research\n  prompt: \"Refactor auth...\"   # Task instruction\n)\n
\n

The agent runs in its own session with auto-approved tools. No blocking – it executes in the background while the parent continues.

\n

Wait for Completion

\n
wait_agent(\n  agent_id: \"abc-123\",\n  timeout_secs: 300            # Max wait time (default: 300s)\n)\n
\n

Multi-Turn with send_input

\n

After spawning, you can send additional instructions without restarting:

\n
send_input(\n  agent_id: \"abc-123\",\n  text: \"Also add unit tests for the new module\"\n)\n
\n

The child agent processes the input on its next iteration. This enables iterative workflows – review the agent’s output, then ask it to refine or continue.

\n

Resume a Completed Agent

\n
resume_agent(\n  agent_id: \"abc-123\",\n  prompt: \"Now port the same changes to the other two files\"\n)\n
\n

The agent continues in its original session, preserving all prior context. No need to re-explain the codebase.

\n

Team Orchestration

\n

The TeamManager coordinates named groups of agents for parallel execution. Three team-specific tools:

\n

Create a Team

\n
team_create(\n  team_name: \"backend-refactor\",\n  agents: [\n    { label: \"auth\", agent_type: \"code\", prompt: \"Refactor auth module\" },\n    { label: \"tests\", agent_type: \"code\", prompt: \"Write tests for auth\" },\n    { label: \"docs\", agent_type: \"general\", prompt: \"Update documentation\" }\n  ]\n)\n
\n

All agents spawn simultaneously and run in parallel. Returns the team name and all agent IDs.

\n

Broadcast to a Team

\n
team_broadcast(\n  team_name: \"backend-refactor\",\n  message: \"Use the new AuthError enum instead of plain strings\"\n)\n
\n

Sends a message to all running agents in the team. Non-running agents are skipped. Useful for sharing context or direction changes.

\n

Delete a Team

\n
team_delete(team_name: \"backend-refactor\")\n
\n

Cancels all running agents and cleans up resources. Completed agents are left in the subagent manager for reference.

\n

Subagent Provider/Model Config

\n

By default, every spawned agent inherits the parent session’s provider and model. You can override this globally in config.toml so child agents route to a different (usually cheaper or faster) backend:

\n
[agent]\nsubagent_provider = \"openrouter\"   # Provider for child agents\nsubagent_model    = \"qwen/qwen3-235b\" # Model override\n\n# Omit both keys and child agents inherit the parent session's provider\n# and run on that provider's default model.\n
\n

The override applies to spawn_agent, resume_agent, and every member of a team_create team. Changes take effect on next session start; running sessions keep their existing provider.

\n

Per-Call Overrides (v0.3.35)

\n

spawn_agent, resume_agent, and team_create now accept optional provider and model fields that override config defaults for a single call. This enables mixed-model teams:

\n
team_create(\n  team_name: \"mixed-stack\",\n  agents: [\n    { label: \"planner\", provider: \"zhipu\", model: \"glm-5\", prompt: \"Architect the feature\" },\n    { label: \"coder\", provider: \"deepseek\", model: \"deepseek-coder\", prompt: \"Implement it\" },\n    { label: \"reviewer\", provider: \"kimi\", model: \"kimi-k2.5\", prompt: \"Review the code\" }\n  ]\n)\n
\n

Precedence order (highest first): per-call provider/model > [agent] subagent_provider/subagent_model in config > parent session’s provider.

\n

Why It Matters

\n

The common pattern is premium parent, cheap children. Your main conversation stays on a reasoning-capable model (Opus, GPT-5, Gemini 2.5 Pro) while subtasks — file exploration, test writing, web research, bulk refactors — run on a faster, cheaper model. With a 4-agent team running 10 minutes each, the cost delta between Opus and Qwen on the children is roughly 50x.

\n

Concrete Examples

\n

OpenRouter parent, Qwen children — best bang-for-buck on mixed workloads:

\n
[providers.openrouter]\nenabled = true\napi_key = \"sk-or-...\"\nmodel = \"anthropic/claude-opus-4\"\n\n[agent]\nsubagent_provider = \"openrouter\"\nsubagent_model    = \"qwen/qwen3-235b-a22b-instruct\"\n
\n

Kimi on custom OpenCode provider — fast code generation for code and explore agents:

\n
[providers.opencode-kimi]\nenabled = true\nbase_url = \"https://api.kimi.com/v1\"\napi_key  = \"...\"\nmodel    = \"kimi-k2.5\"\n\n[agent]\nsubagent_provider = \"opencode-kimi\"\nsubagent_model    = \"kimi-k2.6\"\n
\n

Local Ollama children — zero cost, fully offline, good for explore agents that just read files:

\n
[providers.ollama]\nenabled = true\nmodel = \"qwen3:14b\"\n\n[agent]\nsubagent_provider = \"ollama\"\nsubagent_model    = \"qwen3:14b\"\n
\n

Gemini parent, Gemini Flash children — single billing account, reasoning on main, flash on team:

\n
[providers.gemini]\nenabled = true\nmodel = \"gemini-2.5-pro\"\n\n[agent]\nsubagent_provider = \"gemini\"\nsubagent_model    = \"gemini-2.5-flash\"\n
\n

Gotchas

\n
    \n
  • The subagent provider must be enabled and have a valid API key (or be a CLI/none-auth provider). Missing keys cause the spawn to fail with a provider resolution error.
  • \n
  • subagent_model must be a model the provider actually serves. qwen/qwen3-235b works on OpenRouter, not on Anthropic. Check /models on the target provider to confirm.
  • \n
  • team_create members all share the same subagent config. If you need heterogeneous routing (e.g. a research agent on web-search model, a code agent on code-specialized model), spawn them individually with spawn_agent under different config profiles.
  • \n
  • The CLI model override is surfaced in the spawn_agent, resume_agent, and team_create tool descriptions themselves, so the LLM knows to mention these keys to you instead of inventing per-call overrides.
  • \n
\n

If subagent_provider or subagent_model is not set, the spawned agent loads from the parent session’s provider and runs on that provider’s default model.

\n

Workflow Patterns

\n

Parallel Research + Implementation

\n
team_create(\"feature-research\", [\n  { label: \"research\", agent_type: \"research\", prompt: \"Find best practices for rate limiting in Rust\" },\n  { label: \"explore\", agent_type: \"explore\", prompt: \"Find all middleware files in the codebase\" }\n])\n
\n

Wait for results, then spawn a code agent with the combined context.

\n

Iterative Code Review

\n
# 1. Spawn a code agent\nspawn_agent(label: \"impl\", agent_type: \"code\", prompt: \"Implement rate limiting middleware\")\n\n# 2. Wait for completion\nwait_agent(agent_id: \"impl-id\")\n\n# 3. Resume with refinements\nresume_agent(agent_id: \"impl-id\", prompt: \"Add tests for the edge cases we discussed\")\n
\n

Large-Scale Refactoring

\n
team_create(\"refactor-team\", [\n  { label: \"module-a\", agent_type: \"code\", prompt: \"Refactor module A to use the new trait\" },\n  { label: \"module-b\", agent_type: \"code\", prompt: \"Refactor module B to use the new trait\" },\n  { label: \"module-c\", agent_type: \"code\", prompt: \"Refactor module C to use the new trait\" },\n  { label: \"tests\", agent_type: \"code\", prompt: \"Update all tests for the new trait signature\" }\n])\n
\n

Testing

\n

84 tests cover the entire multi-agent system:

\n
    \n
  • Manager state machine (spawn, wait, close lifecycle)
  • \n
  • SendInput wiring and input loop
  • \n
  • CloseAgent cleanup
  • \n
  • WaitAgent timeout behavior
  • \n
  • AgentType tool filtering
  • \n
  • TeamManager, TeamDelete, TeamBroadcast
  • \n
  • Registry exclusion (ALWAYS_EXCLUDED enforcement)
  • \n
\n\n
\n\n \n
\n
\n\n \n\n
\n\n \n \n \n \n \n\n\n\n \n\n\n \n \n \n\n \n \n \n\n \n \n\n\n\n
\n \n\n"}}}}