Let's build a practical 3-agent pipeline: Researcher gathers information, Writer drafts content, Reviewer provides feedback. The loop continues until quality is sufficient.
┌─────────────────────────────────────┐ │ ORCHESTRATOR │ │ (manages handoffs, tracks quality) │ ├──────┬──────────┬──────────┬────────┤ │ Step │ Agent │ Input │ Output │ ├──────┼──────────┼──────────┼────────┤ │ 1 │Researcher│ Topic │ Notes │ │ 2 │ Writer │ Notes │ Draft │ │ 3 │ Reviewer │ Draft │ Score │ │ 4 │ Writer │ Feedback │ v2 │ │ ...repeat until score >= 8/10... │ └─────────────────────────────────────┘
const agents = {
researcher: {
system: "You are a research specialist. Given a topic, search the web and compile a structured research brief with key facts, statistics, and expert opinions. Output JSON.",
tools: ["web_search", "read_url"],
model: "claude-sonnet-4-20250514"
},
writer: {
system: "You are a technical writer. Given research notes (and optional reviewer feedback), write a clear, engaging blog post. Use examples and code snippets.",
tools: [],
model: "claude-sonnet-4-20250514"
},
reviewer: {
system: "You are an editor. Score the draft 1-10 on accuracy, clarity, and engagement. Provide specific, actionable feedback. Output JSON: {score, feedback[]}",
tools: [],
model: "claude-haiku-4-20250514" // Cheap model for review
}
};
| Tip | Why |
|---|---|
| Use a cheap model for the reviewer | Review doesn't need creativity, saves 5-10x on tokens |
| Cap iterations at 3 | Diminishing returns after 2-3 revision cycles |
| Pass summaries, not full outputs | Writer only needs the feedback, not the full review analysis |
| Log every handoff | Essential for debugging — you need to see what each agent received |