API Reference

Channel API

Channels are named conduits for events. They route events between agents and connect to external systems via proxies.

Creating Channels

Main Channel

TypeScript
registerAgent(router).subscribe(mainChannel);

mainChannel is the main channel the network creates; start events are published there. It is a channel, not a function, and createChannel('main') returns the same channel.

Additional Channels

TypeScript
const processing = createChannel('processing');
const client = createChannel('client');

Channel names must be kebab-case (e.g. 'main', 'client-output').

Channel Configuration

.events([...])

Optionally declare which events a channel carries. The declaration is enforced:

TypeScript
const client = createChannel('client')
  .events([responseEvent, errorEvent]);
  • An agent publishes each emitted event only to those of its publishTo channels that accept it. When none does, emit throws EmitValidationError (reason: 'channel') and the agent's onAgentError policy applies (run failure kind: 'invalid-emit').
  • An external publish (plane.publish, proxy publish / publishInbound) of an event the channel does not accept resolves false; the event is not delivered and a warning goes to the network's logger. The run is not failed, the same as an event refused because its run belongs to another principal.
  • Runtime m4trix:* events (run end, agent errors) always pass. Only the runtime publishes them: an external publish of an m4trix: name fails with ReservedEventNameError.
  • A channel without .events() carries every event.

Contradictions are caught when the network is set up: an agent that emits an event none of its publish channels accepts, or listens to one none of its subscribed channels accepts, makes AgentNetwork.setup() throw. See Wiring check.

.proxy(...proxies)

Attach one or more proxy declarations. A channel can declare multiple proxies.

TypeScript
const client = createChannel('client').proxy(proxy.sse());
const output = createChannel('output')
  .proxy(proxy.sse())
  .proxy(proxy.custom('queue', { topic: 'output-events' }));

Proxy Factories

ProxyDescription
proxy.sse()Streams events as SSE to HTTP clients
proxy.custom(kind, config, direction)Declares a user-defined proxy kind (see Custom Proxies)

Kafka and Socket.IO proxies are not built in; bridges for them are planned on top of EventTransport.

See Also