{"slug": "a-message-bus-for-ai-agents-in-one-text-file", "title": "A message bus for AI agents in one text file", "summary": "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.", "body_md": "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.\n\nThis post builds one in about 35 lines of Node, with no packages. The code below was run before it was posted.\n\nEvery 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.\n\nSave this as `send.mjs`:\n\n``` js\nimport { appendFileSync } from 'node:fs';\n\nconst [from, to, ...words] = process.argv.slice(2);\nif (!from || !to || !words.length) {\n  console.error('usage: node send.mjs <from> <to> \"text\"');\n  process.exit(2);\n}\nconst msg = {\n  id: Date.now().toString(36),\n  ts: new Date().toISOString(),\n  from,\n  to,\n  text: words.join(' ').slice(0, 2000),\n};\nappendFileSync('bus.ndjson', JSON.stringify(msg) + '\\n');\nconsole.log(`sent ${msg.id}: ${from} -> ${to}`);\n```\n\n`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.\n\nSave this as `watch.mjs`:\n\n``` js\nimport { existsSync, readFileSync, writeFileSync } from 'node:fs';\n\nconst me = process.argv[2];\nconst cursorFile = `cursor-${me}.json`;\nlet seen = existsSync(cursorFile)\n  ? JSON.parse(readFileSync(cursorFile, 'utf8')).line\n  : 0;\n\nsetInterval(() => {\n  if (!existsSync('bus.ndjson')) return;\n  const lines = readFileSync('bus.ndjson', 'utf8').split('\\n').filter(Boolean);\n  for (const raw of lines.slice(seen)) {\n    const m = JSON.parse(raw);\n    if (m.to === me || m.to === 'all') console.log(`[${m.id}] ${m.from}: ${m.text}`);\n  }\n  seen = lines.length;\n  writeFileSync(cursorFile, JSON.stringify({ line: seen }));\n}, 1000);\n```\n\nThe 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.\n\nOpen two terminals in the same folder. In the first:\n\n```\nnode watch.mjs reviewer\n```\n\nIn the second:\n\n```\nnode send.mjs builder reviewer \"The login page is ready for review\"\nnode send.mjs builder all \"Stopping for today\"\nnode send.mjs builder tester \"Run the checkout tests\"\n```\n\nThe reviewer's terminal shows the first two messages and not the third, which was for the tester. The ids will differ on your machine:\n\n```\n[mwwo4wpy] builder: The login page is ready for review\n[mwwo4wru] builder: Stopping for today\n```\n\nTo 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.\n\nIt is a small tool, and it has edges:\n\n`JSON.parse` in a `try` if anything else writes to the file.\nThe 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.\n\n*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](https://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.*", "url": "https://wpnews.pro/news/a-message-bus-for-ai-agents-in-one-text-file", "canonical_source": "https://dev.to/agencykitstudio/a-message-bus-for-ai-agents-in-one-text-file-3dgj", "published_at": "2026-11-25 22:03:45+00:00", "updated_at": "2026-11-25 22:13:46.678574+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "ai-tools"], "entities": ["Agency Kit Studio", "Agency Kit", "Node.js", "Claude Code"], "also_reported_by": [], "takeaway": "For a handful of agents on one machine, a shared NDJSON file with per-agent line cursors gives a durable, inspectable message bus in about 35 lines of Node with no packages.", "recommendation": {"advice": "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.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/a-message-bus-for-ai-agents-in-one-text-file", "markdown": "https://wpnews.pro/news/a-message-bus-for-ai-agents-in-one-text-file.md", "text": "https://wpnews.pro/news/a-message-bus-for-ai-agents-in-one-text-file.txt", "jsonld": "https://wpnews.pro/news/a-message-bus-for-ai-agents-in-one-text-file.jsonld"}}