|
| 1 | +# Build an Automated Code Review Team |
| 2 | + |
| 3 | +**Difficulty:** Medium |
| 4 | + |
| 5 | +## What you'll build |
| 6 | + |
| 7 | +A three-agent code review team using the supervisor-worker pattern. The code |
| 8 | +reviewer supervises a test writer and a security auditor, all enhanced with smart |
| 9 | +prompts and exported to Claude Code. |
| 10 | + |
| 11 | +## Prerequisites |
| 12 | + |
| 13 | +- Python 3.10+ |
| 14 | +- `pip install multi-agent` |
| 15 | +- Completed [01 -- Getting Started](01-getting-started.md) |
| 16 | + |
| 17 | +## Step 1 -- Load the agents |
| 18 | + |
| 19 | +```python |
| 20 | +from multiagent import Catalog |
| 21 | + |
| 22 | +catalog = Catalog() |
| 23 | +reviewer = catalog.load("code/code-reviewer") |
| 24 | +test_writer = catalog.load("code/test-writer") |
| 25 | +security_auditor = catalog.load("code/security-auditor") |
| 26 | + |
| 27 | +print(f"Supervisor: {reviewer.full_name}") |
| 28 | +print(f"Workers: {test_writer.full_name}, {security_auditor.full_name}") |
| 29 | +``` |
| 30 | + |
| 31 | +## Step 2 -- Compose with supervisor-worker pattern |
| 32 | + |
| 33 | +The supervisor decomposes the task and delegates subtasks to workers: |
| 34 | + |
| 35 | +```python |
| 36 | +from multiagent import patterns |
| 37 | + |
| 38 | +team = patterns.supervisor_worker( |
| 39 | + supervisor=reviewer, |
| 40 | + workers=[test_writer, security_auditor], |
| 41 | + model="claude-haiku-4-5", |
| 42 | +) |
| 43 | + |
| 44 | +print(team.describe()) |
| 45 | +``` |
| 46 | + |
| 47 | +## Step 3 -- Enhance with smart prompts |
| 48 | + |
| 49 | +Make each agent smarter with research-backed prompt engineering: |
| 50 | + |
| 51 | +```python |
| 52 | +from multiagent import enhance_agent |
| 53 | + |
| 54 | +smart_reviewer = enhance_agent(reviewer, profile="all") |
| 55 | +smart_test_writer = enhance_agent(test_writer, profile="category") |
| 56 | +smart_auditor = enhance_agent(security_auditor, profile="category") |
| 57 | + |
| 58 | +print(f"Original prompt: {len(reviewer.system_prompt)} chars") |
| 59 | +print(f"Enhanced prompt: {len(smart_reviewer.system_prompt)} chars") |
| 60 | +``` |
| 61 | + |
| 62 | +## Step 4 -- Export to Claude Code |
| 63 | + |
| 64 | +Generate skill files that Claude Code auto-discovers: |
| 65 | + |
| 66 | +```python |
| 67 | +from multiagent import export_agent |
| 68 | + |
| 69 | +for agent in [smart_reviewer, smart_test_writer, smart_auditor]: |
| 70 | + output = export_agent(agent, target="claude-code", output_dir=".agents/skills") |
| 71 | + print(f"Exported: {agent.name}.md") |
| 72 | +``` |
| 73 | + |
| 74 | +This creates files in `.agents/skills/` that Claude Code picks up automatically. |
| 75 | + |
| 76 | +## Step 5 -- Visualize the team |
| 77 | + |
| 78 | +Auto-generate a Mermaid diagram for documentation or README files: |
| 79 | + |
| 80 | +```python |
| 81 | +from multiagent.visualize import visualize_team |
| 82 | + |
| 83 | +diagram = visualize_team( |
| 84 | + [reviewer, test_writer, security_auditor], |
| 85 | + pattern="supervisor-worker", |
| 86 | +) |
| 87 | +print(diagram) |
| 88 | +``` |
| 89 | + |
| 90 | +## Step 6 -- Cost comparison across models |
| 91 | + |
| 92 | +```python |
| 93 | +from multiagent import CostEstimator |
| 94 | + |
| 95 | +agents = [reviewer, test_writer, security_auditor] |
| 96 | + |
| 97 | +print(f"{'Model':<25} {'Cost':>10} {'Tokens':>8}") |
| 98 | +print("-" * 47) |
| 99 | + |
| 100 | +for model in ["claude-haiku-4-5", "claude-sonnet-4-6", "gpt-4o", "gpt-4o-mini", |
| 101 | + "gemini-2.5-flash", "gemma4-27b"]: |
| 102 | + est = CostEstimator.estimate_team(agents, model=model, extra_input_tokens=5000) |
| 103 | + e = est.estimates[0] |
| 104 | + cost = f"${e.cost_usd:.4f}" if e.cost_usd > 0 else "free" |
| 105 | + print(f"{model:<25} {cost:>10} {e.total_tokens:>8}") |
| 106 | +``` |
| 107 | + |
| 108 | +## Complete runnable script |
| 109 | + |
| 110 | +```python |
| 111 | +"""Build a code review team with smart enhancements.""" |
| 112 | + |
| 113 | +from multiagent import Catalog, CostEstimator, enhance_agent, export_agent, patterns |
| 114 | +from multiagent.visualize import visualize_team |
| 115 | + |
| 116 | +catalog = Catalog() |
| 117 | +reviewer = catalog.load("code/code-reviewer") |
| 118 | +test_writer = catalog.load("code/test-writer") |
| 119 | +security_auditor = catalog.load("code/security-auditor") |
| 120 | + |
| 121 | +# Enhance, compose, export, visualize, estimate -- all in one script |
| 122 | +smart_reviewer = enhance_agent(reviewer, profile="all") |
| 123 | +smart_test_writer = enhance_agent(test_writer, profile="category") |
| 124 | +smart_auditor = enhance_agent(security_auditor, profile="category") |
| 125 | + |
| 126 | +team = patterns.supervisor_worker( |
| 127 | + supervisor=smart_reviewer, workers=[smart_test_writer, smart_auditor], |
| 128 | + model="claude-haiku-4-5", |
| 129 | +) |
| 130 | +print(team.describe()) |
| 131 | + |
| 132 | +for agent in [smart_reviewer, smart_test_writer, smart_auditor]: |
| 133 | + export_agent(agent, target="claude-code", output_dir=".agents/skills") |
| 134 | + |
| 135 | +print("\n" + visualize_team([reviewer, test_writer, security_auditor], pattern="supervisor-worker")) |
| 136 | +print("\n" + str(CostEstimator.estimate_team([reviewer, test_writer, security_auditor], extra_input_tokens=5000))) |
| 137 | +``` |
| 138 | + |
| 139 | +## Next steps |
| 140 | + |
| 141 | +Want to build a research pipeline with parallel agents? Continue with |
| 142 | +[03 -- Research Pipeline](03-research-pipeline.md). |
0 commit comments