Socket.IO Gateway
createAgentGateway() attaches real-time handlers to a Socket.IO server. Clients emit agent.run or team.run and receive streaming chunks, tool events, and final output over WebSockets.
Installation
Basic Setup
Explicit wiring
Auto-discovery (zero-wiring)
Agents and teams auto-register into a globalregistry. The gateway reads from it dynamically — entities created after the gateway starts are immediately reachable.
serve:
GatewayOptions
Server
required
Socket.IO server instance.
Record<string, Agent>
Map of agent names to Agent instances.
Record<string, Team>
Map of team names to Team instances.
Servable[]
Mixed array of Agent and Team instances. Automatically classified. An alternative to passing
agents and teams separately.Registry | false
Controls live auto-discovery. Defaults to the global
registry — all auto-registered entities are available. Pass a custom Registry instance, or false to disable auto-discovery and only serve explicitly passed entities.string
default:"/agentium"
Socket.IO namespace. Clients connect to
http://host/agentium (or your namespace).(socket, next) => void
Socket.IO middleware for authentication. Call
next() to allow, or next(new Error("Unauthorized")) to reject.Toolkit[]
Toolkit instances whose tools are exposed via
tools.list event. Useful for UI tool discovery.Record<string, ToolDef>
Named tools exposed via
tools.list. Merged with toolkit tools (explicit entries take precedence).Events
Client → Server
Server → Client
Listing Agents & Teams
Use acknowledgement callbacks to query registered entities:Real-Time Chat Example
Server:With Authentication
apiKey in the event payload or in handshake.auth:
Session Continuity
UsesessionId to maintain conversation context across multiple agent.run calls:
Voice Gateway
For real-time voice over Socket.IO, see the dedicated Voice Agents docs. ThecreateVoiceGateway() function streams audio between browser clients and VoiceAgent instances using the same Socket.IO server.
Voice Gateway Security
The voice gateway validates all incoming data to prevent abuse:- Audio data (
voice.audio): Must be a string with a maximum size limit.Buffer.from()decoding is wrapped intry/catchto handle malformed base64 data. - Text data (
voice.text): Must be a string with a maximum length limit. - Session cleanup:
session.close()errors invoice.stopare caught and logged instead of crashing the server.
Browser Gateway
For live browser agent observation over Socket.IO, see the Browser Agents docs. ThecreateBrowserGateway() function streams screenshots, actions, and step events from BrowserAgent runs to connected clients.