Skip to main content
The @agentium/transport package provides createAgentRouter() to generate a fully-featured Express router with endpoints for all your agents, teams, and workflows.

Installation

Quick Start

Explicit wiring

Pass agents, teams, and workflows by name:

Auto-discovery (zero-wiring)

Agents, teams, and workflows auto-register into a global registry when instantiated. The transport layer reads from this registry dynamically — entities created after the server starts are immediately available.
You can also pass a mixed array via serve:
This creates the following endpoints:

RouterOptions

Record<string, Agent | ServableAgent>
Map of named agents to expose. Each agent gets /agents/:name/run, /agents/:name/stream, and /agents/:name/corrections endpoints. Accepts any ServableAgent — not just the first-party Agent class.
Record<string, Team>
Map of named teams. Each gets /teams/:name/run and /teams/:name/stream endpoints.
Record<string, Workflow>
Map of named workflows. Each gets /workflows/:name/run endpoint.
Servable[]
Mixed array of Agent, Team, and Workflow instances. Automatically classified and registered. An alternative to passing agents, teams, and workflows 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.
RequestHandler[]
Express middleware applied to all routes (e.g., auth, rate limiting).
SwaggerOptions
Enable Swagger UI. See Swagger docs.
boolean | FileUploadOptions
Enable multipart file upload for multi-modal input. See File Upload docs.
Toolkit[]
Toolkit instances whose tools are exposed via GET /tools. Useful for UI tool discovery.
Record<string, ToolDef>
Named tools exposed via GET /tools. Merged with toolkit tools (explicit entries take precedence).
boolean | { mcpManager?: MCPManager; middleware?: any[] }
Enable admin routes under /admin for managing MCP servers and the toolkit catalog at runtime. Pass true to use defaults, or provide a shared MCPManager instance and authentication middleware. See MCP Admin.In production, admin routes require authentication middleware — the server will throw an error at startup if none is provided.

Request Format

JSON Request

With Session

With API Key

Response Format

Run Response

Structured Output Response

When an agent has structuredOutput configured, the structured field contains the parsed and validated JSON object:

Stream Response (SSE)

List Endpoints

When auto-discovery is enabled (default), the router exposes list endpoints with rich metadata:

Full Example with Multiple Agents

Adding Custom Middleware

Error Handling

The errorHandler middleware catches errors and returns structured JSON responses:
In production (NODE_ENV=production), 5xx errors return a generic "Internal server error" message. Stack traces and internal details are never exposed to clients.

Security

Agentium includes several built-in security measures for the Express transport layer:

Rate Limiting

createAgentRouter() includes a built-in IP-based rate limiter. The rate limiter’s internal state is periodically cleaned (every 60 seconds) to prevent unbounded memory growth from large numbers of unique IPs.

Admin Route Authentication

In production (NODE_ENV=production), mounting admin routes without authentication middleware will throw an error at startup — not just a warning. Always pass auth middleware when enabling admin routes:

Request Logging

The requestLogger middleware sanitizes URL paths to prevent log injection. Control characters and newlines are stripped before logging.

JSON Body Limits

The A2A server applies a 1MB JSON body size limit to prevent large-payload DoS attacks. See the Security page for a full overview of all security protections.