swarmbus

The buzz between your agents.
Reactive pub/sub messaging for AI agents — no polling, instant delivery. Runs on mosquitto (MQTT); local or multi-machine.
Every agent is a peer. The broker is infrastructure. There is no orchestrator and no central server.
Agent A (Planner) Agent B (Coder)
AgentBus(embedded) AgentBus(embedded)
│ │
└────────────┬──────────────┘
mosquitto
(system service)
Each agent embeds an AgentBus instance; the swarm emerges from their shared broker.
Quickstart — two agents talking
The worked example below gets Planner and Coder exchanging messages in under 5 minutes. It's the reference shape; every other integration path is a variation on it.
1. Broker
sudo apt install mosquitto mosquitto-clients # Debian/Ubuntu/RPi
# or: bash scripts/setup-mosquitto.sh
The broker runs as a system service on port 1883 after install. For cross-machine use, run mosquitto on one reachable host and point each agent at it with --broker <host>. Tailscale or a VPN is recommended for untrusted networks.
2. Install the CLI
pip install "swarmbus-py[mcp]"
3. Set up agents with swarmbus init
This is the part most people miss. For an agent to receive messages reactively (no polling), a long-lived listener process must be running — it holds the MQTT subscription and bridges incoming messages into a file the agent session can read.
swarmbus init handles this end-to-end in one command:
swarmbus init --agent-id planner
swarmbus init --agent-id coder
Each init run:
- Installs mosquitto (if not already running)
- Installs the systemd user unit for this agent
- Installs the host plugin (CC or OpenClaw) if
--host-type is given
- Runs
swarmbus doctor to verify everything is green
Use --host-type cc for Claude Code, --host-type openclaw for OpenClaw, or omit it for archive-only (no reactive wake). Use --broker tailscale for cross-machine setups. See swarmbus init --help for all flags.
Full walk-through: docs/agent-onboarding.md.
4. Send — and always archive
From any shell, script, or agent session:
# Set once so every send archives automatically:
export SWARMBUS_OUTBOX=~/sync/planner-outbox.md
swarmbus send --agent-id planner --to coder --subject "hi" --body "got a minute?"
SWARMBUS_OUTBOX (or --outbox per call) appends every outbound message to a file using the same format as the receiver's inbox. Your own sent-log and received-log are now structurally identical and can be merged into one conversation view. Always set this when running under a real agent identity — an unarchived send is a dropped audit trail.
Multi-agent safety. If two agents might share the same shell environment, a bare SWARMBUS_OUTBOX=/path/planner-outbox.md leaks into both. Two fixes, pick one (or use both):
Resolution order (highest first): --outbox flag, SWARMBUS_OUTBOX_<ID>, SWARMBUS_OUTBOX, [outbox] path in the config file, none.
Before an append would take the outbox past 10 MiB, send renames it to <name>.<UTC time>Z.md next to it (for example planner-outbox.20261017T101500123456Z.md) and starts a new one. It keeps the newest 10 rotated files and deletes older ones. Set SWARMBUS_MAX_OUTBOX_BYTES / --outbox-max-bytes (0 = never rotate) and SWARMBUS_KEEP_OUTBOX_FILES / --outbox-keep (0 = keep all). Readers that follow the file by offset and inode (swarmbus tail --inbox <outbox>, scripts/inbox-watch.sh) start again at the top of the new file. Whatever they had not read yet is at the end of the newest rotated file.
Coder's inbox file grows immediately; her next session turn sees it. That's the receive path whenever the listener daemon is running for coder.
swarmbus list # who's online right now?