PTENES
Skip to content
MODULE 4.3

🤖 Multi-Agent Patterns

Architectural patterns for orchestrating multiple agents: fan-out/fan-in, sequential pipelines, Explore-Plan-Execute, specialist agents, distributed error handling, and cost control.

6
Topics
~50
Minutes
4.2
Prerequisite
Adv.
Type
Progress:0%0 of 6
1

Fan-out / fan-in

The most common pattern: an orchestrator distributes (fan-out) tasks to N subagents and then brings together (fan-in) the results. A classic example: analyze 5 codebase modules in parallel and consolidate them into a single report.

The key to fan-out/in is that all distributed tasks are independent. Fan-in is when the parent reads all the results and synthesizes them. If one subagent fails, the others are unaffected.

In one sentence: Fan-out distributes work, and fan-in brings the results together. The most basic and powerful pattern.

2

Sequential pipeline

When tasks depend on one another, use a pipeline: Agent A analyzes, passes the result to Agent B to plan, and Agent B passes it to Agent C to execute. Each agent has a clear scope and receives the previous agent’s output as input. It’s like an assembly line.

Pipeline example

Agent 1 (Analysis): "Read src/ and list all performance issues" → Agent 2 (Plan): "Given these problems, create a prioritized fix plan" → Agent 3 (Execution): "Execute the first 3 fixes in the plan"

In one sentence: pipeline = chained tasks where the output of one feeds the input of the next.

3

Explore, Plan, Execute

A specific pipeline is very effective: Explore (a read-only agent maps the codebase and understands its structure), Plan (another agent receives the map and creates a detailed change plan), Execute (a third agent with write access implements the plan). Each phase uses the most suitable type of agent.

In one sentence: Explore-Plan-Execute separates analysis, planning, and action into specialized agents.

4

Specialist agents

Instead of a single general-purpose agent, create agents specialists: one just for testing, another just for documentation, another for security. Each gets a system prompt focused on its domain, which improves output quality. It's like having a team where each person has their own expertise.

Agent: Tests

"You are a testing expert. Run the tests, analyze failures, and suggest fixes."

Agent: Security

"You are a security reviewer. Analyze the code for OWASP Top 10 vulnerabilities."

Agent: Docs

"You are a technical writer. Update the documentation to reflect recent changes."

In one sentence: Specialist agents with focused prompts deliver better results than a generalist doing everything.

5

Distributed error handling

In multi-agent systems, failures are inevitable. Resilience patterns include: retry with backoff (relaunch the subagent with an adjusted prompt), fallback (if the specialist fails, a generalist tries), and circuit breaker (if 3+ subagents fail at the same task, stop and escalate to a human).

In one sentence: retry, fallback, and circuit breaker ensure resilience in a multi-agent system.

6

Cost control

Each subagent uses tokens. Control strategies: limit max_tokens per subagent, use smaller models (Haiku) for simple tasks like linting or formatting, and measure the ROI before parallelizing. If 5 subagents cost $2 but save 30 minutes of your time, it’s worth it. If they cost $2 and save 2 minutes, it isn’t.

In one sentence: control costs by limiting tokens, using smaller models, and measuring whether parallelism pays off.

🧾 Module Summary

✓
Fan-out/in — distributes and gathers. The most basic pattern.
✓
Pipeline — sequential chaining when there’s a dependency.
✓
Specialists — focused agents deliver better results than generalists.
✓
Cost control — measure ROI before scaling up subagents.

Next module:

4.4 — Git with AI: Semantic Commits, Smart Staging, and Merge Conflicts.