Learn how AI agents exchange information and coordinate actions through structured messages, communication patterns like pub-sub and request-response, and protocols for task delegation and consensus building.

This article is part of the free-to-read AI Agent Handbook
Communication Between Agents
In the previous chapter, you saw how multiple agents can work together by specializing in different tasks. But we glossed over a critical detail: how do agents actually talk to each other? When the guest agent finishes compiling dietary restrictions, how does it pass that information to the menu agent? When the research agent finds important data, how does it tell the writing agent?
Human teams communicate through language, gestures, emails, and meetings. AI agents need their own communication mechanisms. In this chapter, we'll explore how agents exchange information, coordinate their actions, and stay synchronized while working toward shared goals.
The Communication Challenge
Let's start with a concrete problem. Imagine you have two agents:
- Agent A (Research): Finds the current price of Bitcoin
- Agent B (Analysis): Determines if now is a good time to buy
Agent B needs the information Agent A discovers. But how does Agent A send that information? And how does Agent B know it's receiving price data rather than, say, historical trends or market sentiment?
Here's what makes agent communication tricky:
Different Contexts: Each agent has its own conversation history, system prompt, and state. When Agent A says "the price is $45,000," Agent B needs enough context to understand what that means.
Timing: Agent B might need to wait for Agent A to finish its research. How does it know when Agent A is done? What if Agent A encounters an error?
Format: Should Agent A send a simple number, a structured JSON object, or a natural language description? The format affects how easily Agent B can use the information.
Reliability: What if the message gets lost or corrupted? What if Agent A sends information that Agent B doesn't understand?
Let's see these challenges in action with a simple example:
This works, but notice the limitations. The analysis agent receives raw text from the research agent. It has to parse that text and hope it contains the information it needs. There's no guarantee the format will be consistent, no way to verify the message was understood correctly, and no mechanism for the analysis agent to ask follow-up questions.
We can do better.
Message Formats: Speaking a Common Language
The first step to better communication is establishing a shared format. Just as humans might agree to communicate via email with specific subject lines and structure, agents benefit from standardized message formats.
Natural Language Messages
The simplest approach is natural language. Agent A sends a message like "I found that Bitcoin is currently trading at $45,000 with high volatility." Agent B reads this and responds accordingly.
Advantages:
- Flexible and expressive
- Easy to understand when debugging
- Works well with language models' strengths
Disadvantages:
- Ambiguous (what does "high volatility" mean exactly?)
- Hard to parse programmatically
- Prone to misinterpretation
Natural language works well for high-level coordination where precision isn't critical. For example, a coordinator agent might tell worker agents: "Focus on the Q4 data" or "Prioritize accuracy over speed."
Structured Data Messages
For precise information exchange, structured formats like JSON work better:
Now Agent B knows exactly what it's receiving. The price is a number, not a string. The volatility is quantified. The confidence score indicates how reliable this information is. The timestamp shows when the data was collected.
Let's rebuild our example with structured communication:
This structured approach gives us several benefits:
Type Safety: The message_type field lets agents verify they're receiving the expected kind of message.
Traceability: Timestamps and sender/recipient fields create an audit trail of communication.
Error Handling: Agents can send error messages in the same format, making it easy to handle failures.
Extensibility: You can add new message types without breaking existing communication patterns.
Communication Patterns
Now that we have a message format, let's explore different ways agents can communicate.
Request-Response
The simplest pattern: Agent A sends a request, Agent B sends a response.
This is synchronous. Agent A waits for Agent B's response before continuing. It's straightforward but can be inefficient if Agent B takes a long time.
Fire-and-Forget
Agent A sends a message but doesn't wait for a response. It continues with other work.
This is asynchronous and efficient, but Agent A has no way to know if the message was received or processed successfully.
Publish-Subscribe
Multiple agents can subscribe to specific types of messages. When Agent A publishes a message, all subscribed agents receive it.
This pattern works well for broadcasting information to multiple interested parties without Agent A needing to know who they are.
Here's a simple implementation:
Conversation Threads
For complex coordination, agents might need back-and-forth conversations:
This requires maintaining conversation context. Each message needs to reference the thread it belongs to:
Coordination Protocols
Message formats and patterns are building blocks. Coordination protocols define the rules for how agents work together on specific types of tasks.
Task Delegation Protocol
When one agent needs another agent to do work:
- Request: Coordinator sends a task with clear requirements
- Acknowledgment: Worker confirms it received the task
- Progress Updates: Worker sends periodic status updates
- Completion: Worker sends results or error message
- Confirmation: Coordinator acknowledges receipt
This protocol ensures both agents stay synchronized. The coordinator knows the task is being worked on, can track progress, and receives results in a predictable format. The worker has a clear structure for communicating its status.
Consensus Protocol
When multiple agents need to agree on something:
- Proposal: One agent proposes a decision
- Voting: All agents vote (agree, disagree, abstain)
- Tally: Votes are counted according to rules (majority, unanimous, weighted)
- Decision: Result is announced to all agents
Handling Communication Failures
Communication between agents isn't always perfect. Networks fail, messages get lost, agents crash. Robust multi-agent systems need to handle these failures gracefully.
Timeouts
If Agent A sends a request to Agent B and doesn't get a response within a reasonable time, it should timeout and either retry or report an error:
Retries
For transient failures, retrying can help:
Acknowledgments
For critical messages, require acknowledgments:
Real-World Communication: The A2A Protocol
Earlier we discussed the Agent-to-Agent (A2A) Protocol as a framework for multi-agent systems. Now let's look specifically at how A2A handles communication.
A2A defines standard message formats and communication patterns that work across different platforms. When agents use A2A, they can communicate even if one is built with Claude, another with GPT-5, and a third with Gemini.
Key A2A Communication Features:
Agent Discovery: Agents can find other agents by querying a registry. "Are there any research agents available?" returns a list of agents with their capabilities.
Capability Negotiation: Before communicating, agents can check if they speak compatible "languages." Agent A can ask Agent B: "Do you accept JSON input?" or "Can you return image data?"
Standardized Message Envelope: All A2A messages include metadata (sender, recipient, timestamp, message type) in a consistent format, similar to our AgentMessage class but with additional fields for authentication and routing.
Task Lifecycle Management: A2A includes built-in protocols for task delegation, progress tracking, and completion, similar to our TaskDelegationProtocol but standardized across all A2A-compatible agents.
Error Handling: A2A defines standard error codes and formats, so agents can understand what went wrong even across different implementations.
While we won't implement the full A2A protocol here (it's complex and still evolving), the patterns we've explored in this chapter align with A2A's design principles. When you build multi-agent systems, following similar patterns will make your agents more interoperable and maintainable.
Practical Considerations
As you design communication between your agents, keep these principles in mind:
Keep Messages Small: Large messages slow down communication and increase the chance of errors. If you need to share a big dataset, send a reference (like a file path or database query) rather than the data itself.
Be Explicit: Don't assume the receiving agent has context. Include enough information in each message for it to be understood independently.
Version Your Protocols: As your system evolves, message formats might change. Include version numbers so agents can handle different formats gracefully.
Log Everything: Communication logs are invaluable for debugging. When something goes wrong, being able to trace the message flow helps you find the problem quickly.
Design for Failure: Assume messages will get lost, delayed, or corrupted. Build in timeouts, retries, and error handling from the start.
Test Communication Separately: Before building complex multi-agent workflows, test that your agents can reliably exchange simple messages. Get the communication layer working first, then add sophisticated behaviors.
Looking Ahead
You now understand how agents communicate: through structured messages, following specific patterns (request-response, pub-sub, conversations), using coordination protocols (task delegation, consensus), and handling failures gracefully.
In the next chapter, we'll explore the benefits and challenges of multi-agent systems in more depth. You'll learn when the added complexity of multiple agents is worth it, what problems can arise, and how to design multi-agent systems that are robust, efficient, and maintainable.
The key insight from this chapter is that communication is the foundation of collaboration. Just as human teams need clear communication channels and protocols, AI agents need well-designed message formats and coordination mechanisms. Get the communication right, and your agents can accomplish remarkable things together.
Glossary
Acknowledgment: A message sent by a recipient to confirm that it received and understood a previous message, used to ensure reliable communication.
Asynchronous Communication: A pattern where the sender doesn't wait for a response and continues with other work, useful for fire-and-forget messages and parallel processing.
Consensus Protocol: A set of rules for how multiple agents reach agreement on decisions through proposals, voting, and tallying results according to defined thresholds.
Conversation Thread: A sequence of related messages between agents, maintained with a thread ID and message history to preserve context across multiple exchanges.
Message Broker: A component that manages publish-subscribe communication, routing messages from publishers to all subscribed agents based on topics.
Message Envelope: The wrapper around message content that includes metadata like sender, recipient, timestamp, and message type, enabling proper routing and handling.
Publish-Subscribe: A communication pattern where agents subscribe to topics of interest and receive all messages published to those topics, enabling one-to-many communication.
Request-Response: A synchronous communication pattern where one agent sends a request and waits for another agent to send back a response before continuing.
Structured Data: Information formatted in a standardized way (like JSON) with defined fields and types, making it easier for agents to parse and use reliably.
Task Delegation Protocol: A coordination protocol that defines how one agent requests work from another, including acknowledgment, progress updates, completion, and error handling.
Timeout: A mechanism that limits how long an agent waits for a response before concluding the message was lost or the recipient is unavailable.
Quiz
Ready to test your understanding? Take this quick quiz to reinforce what you've learned about agent communication patterns and protocols.





Comments