Pub/Sub Agent Mesh

Topics, not addresses. Agents subscribe to what they care about.

Agents publish to and subscribe to named topics on a shared bus instead of calling each other directly, so a publisher never knows who consumes its events and subscribers can be added or removed without touching the publisher.

In practiceA sensor-monitoring platform publishes `anomaly.detected` events on a shared bus; three independent agents — alerting, logging, and auto-remediation — each subscribe and react independently without knowing about each other.

Level
04 · Production
Subdomain
Runtime Architecture
Also known as
Agent Mesh, Publish-Subscribe Agents, Message Bus Coordination
Trade-off
Scalable decoupling is achieved against more complex delivery, debugging, and governance.
Native in
Amazon SNS, Amazon EventBridge, Microsoft Agent Framework, LangGraph
The mechanism

How it works.

Agents do not call each other. They publish messages to a named topic and subscribe to topics, and a broker in between delivers every message to everyone who subscribed.

1 · Set up

  1. Name the topicsOne per kind of message
  2. Agents subscribeEach to the topics it needs

2 · At run time

  1. An agent publishesTo a topic, not to a receiver
  2. The broker fans outOne copy per subscriber
  3. Each subscriber actsOn its own, at its own pace
  4. A new agent joinsIt subscribes, and the publisher does not change
Topic
A named channel. Publishers and subscribers agree on the name and on nothing else.
Broker
The component in the middle. It holds and delivers messages, so publisher and subscriber need not run at the same moment.
Delivery guarantee
At least once is common: a message can arrive twice, so a subscriber has to cope with duplicates.
Walk it through

A real run, step by step.

TaskA sensor agent publishes one message to the topic anomaly.detected. Four agents are subscribed:
Illustrative setup.
SubscriberReactionSubscribed
AlertingPages the engineer on callFrom the start
LoggingWrites the event to the incident logFrom the start
RemediationRestarts the affected pump controllerFrom the start
ReportingAdds the event to the weekly reportThree months later, with no change to the sensor agent
What this shows: the sensor agent published once and does not know that four agents reacted, or that one of them did not exist when it was written. The mesh is the transport; a choreography is the workflow built on top of it. The price: when remediation fails to react, the publisher never learns of it, and duplicates, ordering and the question of who may subscribe all have to be handled.
In code

The pattern in code.

Plain Pythonpython
class Broker:
    def __init__(self):
        self.subscribers = {}  # topic -> list of callbacks

    def subscribe(self, topic, callback):
        self.subscribers.setdefault(topic, []).append(callback)

    def publish(self, topic, message):
        # one copy per subscriber
        for callback in self.subscribers.get(topic, []):
            callback(message)  # the publisher never sees who they are

bus = Broker()
bus.subscribe("anomaly.detected", alerting_agent)
bus.subscribe("anomaly.detected", logging_agent)
bus.subscribe("anomaly.detected", remediation_agent)
bus.publish("anomaly.detected", {"sensor": "pump-7", "value": 9.4})
Fit

Use it, or not.

When to reach for it

  • Many agents or services are loosely coupled.
  • Events go to multiple receivers.
  • Extensibility without central dependencies is important.

When it backfires

  • Direct synchronous calls suffice.
  • Message ordering and delivery are unresolved.
  • Observability is not established.
Pitfalls

Two ways this pattern will hurt you.

Topic taxonomy rots

Topics are coined ad-hoc; near-synonyms multiply; agents subscribe to one and miss messages published to the other. The naming is the system's bug surface.

Countermeasure

Centralize topic definitions in a registry with descriptions and ownership. Reject publishes to unregistered topics at the broker.

At-least-once delivery double-processes an event

The bus redelivers an event after a consumer ack times out. A non-idempotent handler runs the side effect twice — a second charge, a duplicate order, a doubled metric.

Countermeasure

Make handlers idempotent keyed by event id, and dedupe within a window at the consumer; never assume exactly-once from the broker.

Framework support

Where Pub/Sub Agent Mesh is native.

Amazon SNSServicetopic fan-outNative
Amazon EventBridgeServiceevent bus that routes events to subscribersNative
Microsoft Agent Frameworkmessage-bus agentsNative
LangGraphevent-bus runtimeNative
Sources

Where this pattern comes from.

  1. Enterprise Integration PatternsIn the source list

Search

Search patterns, frameworks, and pages.