Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.m4trix.dev/llms.txt

Use this file to discover all available pages before exploring further.

The AgentNetwork orchestrates agents, channels, and the event plane. Use AgentNetwork.setup() to wire everything together.

Setup

const network = AgentNetwork.setup(
  ({ mainChannel, createChannel, sink, registerAgent, spawner }) => {
    // ...
  },
);

Setup Context

mainChannel(name)

Creates and designates the main channel. Start events are published here when the network is exposed as an API. Every network should have exactly one main channel.
const main = mainChannel('main');

createChannel(name)

Creates an additional named channel. Names must be kebab-case.
const client = createChannel('client');
const analytics = createChannel('analytics');

sink

Provides sink factories:
const client = createChannel('client').sink(sink.httpStream());
const events = createChannel('events').sink(sink.kafka({ topic: 'events' }));

registerAgent(agent)

Registers an agent and returns a binding builder:
registerAgent(myAgent)
  .subscribe(main)
  .publishTo(client);
An agent can subscribe to and publish to multiple channels:
registerAgent(routerAgent)
  .subscribe(main)
  .subscribe(feedback)
  .publishTo(client)
  .publishTo(analytics);

spawner

Creates a spawner for dynamically creating agents at runtime (multi-tenant, on-demand):
spawner(AgentFactory)
  .listen(main, spawnEvent)
  .registry({ analyst: analystFactory, writer: writerFactory })
  .defaultBinding(({ kind }) => ({ subscribe: ['main'], publishTo: ['client'] }))
  .onSpawn(({ kind, factory, payload, spawn }) => {
    const agent = factory.produce(payload.params);
    spawn(agent);
    return agent;
  });

Running the Network

const api = network.expose({
  protocol: 'sse',
  select: { channels: 'client' },
  startEventName: 'user-request',
});
See IO + Adapters.

Programmatic Run

await Effect.runPromise(
  Effect.scoped(
    Effect.gen(function* () {
      const plane = yield* network.run();
      // publish events, wait for results...
    }),
  ),
);

Accessors

network.getChannels();             // Map<ChannelName, ConfiguredChannel>
network.getMainChannel();          // ConfiguredChannel | undefined
network.getAgentRegistrations();   // Map<string, AgentRegistration>
network.getSpawnerRegistrations(); // ReadonlyArray<SpawnerRegistration>

See Also