Passing messages
As systems grow beyond a single agent, agents need a way to ask for work, report results, and coordinate decisions. Passing messages is the simplest way to make that happen. It gives us a clear, explicit channel for communication without forcing agents to share all their internal state or logic.
What a message represents
In a multi-agent system, a message represents an intentional communication from one agent to another. It is not raw data or shared memory, but a discrete unit of meaning: a request, a response, or a notification. Thinking in terms of messages helps us reason about interactions without tightly coupling agents together.
Representing messages as structured data
Messages work best when they are structured rather than free-form text. In Python, this usually means dictionaries or small data objects with clearly named fields. Structure makes messages easier to validate, log, and act on programmatically.
message = {
"type": "task_request",
"task": "generate_planet_page",
"target": "mars"
}
Sending messages between agents
Sending a message is simply making it available to another agent through an agreed mechanism. This might be a function call, a queue, or a shared inbox structure. The important part is that the sender does not assume how the receiver will handle the message.
outbox.append(message)
Receiving and interpreting messages
Receiving an agent treats incoming messages as inputs to its decision logic. It inspects the message structure, identifies the message type, and decides what to do next. The message itself does not force behavior; it only provides information.
incoming = inbox.pop(0)
if incoming["type"] == "task_request":
handle_task(incoming)
Using messages to request work or report results
Messages commonly flow in two directions: requests and results. A manager agent might send a task request, while a worker replies with a result message. Keeping these roles explicit makes the system easier to follow and extend.
result_message = {
"type": "task_result",
"task": "generate_planet_page",
"status": "completed",
"output_file": "mars.html"
}
Conclusion
By passing structured messages between agents, we give each agent a clear way to communicate intent without sharing internal implementation details. At this point, we are oriented: we know what messages are, how to represent them, and how they support coordination in multi-agent systems.