Agent Communication and Collaboration

Learn how agents work together: agent-to-agent communication, message passing, shared context such as a blackboard, and collaborative problem solving with roles like researcher, writer and reviewer.

28 minIntermediateCode Examples

The Core Idea: Agents on a team cooperate by passing messages and by sharing a common context. A clear message format, a shared blackboard and defined roles let agents solve problems together instead of repeating or contradicting each other.

  1. Beginner: Agent-to-Agent Communication

When several agents work together, they need a way to talk. In most systems an agent's output simply becomes another agent's input. There are two common ways:

StyleHow it worksGood for
Direct messagesOne agent sends a message to a named agentClear handoffs
Shared context (blackboard)Agents read and write a common workspaceMany agents using the same facts
BroadcastOne message goes to everyoneAnnouncements, status updates

Remember: Agents do not understand each other by magic. Everything they know about the others is what is written in messages and shared context.

  1. Beginner: Message Passing

A good message is structured so the receiver knows what to do with it:

FieldExample from the code
fromresearcher
towriter
kindnotes, draft, revise, approved
contentThe text or data being passed
1
Send: An agent puts a message on the bus.
2
Deliver: The system routes it to the named agent.
3
Handle: The receiver reads the kind and reacts.
4
Reply: It may send a new message, or finish.

In the code: The reviewer rejects the first draft with a revise message. The writer then sends a second draft, and the reviewer approves. Six messages in total.

  1. Medium: Shared Context

Sending big documents in every message is wasteful. Instead, agents write large or shared information to a blackboard (a shared store) and pass only a short pointer in messages.

On the blackboardIn a message
The 3 collected facts3 facts saved on the blackboard
The full draftThe short draft text for the reviewer

Benefits: Less duplicated text, a single source of truth, and an easy record of the work.

Risks: Two agents can overwrite each other, and wrong information on the blackboard spreads to everyone. Use version checks and validate what is written.

  1. Medium: Collaborative Problem Solving

Teams solve problems best when roles are clear and each agent checks another agent's work:

RoleJobHands over
ResearcherCollects facts and sourcesNotes to the writer
WriterTurns notes into a draftDraft to the reviewer
ReviewerChecks quality and accuracyApproval or a revision request

Why a reviewer helps: A separate agent with a different instruction is more likely to catch mistakes than the writer re-reading its own work. Give the reviewer concrete criteria, not just check it.

Debate and critique
Another pattern has agents argue for different answers, and a judge picks the best. It can improve difficult reasoning at a higher cost.

  1. Advanced: Making Communication Reliable

ProblemFix
Vague messagesUse a fixed format with a kind field
Endless back-and-forthLimit rounds, as the reviewer loop did
Lost messagesKeep a log and acknowledge important ones
Wrong handoffValidate each message before it is used
Too much chatterSend only what the receiver needs
Conflicting factsOne source of truth, with version checks

Reminder: Every message costs tokens and adds a possible error. Agents should communicate as little as possible, but as clearly as necessary.

  1. Visual Explanation: Six Messages and a Shared Blackboard

The figure follows the six messages exchanged in the code, then shows how messages and the shared blackboard divide the work.

Part 1 · The Message Flow in the CodeSix messages
ResearchMessages 1 and 2
User gives the task
↓
Researcher saves 3 facts on the blackboard
↓
Researcher tells the writer
↓
Notes ready
Write and reviewMessages 3 and 4
Writer drafts
↓
Reviewer asks for a summary
↓
Revision requested
Revise and approveMessages 5 and 6
Writer adds the summary
↓
Reviewer approves
↓
Report delivered
Part 2 · Messages vs. the BlackboardWhere information lives
Message
Short
Who, what kind, a pointer.
Blackboard
Shared
Facts, drafts, results.
Roles
Clear
Researcher, writer, reviewer.
Limit
Rounds
Stop endless back and forth.
Click to see why a separate reviewer helpsCompare ▼
A reviewer with its own criteria looks at the draft fresh. In the code, it catches a missing summary that the writer left out and sends a precise revision request.

Part 1 groups the six messages into research, write and review, and revise and approve. Part 2 compares messages with the blackboard. Open the bar for the value of a separate reviewer.

  1. Python Implementation: Message Passing and a Shared Blackboard

This script runs three agents (researcher, writer, reviewer) that communicate only by messages and a shared blackboard. The reviewer rejects the first draft, the writer revises it, and the reviewer approves it. A log shows every message.

message_passing.pyPython 3.10+ · standard library only
from collections import deque blackboard = {}                               # shared context every agent can readmessages = deque()                            # the message buslog = [] def send(sender, to, kind, content):    messages.append({"from": sender, "to": to, "kind": kind, "content": content})    log.append(sender + " -> " + to + " [" + kind + "]: " + str(content)) def researcher(msg):    if msg["kind"] == "task":        blackboard["facts"] = ["agents use tools", "agents loop", "agents need limits"]        send("researcher", "writer", "notes", "3 facts saved on the blackboard") def writer(msg):    if msg["kind"] == "notes":        blackboard["draft"] = "Report using " + str(len(blackboard["facts"])) + " facts"        send("writer", "reviewer", "draft", blackboard["draft"])    elif msg["kind"] == "revise":        blackboard["draft"] += " plus a summary"        send("writer", "reviewer", "draft", blackboard["draft"]) def reviewer(msg):    if msg["kind"] == "draft":        if "summary" in msg["content"]:            send("reviewer", "user", "approved", msg["content"])        else:            send("reviewer", "writer", "revise", "please add a summary") AGENTS = {"researcher": researcher, "writer": writer, "reviewer": reviewer} send("user", "researcher", "task", "Write a short report about agents")while messages:    message = messages.popleft()    if message["to"] in AGENTS:        AGENTS[message["to"]](message) print("\n".join(log))print("Messages exchanged:", len(log), "| blackboard keys:", sorted(blackboard))
EXPECTED OUTPUT (your numbers may differ slightly)
user -> researcher [task]: Write a short report about agents
researcher -> writer [notes]: 3 facts saved on the blackboard
writer -> reviewer [draft]: Report using 3 facts
reviewer -> writer [revise]: please add a summary
writer -> reviewer [draft]: Report using 3 facts plus a summary
reviewer -> user [approved]: Report using 3 facts plus a summary
Messages exchanged: 6 | blackboard keys: ['draft', 'facts']

The log shows the entire collaboration. Facts live on the blackboard, while the messages stay short. The review loop ends after one revision. In real systems each agent would be a model call with its own instructions, but the communication pattern is the same.

Knowledge Check

Question 1: Why use a shared blackboard in addition to messages?
Question 2: Why limit the number of back-and-forth rounds between agents?

Key Points

✓Agents cooperate through message passing, a shared context, or both.
✓Use a structured message format with from, to, kind and content.
✓A blackboard stores shared facts and drafts, and messages carry short pointers.
✓Clear roles and a separate reviewer improve quality.
✓Limit rounds, log messages and validate handoffs.
✓Communicate as little as possible but as clearly as necessary.

The Big Picture

Collaboration in One Line

Clear roles + structured messages + a shared blackboard + a reviewer + a round limit

Good communication design is what separates a team of agents from a crowd of agents.

Up Next: Teams need a shape. In Multi-Agent Architectures you will compare supervisor, hierarchical, sequential, parallel and peer-to-peer designs.