š¦ Orchestrator-Workers
<div align="center">
Overview
š Home āŗ Workflows āŗ š¦ Orchestrator-Workers
ā 03 Parallelization āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā 05 Evaluator-Optimizer ā
</div>š¦ Orchestrator-Workers
TL;DR: A central LLM dynamically breaks down tasks, delegates to specialized worker LLMs, and synthesizes results. Different experts collaborate on the same problem.
Diagram
%%{init: {'theme': 'base', 'themeVariables': {'lineColor': '#64748b'}}}%%
flowchart TB
classDef user fill:#6366f1,stroke:#4f46e5,stroke-width:2px,color:#ffffff
classDef main fill:#8b5cf6,stroke:#7c3aed,stroke-width:2px,color:#ffffff
classDef subagent fill:#ec4899,stroke:#db2777,stroke-width:2px,color:#ffffff
INPUT["šāāļøš„ Review this PR"]:::user --> ORCH["š Main Agent"]:::main
ORCH -->|"ššŖŗ Check vulns"| W1["š¦š Security Expert"]:::subagent
ORCH -->|"ššŖŗ Check perf"| W2["š¦ā” Performance Expert"]:::subagent
ORCH -->|"ššŖŗ Check style"| W3["š¦šØ Style Expert"]:::subagent
W1 -->|"š¦š¤ 2 SQLi found"| SYNTH["šš Synthesize"]:::main
W2 -->|"š¦š¤ O(n²) loop"| SYNTH
W3 -->|"š¦š¤ 3 violations"| SYNTH
SYNTH -->|"šš¤"| OUTPUT["šāāļøš¤ Final Report"]:::user
Key Insight
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā š¦ ORCHESTRATOR-WORKERS: Different specialists ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā ā
ā Each š¦ subagent has a DIFFERENT expertise and does a DIFFERENT task. ā
ā ā
ā Key difference from š¤ļø Parallelization: subtasks aren't pre-defined, ā
ā but determined by the orchestrator based on the specific input. ā
ā ā
ā Analogy: Hospital team ā Different experts collaborate ā
ā (Chef + Pastry + Sommelier, not 3 cooks making same recipe) ā
ā ā
ā Compare: ā
ā - š¤ļø Parallelization: Same worker + Different data (assembly line) ā
ā - š¦ Orchestration: Different workers + Same data (expert team) ā
ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Characteristics
| Property | Value |
|---|---|
| Complexity | High |
| Parallelism | High |
| Human-Loop | Optional |
| Iteration | As needed |
When to Use
Well-suited for complex tasks where you can't predict the subtasks needed. The key difference from parallelization is its flexibility ā subtasks aren't pre-defined, but determined by the orchestrator based on the specific input.
| Use Case | Orchestration |
|---|---|
| Coding products | Make complex changes to multiple files dynamically |
| Search tasks | Gather and analyze from multiple sources |
| PR Review | Security + Performance + Style experts |
š Main Agent Responsibilities
| Responsibility | Description |
|---|---|
| Decomposition | Break complex task into subtasks |
| Assignment | Route subtasks to appropriate š¦ subagents |
| Monitoring | Track š¦ subagent progress |
| Synthesis | Combine results into coherent output |
š¦ Subagent Definition Example
# .claude/agents/code-reviewer.md
---
name: code-reviewer
description: Reviews code for quality, security, and best practices.
tools: Read, Grep, Glob
model: sonnet
permissionMode: plan
---
You are a senior code reviewer with expertise in security, performance, and maintainability.
## Review Checklist
1. **Security** - SQL injection, XSS, secrets exposure, auth bypasses
2. **Performance** - O(n²) loops, memory leaks, unnecessary computations
3. **Code Quality** - DRY violations, dead code, unclear naming
4. **Best Practices** - Error handling, logging, testing coverage
## Output Format
### ā CRITICAL (must fix before merge)
- [file:line] Issue description
### ā ļø WARNING (should address)
- [file:line] Issue description
### ā¹ļø SUGGESTIONS (nice to have)
- [file:line] Issue description
Full Orchestration Example
# š Main Agent orchestrates PR review with specialists
# Step 1: Decompose - identify what experts are needed
changed_files = get_pr_diff() # ["auth.py", "api.py", "styles.css"]
# Step 2: Assign - spawn appropriate specialists
Task(
subagent_type="security-reviewer",
prompt=f"Review these files for security: {changed_files}"
)
Task(
subagent_type="performance-reviewer",
prompt=f"Review these files for performance: {changed_files}"
)
Task(
subagent_type="style-reviewer",
prompt=f"Review these files for style/quality: {changed_files}"
)
# Step 3: Monitor - wait for all subagents to complete
# (handled automatically by Task tool)
# Step 4: Synthesize - combine into final report
"""
## PR Review: #123 - Add user authentication
### Security Review (š¦ security-reviewer)
ā CRITICAL: SQL injection in auth.py:45
### Performance Review (š¦ performance-reviewer)
ā ļø WARNING: O(n²) loop in api.py:78
### Final Verdict: ā CHANGES REQUESTED
"""
Critical Rules
| Rule | Explanation |
|---|---|
| No nested subagents | š¦ Subagents cannot spawn other š¦ subagents |
| Isolated context | Each š¦ subagent starts fresh, no shared memory |
| Report to orchestrator | Results flow back to š Main Agent only |
When NOT to Use
- Simple tasks not worth decomposition overhead
- Workers need heavy inter-communication
<div align="center">
ā 03 Parallelization āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā 05 Evaluator-Optimizer ā
</div>