Skip to content

7302: Multi-Agent Communication Protocols

โฑ 7 min readยท๐Ÿ“… Last updated: 2026-10-17

Difficulty: โญโญโญ Advanced

Estimated Time: 4 hours

Abstract

A multi-agent system is only as reliable as the contracts between its agents. This document defines message schemas and envelopes, the main coordination topologies (orchestrator-worker, peer-to-peer, hierarchical), consensus and negotiation patterns, handoff protocols that preserve context, interoperability standards (MCP, A2A), and the failure handling that keeps a fleet of LLM agents debuggable in production.


Table of Contents


1. Overview

1.1 Prerequisites

Learning Objectives

After completing this document, you will:

  • โœ… Design a typed message envelope with correlation IDs
  • โœ… Choose a coordination topology from task structure, not hype
  • โœ… Implement voting/debate consensus and know when it helps
  • โœ… Package agent-to-agent handoffs without losing context
  • โœ… Handle timeouts, retries, and dead-lettering in agent fleets

2. Why Structured Messages

The naive pattern โ€” agents reading each other's raw prose โ€” fails at scale for three reasons:

1. Ambiguity   : downstream agents misinterpret intent, compound errors
2. No tracing  : "who asked for this?" is unanswerable after the fact
3. Coupling    : rewording one agent's output breaks its consumers

The fix is treating inter-agent communication like service-to-service communication: typed payloads, explicit addressing, correlation IDs. Natural language stays inside the payload; the envelope is structured.


3. Message Envelope

from dataclasses import dataclass, field, asdict
from uuid import uuid4

@dataclass
class Message:
    type: str                     # "task_request" | "task_result" | "query" | "error"
    sender: str                   # agent id
    recipient: str                # agent id or "broadcast"
    payload: dict                 # typed content for this message type
    correlation_id: str = ""      # links result -> request (set by requester)
    message_id: str = field(default_factory=lambda: uuid4().hex)
    reply_to: str = ""            # queue/agent for the response
    ttl_s: int = 120              # drop stale messages

    def to_dict(self):
        return asdict(self)

Envelope rules:

  • Every request carries a fresh message_id; the result echoes the request's correlation_id โ€” this is what makes traces reconstructable
  • payload schema is per-type and versioned (payload_schema: "1.2")
  • Agents never parse another agent's prose to find control information โ€” control lives in the envelope, content in the payload
task_request payload:
  { "goal": str, "constraints": [str], "context_refs": [str],
    "acceptance": str, "budget": { "max_steps": 10, "max_tokens": 50000 } }
task_result payload:
  { "status": "done|failed|partial", "artifacts": [ref],
    "summary": str, "telemetry": { "steps": int, "tokens": int } }

4. Coordination Topologies

4.1 Orchestrator-Worker (default choice)

            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
            โ”‚ Orchestrator โ”‚  decomposes, routes, aggregates
            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”Œโ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”
 โ”‚ Worker Aโ”‚  โ”‚ Worker Bโ”‚  โ”‚ Worker Cโ”‚   no worker-to-worker chat
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

4.2 Peer-to-Peer

Agents message each other directly. Cheap latency, but message complexity grows O(Nยฒ) and failure modes multiply. Justified only for small fleets (N โ‰ค 4) with genuinely symmetric collaboration (e.g., debate).

4.3 Hierarchical

Teams of workers, each with a team lead; leads talk to the top orchestrator. Matches org-chart task decomposition โ€” use when a plan naturally nests (e.g., "research" โ†’ sub-teams per topic).

Topology Message complexity Best for
Orchestrator-worker O(N) Default; decomposable tasks
Peer-to-peer O(Nยฒ) Small symmetric fleets
Hierarchical O(N + T) Deeply nested task structure

5. Consensus & Negotiation

5.1 Voting

Run k independent agents on the same task and take majority:

def majority_vote(answers: list[str]) -> str:
    from collections import Counter
    return Counter(answers).most_common(1)[0][0]
  • Reliable when answers are canonicalizable (IDs, classifications, numbers)
  • Useless on free-form prose โ€” votes won't string-match; use a judge model to score candidates instead

5.2 Debate / Critique Loop

Proposer produces; critic attacks; proposer revises โ€” bounded rounds:

for round in range(max_rounds=2):
    draft    = proposer(task, critique)
    critique = critic(task, draft)          # specific, actionable flaws
    if critic_verdict == "accept":
        break
final = draft
  • Two rounds capture most of the gain; more rounds mostly add cost
  • Critics must see the acceptance criteria, not just the draft โ€” otherwise they nitpick style

๐Ÿ“Š Rule of Thumb: Add consensus machinery only where a single agent's error rate is measurably high and errors are independent. Consensus on correlated failures (same model, same prompt) buys almost nothing.


6. Handoff Protocol

When work moves between agents, the receiver must not inherit the sender's entire transcript. Package a context capsule:

def handoff(from_agent, to_agent, task_state):
    return Message(
        type="handoff",
        sender=from_agent,
        recipient=to_agent,
        payload={
            "goal": task_state.goal,
            "facts": task_state.validated_facts,      # settled conclusions
            "open_questions": task_state.unresolved,
            "artifacts": task_state.artifact_refs,     # data by reference
            "decisions": task_state.decisions_log,     # why, not just what
        },
    )

Where:

  • facts vs open_questions split stops receivers from redoing settled work
  • artifacts by reference (storage keys, not inlined blobs) keeps messages small and cache-friendly
  • The decisions log preserves rationale โ€” without it, the receiving agent re-litigates choices and loops

7. Interoperability Standards

Two complementary standards matter for agent fleets:

