← Table of Contents · Page 472 of 868
COMMUNICATION AND PROTOCOLS BETWEEN AGENTS
Part 2 of 9
MESSAGE BUSES AND GRAPH EDGES AS COMMUNICATION PATHS
A message bus is a shared channel to which agents publish messages and from which they receive messages, so that agents communicate through the bus rather than directly with each other.
This approach is often called publish and subscribe.
An agent that publishes a message puts it on the bus tagged with a type, such as "resume_parsed" or "report_ready."
An agent that subscribes tells the bus which types of messages it wants to receive, and the bus delivers matching messages to it.
The big advantage is loose coupling.
Coupling is how tightly two parts of a system depend on each other.
Tight coupling means that if you change one part, you must change the other.
With a bus, the publisher does not need to know who is listening, and the listener does not need to know who is speaking.
You can add a new logging agent or a new reviewer agent by simply subscribing it, without touching existing agents.
A bus also gives you a natural place to record everything.
Because all messages flow through one channel, you can log them in order, making debugging and auditing far easier, connecting to the logging ideas from Chapter 29.
The disadvantages are that the bus becomes a critical piece of infrastructure, and that message flows are less obvious when reading the code, since the connections are implicit, not written out as direct calls.
Good message types, clear naming, and good logs help.
The other main way to describe communication paths is a graph.
A graph, in the computer science sense, is a set of points called nodes connected by lines called edges.
Here, each node is a step or an agent, and each edge is an allowed path for work or information to travel from one node to another.
You may recall from Chapter 10 that control flow can be drawn as nodes and edges.
In a multi-agent graph, an edge from node A to node B means that A may send its output to B.
Edges can be fixed, meaning always go from A to B, or conditional, meaning go to B if one condition holds and to C otherwise.
Edges can also loop back, letting a reviewer send a draft back to the writer for another pass.
Drawing communication as a graph forces you to be explicit about who can talk to whom, which is also valuable for safety, because a path that does not exist cannot be abused.
A message bus and a graph are not rivals.
You might use a graph to define the main flow of work, and a bus to carry side channel messages such as logs, progress notices, and alerts.
Advertisement
Read Aloud:
0:00 / 0:00