@morphixai/agent-bus
v0.2.2
Published
Parent/child/sibling messaging bus for agent runtimes — ask/reply, notifications, and subtree teardown.
Maintainers
Readme
@morphixai/agent-bus
Parent/child/sibling messaging bus for agent runtimes.
Each agent runtime owns one AgentBus node in a tree. Spawning a child agent
creates a child bus node mirroring the runtime fork; closing a node tears down
its subtree and rejects any pending asks. The bus carries three kinds of
traffic: asks (request/reply with timeout), notifications
(fire-and-forget), and internal lifecycle messages.
Install
npm install @morphixai/agent-busUsage
import { createBus, INTERNAL_TYPES } from '@morphixai/agent-bus';
const root = createBus();
const child = root.spawnChild('child-1');
// request/reply (rejects on timeout)
const answer = await child.ask({ question: 'need approval?' }, { timeoutMs: 30_000 });
// parent drains asks it must answer
for (const ask of root.drainPendingAsksForPrompt()) ask.resolve({ approved: true });
// fire-and-forget notification
child.notify({ kind: 'status', text: 'done' });
child.close(); // tear down subtreeAPI
createBus()— rootAgentBusnode.bus.spawnChild(id)— fork a child node.bus.ask(payload, { timeoutMs })— request/replyPromise.bus.notify(message)— fire-and-forget.bus.subscribe(type)— async iterator over messages of a type.bus.drainPendingAsksForPrompt()/drainUnreadNotifications()— pull buffered traffic.bus.hasUnpresentedAsks— whether asks await presentation.bus.close()— tear down subtree.INTERNAL_TYPES,BusError— message-type constants and error class.
License
MIT © MorphixAI
