Skip to content
Phase 5: AdvancedStep 14 of 14AdvancedOngoingADVANCED

Multi-Agent Systems

Coordinate teams of specialized agents that communicate, delegate, and collaborate.

Agent communicationTask delegationConsensusMCP protocolA2A protocol

Getting Started

A single agent has limits. It can only hold so much context, reason from one perspective, and work on one task at a time. Multi-agent systems break complex problems into parts and assign them to specialized agents that collaborate toward a shared goal. This mirrors how human teams work: a researcher gathers data, an analyst finds patterns, and a writer communicates findings.

The key challenge is not building individual agents — you already know how to do that. The challenge is coordination: how agents communicate, how work gets delegated, and how the system reaches consensus on a final result.

Key Concepts

Agent communication protocols define the structure of messages between agents. At minimum, each message needs a sender, recipient, content, and type. A simple message bus routes messages to the right agent:

from dataclasses import dataclass
from enum import Enum

class MessageType(Enum):
    TASK = "task"
    RESULT = "result"
    QUESTION = "question"
    FEEDBACK = "feedback"

@dataclass
class AgentMessage:
    sender: str
    recipient: str
    content: str
    msg_type: MessageType
    metadata: dict | None = None

class MessageBus:
    def __init__(self):
        self.agents: dict[str, "BaseAgent"] = {}
        self.history: list[AgentMessage] = []

    def register(self, agent: "BaseAgent"):
        self.agents[agent.name] = agent

    def send(self, message: AgentMessage):
        self.history.append(message)
        recipient = self.agents[message.recipient]
        return recipient.process_message(message)

Task delegation is how a coordinator agent breaks a complex task into subtasks and assigns them to specialists. The coordinator needs to understand each agent's capabilities, decompose the problem, and sequence the subtasks correctly. A simple approach is defining a workflow as a list of stages where each stage maps to an agent:

workflow = [
    {"agent": "researcher", "task": "Find information about {topic}"},
    {"agent": "analyst", "task": "Analyze findings: {researcher_output}"},
    {"agent": "writer", "task": "Write report from analysis: {analyst_output}"},
]

Consensus mechanisms matter when agents disagree. If two agents produce conflicting analyses, you need a strategy: majority vote, confidence scoring, or escalation to a human. For most practical systems, simple strategies work — a lead agent reviews outputs and requests revisions.

MCP (Model Context Protocol) standardizes how agents discover and use tools. Instead of each agent having hardcoded tool integrations, MCP provides a common protocol for tool discovery, schema inspection, and invocation. This makes it straightforward to share tools across agents.

A2A (Agent-to-Agent) protocols extend this standardization to inter-agent communication, defining how agents from different systems or providers can collaborate.

Hands-On Practice

Build a three-agent system with a shared message bus. Start simple: the Researcher takes a topic and returns bullet points, the Analyst takes bullet points and returns a structured analysis, and the Writer takes the analysis and produces a paragraph summary. Run the full pipeline and examine the message history to understand the flow. Then add complexity: let agents ask each other clarifying questions, and have the coordinator handle retries when an agent's output does not meet quality criteria.

Exercises

Build a 3-Agent Research System

Create a multi-agent system with three specialized agents: a Researcher that gathers information, an Analyst that synthesizes findings into insights, and a Writer that produces a final report. The agents should communicate through a shared message bus with structured messages.

Knowledge Check

What is the Model Context Protocol (MCP) primarily used for in multi-agent systems?

Milestone Project

System with 3+ specialized agents collaborating on a complex task with defined roles