PHASE 3 ← Back to Course
20 / 23
👥

Multi-Agent Systems

When one agent isn't enough — orchestrate multiple specialized agents to tackle complex tasks. Understand collaboration patterns that solve problems individual agents can't.

1

Why Multi-Agent? The Power of Specialization

A single agent is jack-of-all-trades, master of none. A multi-agent system assigns specific roles: one agent researches, one analyzes, one writes. Like a development team working on a product.

👷

Analogy: A Development Team

A single developer can build an app, but a team is better: frontend engineer handles UI, backend engineer handles API, DevOps engineer handles deployment. Each specializes, then they integrate. Multi-agent systems work the same way: each agent is an expert, they coordinate.

🎯

Division of Labor

Complex tasks broken into specialized subtasks. Each agent excels at one thing.

Parallel Work

Agents work in parallel (or pipeline) to speed up overall task completion.

🔍

Quality Improvement

One agent's output becomes another's input. Iterative refinement improves quality.

🛡️

Error Detection

A critic agent can verify other agents' work, catching mistakes before delivery.

2

Multi-Agent Patterns — Four Key Architectures

There are four proven patterns for orchestrating multiple agents. Each suits different task types.

Pattern 1: Supervisor (Manager)

One supervisor agent delegates to specialists. The supervisor breaks down the goal, assigns subtasks, gathers results, and synthesizes them. Classic orchestration pattern.

Text — Supervisor Pattern Flow
User: "Write a product launch plan"
       ↓
Supervisor Agent:
  - Breaks into: Market Analysis, Budget Planning, Timeline, Risk Mitigation
  - Assigns to specialists
       ↓
Market Analyst: "Competitors, target audience, positioning"
Budget Planner: "Cost breakdown, revenue projections"
Timeline Manager: "Phases, milestones, dependencies"
Risk Analyst: "Risks, mitigation strategies"
       ↓
Supervisor: Gathers results, synthesizes into final plan
       ↓
User: Complete launch plan

Pattern 2: Peer-to-Peer

Agents work together at the same level. Each can initiate messages to others. Useful for exploratory problems where the solution emerges from discussion.

Pattern 3: Pipeline

Output of one agent becomes input to the next. Linear workflow. Researcher → Analyst → Writer → Editor. Clear data flow.

Pattern 4: Debate / Critic

Multiple agents argue for different viewpoints, a judge/critic decides. Excellent for improving quality by exposing weaknesses in reasoning.

👔

Supervisor (Hierarchical)

One orchestrator, many specialists. Best for: well-defined tasks with clear subtasks.

🤝

Peer-to-Peer (Flat)

All agents equal, self-coordinating. Best for: exploratory, collaborative work.

⛓️

Pipeline (Sequential)

Output → Input chain. Best for: transform-heavy workflows (research → analysis → writing).

⚖️

Debate/Critic (Adversarial)

Opposing viewpoints, judge decides. Best for: quality improvement, difficult decisions.

3

Communication Protocols — How Agents Talk

Agents need a way to communicate: pass data, request information, coordinate actions. There are several approaches, each with tradeoffs.

💬

Message Passing

Agents send structured messages to each other. Asynchronous, loosely coupled. Good for pipelines.

📦

Shared State

All agents read/write to a shared state dictionary. Tightly coupled but fast. Risk of conflicts.

Blackboard Pattern

Central "blackboard" where agents post findings. Others read, build on ideas. Great for exploratory work.

🗂️

Database/File System

Persistent storage for intermediate results. Survives agent restarts. Best for production.

4

The Supervisor Pattern — Complete Implementation

Let's implement the supervisor pattern in Python. This is the most practical pattern for production systems.

Python — Supervisor Pattern
class Agent:
    def __init__(self, name: str, role: str):
        self.name = name
        self.role = role
        self.client = anthropic.Anthropic()

    def work(self, task: str) -> str:
        """Execute a task and return result."""
        response = self.client.messages.create(
            model="claude-opus-4-6",
            max_tokens=2048,
            system=f"You are a {self.role}. Your name is {self.name}. Do excellent work.",
            messages=[{"role": "user", "content": task}]
        )
        return response.content[0].text

class SupervisorAgent:
    def __init__(self):
        self.supervisor = Agent("Supervisor", "Project Manager")
        self.specialists = [
            Agent("Alice", "Market Research Analyst"),
            Agent("Bob", "Financial Analyst"),
            Agent("Carol", "Project Manager")
        ]

    def run(self, goal: str) -> str:
        """Supervisor breaks goal into subtasks, delegates to specialists."""

        # 1. Supervisor analyzes goal and creates subtasks
        subtasks_prompt = f"""Goal: {goal}

Break this into 3 specific subtasks for different specialists:
1. For a Market Research Analyst
2. For a Financial Analyst
3. For a Project Manager

Format:
SUBTASK 1: [task for analyst 1]
SUBTASK 2: [task for analyst 2]
SUBTASK 3: [task for analyst 3]"""

        subtasks_text = self.supervisor.work(subtasks_prompt)

        # 2. Parse subtasks (simple regex approach)
        subtasks = []
        for line in subtasks_text.split("\n"):
            if "SUBTASK" in line:
                subtasks.append(line)

        # 3. Distribute to specialists
        results = []
        for i, specialist in enumerate(self.specialists):
            if i < len(subtasks):
                result = specialist.work(subtasks[i])
                results.append({
                    "specialist": specialist.name,
                    "result": result
                })

        # 4. Supervisor synthesizes results
        synthesis_prompt = f"""You have collected the following results from specialists:

{chr(10).join([f"{r['specialist']}: {r['result'][:300]}" for r in results])}

Synthesize these into a cohesive final deliverable for the goal: {goal}

Provide a comprehensive, well-structured final answer."""

        final_answer = self.supervisor.work(synthesis_prompt)
        return final_answer

