RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Eruo Fredoline
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /Courses
  5. /Multi-Agent Systems
  6. /Ch. 4
Multi-Agent Systems

04. Agent Communication Protocols

Chapter 4 of 24 · 15 min
KEY INSIGHT

Protocol design determines whether agents interoperate or become isolated silos; clean abstractions survive model changes while brittle interfaces crumble. Agent communication requires explicit protocols governing message formats, turn-taking, error handling, and state management. Without standardized protocols, each agent pair requires custom integration code. Adding a new agent means updating every existing peer. Protocols prevent this N×M integration problem. Communication protocols define three layers: syntactic (message structure and serialization), semantic (meaning of message contents and valid transitions), and pragmatic (conversational patterns and context management). Syntactic choices (JSON vs protobuf vs custom formats) matter less than semantic clarity and pragmatic reliability. Messages carry intents: requests, responses, notifications, errors. Each intent type carries different expectations about acknowledgment, retry behavior, and timeout handling. A request expects a response; a notification does not. Protocols must distinguish these patterns to enable appropriate handling. State management during conversations requires careful design. Does each agent maintain conversation state? Is there a shared conversation tracker? Does each message carry full context? Stateful protocols support richer interactions but complicate implementation. Stateless protocols scale better but require clients to track context. Error handling deserves explicit protocol attention. Network failures, agent crashes, malformed messages, and timeout scenarios must all produce deterministic behavior. Protocols should specify retry budgets, backoff strategies, and dead-letter handling. Protocol versioning enables evolution. Agents supporting multiple protocol versions interoperate with both old and new peers. The protocol should define negotiation mechanisms so agents discover mutual capabilities. ```python from abc import ABC, abstractmethod from dataclasses import dataclass, field from typing import Any, Optional from enum import Enum import json class MessageType(Enum): REQUEST = "request" RESPONSE = "response" NOTIFICATION = "notification" ERROR = "error" @dataclass class Message: id: str type: MessageType sender: str receiver: Optional[str] # None for broadcast action: str payload: dict[str, Any] correlation_id: Optional[str] = None # Links request/response ttl_seconds: int = 30 metadata: dict[str, Any] = field(default_factory=dict) class AgentProtocol(ABC): @abstractmethod async def send(self, message: Message) -> None: pass @abstractmethod async def receive(self) -> Optional[Message]: pass @abstractmethod async def acknowledge(self, message_id: str) -> None: pass class JSONAgentProtocol(AgentProtocol): def __init__(self, transport): self.transport = transport self.pending = {} async def send(self, message: Message) -> None: serialized = json.dumps({ "id": message.id, "type": message.type.value, "sender": message.sender, "receiver": message.receiver, "action": message.action, "payload": message.payload, "correlation_id": message.correlation_id, "ttl": message.ttl_seconds, "metadata": message.metadata }) if message.type == MessageType.REQUEST: self.pending[message.id] = message await self.transport.send(serialized) async def receive(self) -> Optional[Message]: raw = await self.transport.receive() if not raw: return None data = json.loads(raw) return Message( id=data["id"], type=MessageType(data["type"]), sender=data["sender"], receiver=data["receiver"], action=data["action"], payload=data["payload"], correlation_id=data.get("correlation_id"), ttl_seconds=data.get("ttl", 30), metadata=data.get("metadata", {}) ) async def acknowledge(self, message_id: str) -> None: ack = Message( id=f"ack_{message_id}", type=MessageType.NOTIFICATION, sender="local", receiver=None, action="ack", payload={"original_id": message_id} ) await self.send(ack) ```

EXERCISE

Design a protocol for a multi-agent system where one agent generates code, another reviews it, and a third executes tests. Specify message formats for each interaction type (code submission, review feedback, test results). Include error handling for timeouts, malformed code, and execution failures. Implement the message serialization logic. (15 minutes)

← Chapter 3
Debate Pattern
Chapter 5 →
Message Passing