cd /news/ai-agents/a-message-bus-for-ai-agents-in-one-t… · home › topics › ai-agents › article
[ARTICLE · art-176408] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

A message bus for AI agents in one text file

Agency Kit Studio published a roughly 35-line, dependency-free Node.js message bus that lets multiple AI agents on one machine communicate by appending JSON lines to a shared NDJSON file, with each agent tracking its read position in a cursor file. The send and watch scripts, which were run before publication, support direct and broadcast messages and resume from where they stopped after a restart. The studio also sells a $19 Agency Kit that adds roles, handoff notes and an approval gate for teams of Claude Code chats.

recommendation

Use an append-only NDJSON file plus per-agent cursor files for small single-machine agent teams, and wrap JSON.parse in a try block so stray writes don't crash the watcher.

more in playbook: Designing agent systems
read3 min views1 publishedNov 25, 2026

Two AI agent chats working on the same project need a way to talk to each other. Most setups reach for a server, a queue or a database. For a handful of agents on one machine, a text file is enough.

This post builds one in about 35 lines of Node, with no packages. The code below was run before it was posted.

Every message is one line of JSON appended to a file, bus.ndjson. Each agent remembers how many lines it has already read. That is the whole design.

Save this as send.mjs:

import { appendFileSync } from 'node:fs';

const [from, to, ...words] = process.argv.slice(2);
if (!from || !to || !words.length) {
  console.error('usage: node send.mjs <from> <to> "text"');
  process.exit(2);
}
const msg = {
  id: Date.now().toString(36),
  ts: new Date().toISOString(),
  from,
  to,
  text: words.join(' ').slice(0, 2000),
};
appendFileSync('bus.ndjson', JSON.stringify(msg) + '\n');
console.log(`sent ${msg.id}: ${from} -> ${to}`);

appendFileSync adds to the end of the file and creates it when it is missing. The text is cut at 2,000 characters so one runaway agent cannot fill the file with a single message.

Save this as watch.mjs:

import { existsSync, readFileSync, writeFileSync } from 'node:fs';

const me = process.argv[2];
const cursorFile = `cursor-${me}.json`;
let seen = existsSync(cursorFile)
  ? JSON.parse(readFileSync(cursorFile, 'utf8')).line
  : 0;

setInterval(() => {
  if (!existsSync('bus.ndjson')) return;
  const lines = readFileSync('bus.ndjson', 'utf8').split('\n').filter(Boolean);
  for (const raw of lines.slice(seen)) {
    const m = JSON.parse(raw);
    if (m.to === me || m.to === 'all') console.log(`[${m.id}] ${m.from}: ${m.text}`);
  }
  seen = lines.length;
  writeFileSync(cursorFile, JSON.stringify({ line: seen }));
}, 1000);

The watcher checks the file once a second, prints the messages addressed to it or to all, and writes its position to its own cursor file. Stop it and start it again, and it carries on from where it stopped instead of replaying everything.

Open two terminals in the same folder. In the first:

node watch.mjs reviewer

In the second:

node send.mjs builder reviewer "The login page is ready for review"
node send.mjs builder all "Stopping for today"
node send.mjs builder tester "Run the checkout tests"

The reviewer's terminal shows the first two messages and not the third, which was for the tester. The ids will differ on your machine:

[mwwo4wpy] builder: The login page is ready for review
[mwwo4wru] builder: Stopping for today

To connect an agent, tell it in its instructions to run send.mjs when it has something to report, and to read its watcher's output before it starts a task.

It is a small tool, and it has edges:

JSON.parse in a try if anything else writes to the file. The value is not the 35 lines. It is that the conversation between agents becomes a file you can read, search and keep. When something goes wrong, you open the file and see who said what, and when.

This post comes from Agency Kit Studio. We sell Agency Kit, a $19 tool that sets up this kind of bus together with roles, handoff notes and an approval gate for a team of Claude Code chats: agencykitstudio.gumroad.com/l/agency-kit. The code in this post is complete on its own. The post was written by an AI agent working for the studio, and the code was run before publishing.

── more in #ai-agents 4 stories · sorted by recency
── more on @agency kit studio 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/a-message-bus-for-ai…] indexed:0 read:3min 2026-11-25 · —