Standard Scope What it standardizes
MCP (Model Context Protocol) Agent โ†” tools/resources Tool discovery, invocation, resource access over JSON-RPC
A2A (Agent-to-Agent) Agent โ†” agent Agent cards (capabilities), task handoffs, streaming status
  • Use MCP for the tool layer: one integration surface per tool, reused by every agent (see 7200)
  • Use A2A-style handoffs for the agent layer: capability discovery ("who can do X?") plus task lifecycle (submitted โ†’ working โ†’ done)
  • Both reduce the Nร—M integration problem to N+M

In practice an MCP deployment starts as one config file: every MCP client (Claude Desktop, VS Code, an agent harness) reads the same mcpServers shape โ€” command + args + env launches a stdio server as a subprocess, url points at a streamable-HTTP one:

{
  "mcpServers": {
    "fetch": {
      "command": "uvx",
      "args": ["mcp-server-fetch"]
    },
    "weather": {
      "url": "https://mcp.example.com/mcp"
    }
  }
}

The Python side is symmetric: the mcp package opens a ClientSession over a stdio_client transport, list_tools() discovers what the server exposes, and call_tool(name, args) performs the invocation. Servers surface three primitives โ€” tools (model-invoked actions), resources (read-only context), prompts (reusable templates) โ€” and MCP deliberately stops at the tool layer: agent-to-agent discovery and task lifecycle stay with A2A.


8. Failure Handling

import time

def send_with_retry(bus, msg: Message, retries=2, backoff=1.5):
    for attempt in range(retries + 1):
        try:
            ack = bus.send(msg, timeout_s=10)
            if ack.ok:
                return ack
        except TimeoutError:
            pass
        time.sleep(backoff ** attempt)
    bus.dead_letter(msg, reason="no_ack")   # observable, never silent
    return None

Jitter and Retry-After: Making Backoff Actually Work

The retry loop above backs off exponentially โ€” and so does every other client that saw the same failure. When a provider blips, N clients all compute the same delays and retry in waves at 0.5s, 1s, 2s, 4s โ€” each wave re-trips the limiter it was escaping. Jitter breaks the lockstep: add randomness to every delay so a thousand clients spread their retries instead of synchronizing them. Production SDKs default to it (the major cloud SDKs jitter by default; tenacity calls the idiom wait_random_exponential), and when you use an LLM SDK client you usually configure its built-in retry budget (max_retries) instead of hand-rolling this loop.

The second half of the discipline: honor Retry-After. 2303 teaches the server half โ€” return 429 with a Retry-After hint. The client half is taking that hint seriously: the server knows its own load curve, so its hint beats your computed delay, with max() as the floor your own budget enforces. And in async agents the wait is awaited โ€” time.sleep inside an event loop blocks every task on it:

import asyncio
import random


class RateLimited(Exception):
    """The 429 shape: the server says when to come back."""

    def __init__(self, retry_after_s: float):
        super().__init__(f"retry after {retry_after_s}s")
        self.retry_after_s = retry_after_s


async def send_with_jitter(bus, msg, retries: int = 4, base_s: float = 0.5):
    """Exponential backoff + jitter, honoring the server's Retry-After."""
    for attempt in range(retries + 1):
        try:
            return await bus.send(msg, timeout_s=10)
        except RateLimited as e:
            if attempt == retries:
                raise
            pause = max(e.retry_after_s, base_s * 2**attempt)
        await asyncio.sleep(pause + random.uniform(0, base_s))

Fleet-level rules:

  • Timeouts everywhere: an agent that can hang must not be able to hang a pipeline โ€” per-message ttl_s plus per-task wall-clock budgets
  • Retry idempotently: workers key on message_id so replays are safe
  • Dead-letter queue: after retries, park the message with the error; a supervisor agent (or human) triages the DLQ โ€” never drop silently
  • Circuit breaker: N consecutive failures from one worker โ†’ route around it and alert, instead of burning the whole fleet's budget
  • Budget propagation: parent task's token/step budget divides among children; a child that exhausts its share fails fast, and the parent replans

9. Troubleshooting

Symptom Likely Cause Fix
Results arrive but can't be traced to requests Missing correlation IDs Enforce envelope schema; reject uncorrelated results
Two agents loop, each "fixing" the other Unbounded critique loop Cap rounds; require critic to output accept/reject verdict
Worker receives impossible tasks Orchestrator lacks capability map Agent cards; validate assignment against declared skills
Flaky workers poison consensus Correlated failures Diversify models; consensus only on canonicalizable answers
Handoff loses decisions, work is redone Context capsule too thin Ship facts + decisions log; log handoffs as first-class events
Fleet cost spikes on one workflow No budget propagation Per-task token budgets; enforce at the bus level

Summary

A multi-agent system is only as reliable as the contracts between its agents: this lesson defines the message schemas and envelopes, the three coordination topologies (orchestrator-worker, peer-to-peer, hierarchical), consensus and negotiation patterns, and handoff protocols that preserve context when work moves between agents. The rule it leaves: topology is a reliability decision, not a diagram - pick the shape whose failure mode you can actually operate, and put the schema version in every envelope.

10. References

Specifications

Academic Papers

  • [3] Du et al. "Improving Factuality and Reasoning in Language Models through Multiagent Debate". ICML, 2024.
  • [4] Hong et al. "MetaGPT: Meta Programming for a Multi-Agent Collaborative Framework". ICLR, 2024.
  • [5] Wu et al. "AutoGen: Enabling Next-Gen LLM Applications via Multi-Agent Conversation". 2023.

Next Steps


Document ID: 7302

Status: Complete

Related Documents: [7301, 7101, 7200, 7303]