IO + Adapters (NextEndpoint, Express, etc.)

The IO layer turns an AgentNetwork into an HTTP API. Built-in adapters: NextEndpoint (Next.js) and ExpressEndpoint (Express).

Exposing a Network

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

expose() Options

Option
Description

protocol

'sse' (currently the only option)

auth

Per-request auth callback: async (req) => { allowed, message?, status? }

select.channels

Channel(s) to stream from (string or string[])

select.events

Filter to specific event names (string[])

startEventName

Event name published when request arrives (default: 'request')

onRequest

Callback before streaming; must call emitStartEvent() if provided

plane

Optional: reuse existing EventPlane

NextEndpoint

Maps ExposedAPI to Next.js App Router handlers. Handles Request, auth, payload extraction, SSE response.

ExpressEndpoint

Requires express.json() (or body-parser) for POST. Handles client disconnect and res.flush() when available.

Response Format

Events are streamed as SSE:

Full Example: Next.js Streaming API

See Also

Last updated