Phase 4: Multi-Agent Systems · 55 min · Python · Pydantic · Anthropic SDK
Agent Communication Protocols
Treat agent-to-agent messages like API calls, not chat messages.
Hiring signal: Protocol design is a systems engineering skill that most AI engineers from a data science background lack. Engineers who think about inter-agent communication like API design — with versioning, typed schemas, and backward compatibility — signal production engineering experience. This is tested in system design rounds at companies building multi-agent products.
What you will learn
- Design structured message schemas for agent-to-agent communication
- Implement a shared context object that flows through a multi-agent workflow
- Handle schema versioning when agent protocols evolve
The Problem
Free-text agent communication has three critical flaws: ambiguity (the receiving agent must infer meaning), cost (every status check requires an LLM call to parse), and fragility (natural language descriptions of results change unpredictably). Structured message schemas eliminate all three.
The principle is straightforward: treat inter-agent communication like an internal API. If you wouldn't send free-text JSON to a microservice, don't send it between agents.
Agent Message Schema Design
Every message between agents should be a typed Pydantic object. Standard fields:
class AgentMessage(BaseModel):
message_id: str # Unique ID for deduplication and tracing
schema_version: str # "1.0.0" — for migration support
from_agent: str # Sender identity
to_agent: str # Intended recipient
task_id: str # The workflow task this belongs to
payload: dict # The actual task or question
status: str # "pending" | "complete" | "failed" | "partial"
confidence: float # 0.0–1.0: how certain is the sender?
metadata: dict # Timing, costs, token counts, source refs
timestamp: str # ISO 8601
The confidence field deserves special attention. It enables downstream agents to make decisions without calling an LLM:
if result.confidence < 0.6:
# Re-research with a different source
...
elif result.confidence < 0.8:
# Add a "low confidence — verify before use" caveat
...
else:
# Proceed normally
...
This is logic that would require a full LLM call if confidence were expressed in natural language ("I'm fairly sure but not completely certain...").
Agent A sends Agent B a free-text string: "The research on topic X is done. I found some interesting things." What's wrong with this?
Even though LLMs can parse natural language, inter-agent communication should be structured for three reasons: (1) Reliability — no parsing ambiguity. (2) Logic branching — Agent B can check result.status == "complete" without calling an LLM. (3) Cost — checking a field is free; parsing free text costs tokens. Treat agent-to-agent messages like API calls, not chat messages.
Unlock the full lesson
You've read the first 2 sections. The rest of this lesson covers Shared Context Objects, Protocol Versioning, Build It, What to Practice — plus a hands-on lab, quiz, and project artifact.
Create a free account to unlock Phase 0 and Phase 1 of every course — no credit card.
Browse all courses · View pricing · DeVenture Academy