# Usage
supervisor = SupervisorAgent()
result = supervisor.run("Create a launch strategy for a new SaaS product")
print(result)
5

The Debate Pattern — Quality Through Adversarial Collaboration

Two agents argue for opposite positions. A judge evaluates both and decides. This improves answer quality by forcing reasoning to surface weaknesses.

Python — Debate Pattern
class DebateAgents:
    def __init__(self):
        self.pro_agent = Agent("Pro", "Advocates FOR the proposal")
        self.con_agent = Agent("Con", "Advocates AGAINST the proposal")
        self.judge = Agent("Judge", "Evaluates both sides fairly")

    def debate(self, question: str) -> str:
        # Round 1: Pro argues FOR
        pro_argument = self.pro_agent.work(
            f"Argue STRONGLY FOR: {question}\nBe compelling and data-driven."
        )

        # Round 2: Con argues AGAINST
        con_argument = self.con_agent.work(
            f"Argue STRONGLY AGAINST: {question}\nAddress Pro's points if possible."
        )

        # Round 3: Judge decides
        judgment = self.judge.work(
            f"""Question: {question}

Pro argument: {pro_argument}

Con argument: {con_argument}

Evaluate both arguments. Which is stronger? Why? What's the best decision?"""
        )

        return f"""
PRO ARGUMENT:
{pro_argument}

CON ARGUMENT:
{con_argument}

JUDGE'S DECISION:
{judgment}"""

# Usage
debate = DebateAgents()
decision = debate.debate("Should we adopt microservices architecture?")
print(decision)
💡

When Debate Wins

Strategic decisions, architecture choices, hiring decisions. When the answer has legitimate pros and cons, debate surfacing both sides improves quality.

6

Challenges of Multi-Agent Systems

Multi-agent systems are powerful but introduce new problems. Understanding challenges is critical for success.

⚠️

Challenge 1: Coordination Overhead

More agents = more communication. Message passing, context sharing, state management. For simple tasks, the overhead outweighs benefits. Single-agent may be faster.

⚠️

Challenge 2: Infinite Loops

Agent A asks Agent B, who asks Agent C, who asks Agent A. Uncontrolled loops waste tokens and time. Add strict termination conditions and loop detection.

⚠️

Challenge 3: Conflicting Outputs

Different agents disagree or contradict each other. You need a judge or arbitrator. Build conflict resolution into your system design.

⚠️

Challenge 4: Cost Explosion

Multiple agents = multiple LLM calls. 5 agents × 10 iterations = 50 API calls. Costs add up fast. Monitor and budget carefully.

7

When Multi-Agent is Overkill

Not every problem needs multi-agent. Sometimes a single well-engineered agent is better.

✅ USE Multi-Agent For:
- Complex, multi-step workflows
- Tasks needing specialization
- Quality validation (critic agent)
- Exploratory/debate scenarios
- Team-like coordination
❌ Skip Multi-Agent For:
- Single-step tasks
- Simple classification/summarization
- Latency-critical applications
- Cost-sensitive deployments
- Well-defined linear workflows
💎

Start Simple, Scale Gradually

Build a single agent first. If it can't handle the task, add specialists. Add a critic agent if quality is an issue. This incremental approach prevents over-engineering.

2025+ Update: Agent-to-Agent (A2A) Protocol

As multi-agent systems move from research to production, a major challenge has emerged: how do agents from different vendors communicate? Google's A2A protocol (Agent-to-Agent) is an open standard that solves this.

🔗 What is A2A?

An open protocol that lets agents discover each other's capabilities, negotiate tasks, and exchange results — regardless of which framework or vendor built them. Think of it as HTTP for agent communication.

📋 Agent Cards

Each agent publishes an Agent Card (a JSON descriptor) at a well-known URL. It describes the agent's skills, input/output formats, and authentication requirements — enabling automatic discovery and interoperability.

🤝 A2A + MCP Together

A2A and MCP are complementary, not competing. MCP connects agents to tools and data sources. A2A connects agents to other agents. Production systems use both protocols together.

🏢 Industry Adoption

Backed by Google, Salesforce, SAP, Atlassian, and 50+ companies. A2A supports streaming, push notifications, and multi-turn conversations between agents — designed for enterprise-grade orchestration.

Key Insight: The patterns you learned in this lesson (supervisor, pipeline, debate) describe how agents collaborate. A2A standardizes the communication layer so those patterns work across organizational and vendor boundaries. When building multi-agent systems, design your agent interfaces to be A2A-compatible from the start.

Check Your Understanding

Quick Quiz — 4 Questions

1. In the supervisor pattern, what does the supervisor do?

2. The debate pattern is best for what type of problem?

3. What's a major risk with multi-agent systems?

4. When is a single agent better than multiple agents?

Topic 16 Summary

Multi-agent systems apply specialization to complex problems. Four patterns dominate: Supervisor (one orchestrator, many specialists), Peer-to-Peer (flat collaboration), Pipeline (sequential transformation), and Debate (adversarial quality improvement). Communication protocols determine how agents coordinate: message passing, shared state, blackboard, or database. Challenges include coordination overhead, infinite loops, conflicting outputs, and cost explosions. Not every problem needs multi-agent — single agents are simpler and cheaper for straightforward tasks. Use multi-agent for genuinely complex, multi-step problems where specialization adds value.

Next up → Topic 17: Full-Stack AI Agent Project
Capstone project: build a complete, production-ready multi-agent research system.

← Topic 15 Topic 20 of 23 Topic 17 →