Skip to content

Agent Orchestration Cheat Sheet

Coordinate multiple AI coding agents for parallel and complex work.

Break work into appropriately-sized chunks:

Too large: "Build the authentication system"
Too small: "Add import statement for bcrypt"
Right size: "Implement password hashing with bcrypt, including
hash generation and verification functions"

Decomposition criteria:

  • Independence — Can this run without waiting for other tasks?
  • Context fit — Does the agent have enough info to complete it?
  • Verifiability — Can you tell if it succeeded?

Each agent has limited context. Decide what to include:

IncludeExclude
Relevant file pathsUnrelated code
API contracts / interfacesFull implementation details
Constraints and requirementsHistorical discussions
Expected output formatAlternative approaches not taken

Parallel independent work, then merge.

┌─► Agent A (feature 1) ─┐
Orchestrator ───────┼─► Agent B (feature 2) ─┼───► Merge
└─► Agent C (feature 3) ─┘

Use when: Features don’t share files, tests are independent.

Sequential handoff between specialists.

Research ──► Plan ──► Implement ──► Review ──► Test

Use when: Each stage needs output from the previous.

Lead agent decomposes, spawns workers.

Lead Agent
├── analyzes task
├── creates subtasks
└── spawns specialists
├── Agent A (backend)
├── Agent B (frontend)
└── Agent C (tests)

Use when: Scope unclear upfront, needs dynamic decomposition.

One writes, another critiques.

Implementer ──► code ──► Reviewer ──► feedback ──► Implementer

Use when: Quality matters, catching blind spots.

Spawn focused subagents from main conversation:

Use Task tool with:
- subagent_type: "Explore" for codebase research
- subagent_type: "Plan" for architecture design
- subagent_type: "general-purpose" for multi-step work
- subagent_type: "Bash" for command execution

Subagent prompt tips:

  • State the goal explicitly
  • Specify output format
  • Include relevant file paths
  • Set clear boundaries (“only modify src/auth/“)

Launch multiple in one message for concurrent execution:

"Research the authentication patterns in this codebase" → Task: Explore agent
"Find all API endpoints that need auth" → Task: Explore agent (parallel)
"Check how tests mock authentication" → Task: Explore agent (parallel)

All agents inherit project instructions:

CLAUDE.md
## Architecture
- API routes in src/routes/
- Business logic in src/services/
- All endpoints require JWT auth except /health
## Conventions
- Use zod for validation
- Errors return { error: string, code: number }
- Tests use vitest with in-memory SQLite

Terminal session manager for multiple AI agents.

Terminal window
# Install
cargo install agent-of-empires
# Launch TUI dashboard
aoe
# Create new session
aoe new --agent claude-code --branch feature/auth
# List sessions
aoe list
# Attach to session
aoe attach <session-name>
# View session status
aoe status

Within tmux session:

Terminal window
Ctrl+b d # Detach (session keeps running)
Ctrl+b [ # Scroll mode
Ctrl+b c # New window
Ctrl+b n/p # Next/prev window

Each agent works on separate branch without conflicts:

Terminal window
# Create worktree for agent
git worktree add ../project-feature-auth feature/auth
git worktree add ../project-feature-api feature/api
# List worktrees
git worktree list
# Agent A works in ../project-feature-auth
# Agent B works in ../project-feature-api
# No merge conflicts during parallel work
# When done, merge and clean up
git checkout main
git merge feature/auth
git merge feature/api
git worktree remove ../project-feature-auth
git worktree remove ../project-feature-api

Manage agent sessions manually:

Terminal window
# Create named session
tmux new-session -d -s agent-auth
tmux new-session -d -s agent-api
# Send command to session
tmux send-keys -t agent-auth 'claude' Enter
tmux send-keys -t agent-auth 'Implement JWT auth in src/auth/' Enter
# View session
tmux attach -t agent-auth
# List sessions
tmux list-sessions
# Kill session
tmux kill-session -t agent-auth
## Task
Implement rate limiting middleware for the Express API.
## Context
- API routes are in src/routes/
- Existing middleware pattern in src/middleware/auth.ts
- Use redis client from src/lib/redis.ts
## Requirements
- 100 requests per minute per IP
- Return 429 with retry-after header
- Bypass for /health endpoint
## Output
- Create src/middleware/rateLimit.ts
- Add middleware to src/app.ts
- Write tests in src/middleware/rateLimit.test.ts
## Goal
Understand how error handling works in this codebase.
## Questions to Answer
1. Where are errors caught and transformed?
2. What error format do API responses use?
3. How are errors logged?
4. Are there custom error classes?
## Output Format
Bullet points with file:line references.
## Task
Review the changes in src/auth/ for security issues.
## Focus Areas
- Input validation
- Authentication bypass risks
- Secrets handling
- SQL/NoSQL injection
## Output Format
List issues with severity (critical/high/medium/low), file location, and
suggested fix.

Signs an agent is stuck:

  • No file changes for extended period
  • Repeating same action
  • Error loops without progress
  • Asking questions it should know
SituationAction
Wrong directionStop early, redirect
Missing contextProvide file contents, clarify
Stuck on errorDebug together, unblock
Scope creepRemind of boundaries
Conflicting with other agentCoordinate, define ownership

When passing work between agents:

## Handoff: Auth Implementation → Review
### Completed
- JWT generation in src/auth/jwt.ts
- Login endpoint in src/routes/auth.ts
- Tests passing (12/12)
### Ready for Review
Files changed:
- src/auth/jwt.ts (new)
- src/routes/auth.ts (modified)
- src/middleware/requireAuth.ts (new)
### Open Questions
- Should refresh tokens be stored in Redis or DB?
- Token expiry: 15min proposed, confirm?
Attempt 1: Original prompt
Attempt 2: Add more context, simplify scope
Attempt 3: Break into smaller pieces
Attempt 4: Human intervention
  • Validate outputs before passing to next stage
  • Use feature flags for incomplete work
  • Keep main branch stable, merge only verified work
  • Set timeouts for long-running agents
Anti-PatternBetter Approach
Vague delegationExplicit goals, files, output format
Too many parallel agentsStart with 2-3, scale based on results
No verificationReview outputs before merging
Shared mutable filesIsolate via worktrees or clear ownership
Fire and forgetMonitor progress, intervene early
Over-orchestratingSome tasks don’t need coordination
TaskApproach
Independent featuresFan-out with worktrees
Sequential stagesPipeline with handoff prompts
Unknown scopeHierarchy with lead agent
Quality-criticalPeer review pattern
Quick researchClaude Code Task with Explore agent
Long-running workExternal tool (AoE, tmux)
Shared codebase knowledgeCLAUDE.md with conventions
  • Agent of Empires — Terminal session manager for multiple AI agents
  • Claude-Flow — Orchestration framework for Claude Code
  • Summarize — Multi-source content summarizer (URLs, YouTube, PDFs, audio)
  • Microsoft Agent Framework — Graph/DAG orchestration with time-travel checkpointing
  • AgenticFleet — Adaptive routing with typed DSPy signatures, built on Agent Framework
  • Antfarm — Minimal dev workflow automation with clean context per step and doer/verifier separation
  • claude-mem — Persistent memory via hooks, progressive disclosure retrieval
  • claude-code-templates — Installable marketplace of agents, commands, hooks, MCPs
  • Claude Quickstarts — Official reference implementations (RAG, computer use, autonomous coding)
  • Graphiti — Temporal knowledge graph with bi-temporal tracking
  • Mem0 — Multi-level vector memory middleware
  • CASS — Three-layer cognitive memory with confidence decay and anti-pattern inversion