Agent-to-Agent Protocols
Just like humans use email, Slack, or Jira to communicate and assign tasks, AI agents need standardized messaging protocols so they can talk to each other without losing context or hallucinating.
Why Does This Exist?
When building Multi-Agent Systems, you often have a team of specialized agents. For example:
- Agent A (Researcher): Browses the web for facts.
- Agent B (Writer): Takes facts and writes a blog post.
If Agent A just sends the raw text "The capital is Paris" to Agent B, Agent B might get confused. Who sent this? What am I supposed to do with it? Is this the whole document or just a fragment?
Agent-to-Agent Protocols define the strict data structures (usually JSON) that agents must use to communicate. Just like TCP/IP defines how computers talk over the internet, agent protocols define how LLMs pass tasks, share context, and report errors to one another.
Think of It Like This
The Corporate Memo
Without Protocol: A coworker walks by your desk, throws a piece of paper that says "500" at you, and walks away. You have no idea what it means.
With Protocol (The Memo): A coworker hands you a formalized memo.
To: John
From: Accounting
Subject: Q3 Expenses
Action Required: Approve by Friday
Body: 500
You instantly know exactly what to do.
How It Actually Works
While there is no single industry standard yet (though frameworks like AutoGen and LangGraph are establishing norms), a good agent protocol usually wraps every LLM generation in an "envelope" before sending it to another agent.
The Envelope Structure
An agent message usually contains:
- Metadata:
Sender_ID,Receiver_ID,Timestamp - Intent: What the sender expects the receiver to do (
REQUEST_TASK,PROVIDE_INFO,REPORT_ERROR). - Context / State: The shared memory of the team (e.g., "We are on step 3 of 5").
- Payload: The actual generated text or JSON from the LLM.
The Parsing Mechanism
When Agent B receives the message, the Python orchestration layer parses the envelope. It injects the metadata into Agent B's System Prompt: "You received a message from Researcher Agent. The intent is REQUEST_TASK. Here is the payload..." This ensures Agent B understands exactly why it is being prompted.
Show Me the Code
This conceptual code shows how you might structure the Python communication layer between two agents.
import json
# 1. Define the Standard Protocol Envelopeclass AgentMessage: def __init__(self, sender, receiver, intent, payload, shared_state=None): self.sender = sender self.receiver = receiver self.intent = intent # e.g., "TASK_ASSIGNMENT", "CLARIFICATION", "FINAL_RESULT" self.payload = payload self.shared_state = shared_state or {} def to_json(self): return json.dumps(self.__dict__, indent=2)
# 2. The Orchestrator that passes messagesdef handle_communication(message: AgentMessage): print(f"--- Message Transmitted on Bus ---") print(f"Routing from [{message.sender}] -> [{message.receiver}]") print(f"Intent: {message.intent}") # In reality, this would route the message to Agent B's specific LLM prompt loop print(f"Payload: {message.payload[:50]}...") print("----------------------------------\n")
# --- Execution ---
# Agent A (Researcher) finishes its job and needs to tell Agent B (Writer) to startresearch_results = "1. Paris is the capital. 2. Population is 2.1M."
msg = AgentMessage( sender="ResearcherAgent", receiver="WriterAgent", intent="TASK_ASSIGNMENT", payload=research_results, shared_state={"task_id": 992, "deadline": "urgent"})
# Send it over the wirehandle_communication(msg)
# -> --- Message Transmitted on Bus ---# -> Routing from [ResearcherAgent] -> [WriterAgent]# -> Intent: TASK_ASSIGNMENT# -> Payload: 1. Paris is the capital. 2. Population is 2.1M....# -> ----------------------------------Watch Out For
Context Duplication
If you have 5 agents talking to each other, and every agent attaches the entire chat history to every message they send, the message size grows exponentially. By message 10, the envelope contains 50,000 tokens of duplicate history, blowing out your Context Budget. Good protocols implement State Pointers. Instead of passing the whole history, the message just contains session_id: 123. The receiving agent queries a central database for session_id: 123 to read the history itself.
The Quick Version
- If you just pipe the raw text output of Agent A into the input of Agent B, the system will eventually derail due to confusion.
- Agent-to-Agent Protocols are strict JSON schemas that wrap the LLM's text.
- They act like corporate memos, defining exactly who sent the message, who is supposed to read it, and what the expected action is.
- Frameworks like Microsoft AutoGen are built entirely around these conversational protocols.
What to Read Next
- Read Multi-Agent Systems to understand the architectures where these protocols are actually used.
- Read Supervisor Pattern to see a specific hierarchy where a "Manager" agent routes these protocol messages to "Worker" agents.