SHEPHERDdocs Search the docs/ v0.5.3-beta
On this pageConceptsTopicsPartitions and keysConsumer groupsReading messagesWhat agents do on the busTopic filters in patternsCapping a topicWatching the busPatterns for using the bus well

Topics and events

The event bus: topics, partitions, consumer groups and how agents use them.

Works inDesktop appTerminal UICLI

Agents in a team do not call each other. They publish messages to topics and read messages from topics. The bus keeps every message, so a slow or restarted agent catches up, and you can replay what happened.

This is the same model event streaming systems use, scaled down to run inside Shepherd with no extra service.

Concepts

TermMeaning
TopicA named stream of messages, split into partitions
PartitionAn ordered log inside a topic. Order is guaranteed only within one partition
OffsetThe position of a message in its partition, starting at 0
KeyOptional text. The same key always goes to the same partition
Consumer groupA set of agents that share a topic's partitions. Each message goes to exactly one member
Commit (ack)A consumer confirms it processed messages up to an offset
LagHow many messages a group has not committed yet
ReplayRead old messages again without moving any offsets

Messages are persisted in Shepherd's state, so they survive restarts.

Topics

Topics of a pattern are created when the pattern runs. You can also create your own:

$ shepherd topic create notices --partitions 2
created topic notices (2 partitions)
$ shepherd topic list
NAME     PARTITIONS  MESSAGES
notices  2           0

Publishing to a topic that does not exist creates it with one partition.

Partitions and keys

$ shepherd topic publish notices "hello team" --from me
published message - to notices[0] (offset 0)
$ shepherd topic publish notices "second notice" --from me
published message - to notices[1] (offset 0)
  • Without --key, messages are spread across partitions in turn. This is what you want to share work among workers.
  • With --key, the same key always lands in the same partition. This keeps related messages in order (for example every message about one task).
  • --partition <p> pins a partition explicitly.

Rule of thumb: for N parallel workers, use a topic with at least N partitions and publish without a key. If everything shares one key, one partition gets all the work and one worker does it all.

Consumer groups

Agents that declare the same group in a pattern divide the topic's partitions among themselves. Each message is delivered to one member of the group, so a group is a work queue. Agents in different groups each get every message, so separate groups are broadcast.

$ shepherd topic groups orders
TOPIC   GROUP        MEMBERS  COMMITTED  TOTAL  LAG
orders  worker-pool  2        -          2      p0:1, p1:1

Here two workers share orders; one message is waiting on each partition. When an agent subscribes without naming a group, it keeps the group the run assigned, or gets a group of its own named after its id (so it receives everything).

Reading messages

$ shepherd topic tail notices
[2026-11-09T16:38:40Z] notices[0]:#0 from me: hello team
[2026-11-09T16:38:40Z] notices[1]:#0 from me: second notice

$ shepherd topic tail notices --partition 0 --limit 20
$ shepherd topic replay notices --partition 0 --from 0

tail shows recent messages. replay rereads history from an offset and never changes what consumers have committed, so it is safe for debugging.

Add --json to any of these for structured output.

What agents do on the bus

Agents use six MCP tools (or the shepherd-events skill, which explains them):

ToolPurpose
publishWrite a message to a topic
subscribeJoin a topic (agents in a run are already subscribed to theirs)
pollFetch messages not yet confirmed
ackConfirm messages up to an offset
replayReread history without moving offsets
list_topicsSee the topics that exist

Two details matter for agent prompts:

  • Do not pass group to subscribe unless you mean to change the consumption group. The run already set it up.
  • Do not pass key or partition when publishing unless ordering really matters. Without a key the bus spreads messages across partitions and therefore across the members of a group.

Agents without MCP support get messages typed into their terminal as [shep] from <role>#<n>: ... when their pane is idle.

Waking idle agents

Publishing writes a short notice into the terminal of every idle subscriber except the publisher: 1 new message on 'results': use poll. This is what makes a team event-driven: an agent can finish its turn and be woken when there is work for it, instead of polling in a loop.

A run counts as done when every agent is idle and nothing has been published for run_quiescence_secs. A new message reopens it.

Topic filters in patterns

A topic in a pattern can declare an informational filter, a prefix agents put at the start of a message. The blackboard template uses it so entries read hypothesis: ..., validation: ..., synthesis: .... It is a convention agents follow, not a server-side rule.

topics:
- name: blackboard
  partitions: 1
  filter: hypothesis

Capping a topic

A topic in a pattern can have a hard limit, max_messages. Once the topic holds that many messages the next publish is refused with a message telling the agent to stop and tell the human what is unresolved, and the run shows as stalled. The count survives reopening the bus, so it holds however the agents reach it.

topics:
- name: board
  partitions: 1
  max_messages: 10

Use it on feedback loops (a generator and a critic, a test writer and a coder) so they cannot argue for ever and spend tokens: the built-in loops set it, next to the round limits in their prompts. Without max_messages a topic has no limit.

Watching the bus

  • CLI: shepherd topic tail <topic> follows what agents say to each other. shepherd bus clean --force deletes every message of the bus (agents lose its history).
  • Terminal UI, Events view (7): two sub-views, switched with Tab. *Topics and Flow* shows live messages with offset, partition, sender, key, type and content; Space pauses, r replays from an offset, / filters, n creates a topic (name or name:partitions), m sends a message to the selected topic and C clears the bus after asking. *Pattern Runs* shows each run, with p to pause or resume and K to stop.
  • Native app, Events view: a feed with the time, the sender, and a color per emitter, so you can see who said what at a glance. + Topic creates a topic and Send message sends one to the open topic.

Patterns for using the bus well

  • Work queue: one topic with many partitions, one consumer group of workers, publish without a key.
  • Ordered stream per item: key by an id (task_id) so every message about one item stays in order.
  • Fan-out: several agents each in their own group on the same topic, so each sees every message.
  • Request and reply: one topic for requests, another for results, as in orchestrator-worker.
  • Shared notes: one partition and a prefix convention, as in blackboard.

See Patterns for the ten built-in patterns built from these pieces.

Was this page useful?Suggest an edit on GitHub