Multi-Agent Task Orchestration for LLMs
Navigate: Space / Arrow Keys | Fullscreen: F | Overview: O
One LLM instance handling everything:
Works great for focused tasks. Hits limits on large projects.
Specialized agents with focused responsibilities:
Smaller contexts. Parallel execution. Specialized focus.
LLMs operate in a turn-based execution model, similar to a game of chess or a D&D session.
White moves → Black moves → White moves...
You can't move while opponent is thinking
Player declares action → DM resolves → Next turn...
You act, then wait for the world to respond
Each cycle is one turn. The LLM is blocked while tools execute.
↓ scroll down for details ↓
To prevent runaway agents and control costs, Captain enforces max turns per task:
| Agent Type | Default Max Turns | Typical Use |
|---|---|---|
| Planner | 30-35 | Deep codebase exploration, task decomposition |
| Worker | 50 | Implementation, testing, iteration |
| Validator | 10-15 | Code review, merge conflict resolution |
When an agent hits max turns, it doesn't fail - it saves its session ID and requeues the task. On next attempt, it resumes with full conversation history intact.
if (err instanceof MaxTurnsError) {
await taskQueue.updateMetadata(task.id, {
resumeSessionId: err.sessionId, // Claude SDK session
lastTurnsUsed: err.turnsUsed,
});
await taskQueue.requeue(task.id, "max_turns", 5);
}
Captain orchestrates four specialized agent types, each with distinct responsibilities:
↓ scroll down for each agent ↓
The entry point for all user requests. Receives high-level tasks and creates the initial epic for planning.
# User submits task
captain add "Add user authentication"
# Coordinator creates epic
{
id: "task-abc123",
type: "epic",
title: "Add user authentication",
status: "pending",
priority: 2
}
The architect that researches the codebase and decomposes epics into concrete, implementable tasks.
{
"tasks": [
{
"title": "Create User model",
"type": "task",
"group": "auth-models",
"acceptance": "User model with email, hash"
},
{
"title": "Add JWT middleware",
"depends_on": ["Create User model"],
"group": "auth-middleware"
},
{
"title": "Create login endpoint",
"depends_on": ["Add JWT middleware"]
}
]
}
The implementation engine. Multiple workers run in parallel, each in an isolated git worktree.
groupId - they're claimed together by the same worker and batch-validated.
.captain/
├── worktrees/
│ ├── worker-0/ # Full repo checkout
│ │ └── src/
│ ├── worker-1/ # Full repo checkout
│ │ └── src/
│ └── worker-2/ # Full repo checkout
│ └── src/
└── session-state/
Each worker has complete isolation. No file conflicts. Parallel edits.
The quality guardian. Reviews completed work, handles merges, and extracts learnings.
{
"decision": "approve",
"reasoning": "Implementation matches spec...",
"discoveries": [
{
"type": "pattern",
"content": "Auth middleware uses...",
"files": ["src/middleware/auth.ts"]
}
],
"suggestions": []
}
↓ scroll down for detailed data flow ↓
The planner creates a dependency graph. Tasks execute in parallel when their blockers are resolved.
↓ scroll down for details ↓
{
"tasks": [
{
"id": "A",
"title": "Create Schema",
"depends_on": []
},
{
"id": "B",
"title": "User Model",
"depends_on": ["A"],
"group": "models"
},
{
"id": "C",
"title": "Auth Service",
"depends_on": ["A"],
"group": "auth"
},
{
"id": "D",
"title": "Login Endpoint",
"depends_on": ["B", "C"]
}
]
}
group are claimed together, share contextBeads provides persistent issue tracking that survives conversation compaction and context resets.
.beads/issues.jsonlbackend, auth↓ scroll down for workflow details ↓
# Captain creates a task with labels
captain add "Implement user authentication" --labels=backend,security
# Beads issue is created automatically with full metadata
bd show captain-42
# Output:
# ┌─────────────────────────────────────────────────────────────┐
# │ captain-42: Implement user authentication │
# ├─────────────────────────────────────────────────────────────┤
# │ Status: in_progress │
# │ Type: epic │
# │ Priority: P2 (medium) │
# │ Labels: backend, security │
# │ Created: 2024-01-15 10:30:00 │
# │ │
# │ Blocks: captain-50, captain-51 (downstream tasks) │
# │ Subtasks: captain-43, captain-44, captain-45 │
# └─────────────────────────────────────────────────────────────┘
# View all issues with dependency tree
bd list --all --pretty
# Output with visual dependency graph:
# ┌──────────────────────────────────────────────────────────────────────────────┐
# │ ID Status Title Labels │
# ├──────────────────────────────────────────────────────────────────────────────┤
# │ captain-42 in_progress Implement user authentication backend │
# │ ├─ captain-43 done Create User model backend,db │
# │ ├─ captain-44 done Add password hashing backend │
# │ ├─ captain-45 working Implement JWT middleware backend,auth │
# │ │ └─ captain-46 blocked Create login endpoint backend,api │
# │ │ └─ captain-47 pending Add session management backend │
# │ └─ captain-48 pending Write auth tests test │
# │ │
# │ captain-50 blocked Add user profile page frontend │
# │ └─ (blocked by captain-42) │
# └──────────────────────────────────────────────────────────────────────────────┘
#
# Legend: done=green, working=cyan, pending=gray, blocked=yellow
The tree view shows task hierarchy and blocking relationships at a glance.
# What's ready to work on?
bd ready
# captain-48: Write auth tests
# (all blockers resolved)
# Filter by label
bd list --labels=backend --status=open
# See what's blocked
bd blocked
# captain-46: blocked by captain-45
# captain-50: blocked by captain-42
# Add a dependency
bd dep add captain-47 captain-46
# captain-47 now depends on captain-46
# Close completed work
bd close captain-45 --reason="JWT impl done"
# Sync to git (persists state)
bd sync --flush-only
# Exported 8 issues to .beads/issues.jsonl
ChunkHound is an MCP server that provides embedding-based code search, enabling agents to find code by meaning.
search_semantic - find by meaningsearch_regex - exact pattern matchcode_research - deep analysisget_stats - index statisticshealth_check - server status↓ scroll down to see MCP server in action ↓
When an agent needs to understand existing code, the Claude SDK makes MCP tool calls:
// Agent: "I need to find how authentication is implemented"
{
"tool": "mcp__ChunkHound__search_semantic",
"input": { "query": "user authentication middleware JWT", "page_size": 5 }
}
// ChunkHound responds with ranked results:
{
"results": [
{ "file": "src/middleware/auth.ts", "score": 0.92, "lines": "45-52",
"chunk": "export async function verifyToken(req)..." },
{ "file": "src/utils/tokens.ts", "score": 0.87,
"chunk": "export function generateAccessToken(user)..." }
]
}
For complex questions, agents use the code_research tool for deep analysis:
// Planner needs to understand the entire auth system architecture
{
"tool": "mcp__ChunkHound__code_research",
"input": {
"query": "How does the authentication system work? What are the main components?"
}
}
// ChunkHound performs multi-step analysis and returns markdown report:
{
"analysis": "## Authentication System Architecture\n\n### Components\n1. **JWT Middleware** - Validates Bearer tokens...\n2. **Token Service** - Generates access/refresh tokens...\n3. **Login Endpoint** - POST /api/login...\n\n### Data Flow\nRequest → auth middleware → verify JWT → attach user → handler\n\n### Related Files\n- src/models/User.ts, src/config/jwt.ts, tests/auth.test.ts"
}
// Find all usages of a specific function
{
"tool": "mcp__ChunkHound__search_regex",
"input": {
"pattern": "verifyToken\\(",
"path": "src/",
"output_mode": "content"
}
}
// Response:
{
"matches": [
"src/middleware/auth.ts:47: verifyToken(req)",
"src/routes/profile.ts:12: verifyToken(ctx.req)",
"src/routes/settings.ts:8: verifyToken(ctx.req)"
],
"count": 3
}
// Validator extracts patterns for indexing
{
"discovery": {
"type": "pattern",
"content": "Auth uses Bearer tokens with 15min expiry. Refresh tokens stored in httpOnly cookies.",
"files": [
"src/middleware/auth.ts",
"src/utils/tokens.ts"
]
}
}
// Future agents can find this via:
// "how does token refresh work?"
# captain.yaml
project:
name: my-project
baseBranch: main
redis:
url: redis://localhost:6379
planners:
count: 1 # Usually 1 is enough
workers:
count: 3 # Parallel workers
maxNestedDepth: 2 # Subtask depth limit
validators:
count: 1 # Usually 1 is enough
# Per-agent LLM configuration
planner:
model: claude-sonnet-4-20250514
maxTurns: 35
worker:
model: claude-sonnet-4-20250514
maxTurns: 50
# Integrations
beads:
enabled: true
syncOnComplete: true
chunkhound:
enabled: true
persistDiscoveries: true
# Start with initial task
captain start \
--tui \
--task "Add user auth"
# Start without initial task
captain start --tui
# Add to running session
captain add "Implement logout"
captain add "Add password reset"
# Attach to running session
captain attach
# View session status
captain status
Tab - Switch panels
Enter - Fullscreen panel
j/k - Scroll
a/w/v/p - Filter logs (fullscreen)
q - Quit
Tab panels | Enter fullscreen | j/k scroll | a/w/v/p filter logs | q quit
LLMs work in turns: think, act, observe. Captain manages turn limits and enables session resumption.
Multiple workers in isolated worktrees. Tasks without dependencies run simultaneously.
Planner uses semantic search to understand codebase before decomposing epics into tasks.
Explicit dependency graph ensures correct ordering while maximizing parallelism.
Validator reviews all work before merge. Batch validation for efficiency.
Beads tracks issues in git. ChunkHound indexes discoveries. State survives restarts.
Multi-Agent Task Orchestration
Redis + Claude SDK + Git Worktrees + Beads + ChunkHound
Questions?