External Agents
Agentium’s runtime (registry, Express/Socket.IO gateways, queue workers, observability) is framework-agnostic. Anything that satisfies theServableAgent contract can be registered and served — the first-party Agent class is just one implementation.
The ServableAgent contract
defineExternalAgent()
The easiest way to wrap external logic. It normalizes your return value into a fullRunOutput, provides a default stream() fallback, wires up an EventBus (so observability works out of the box), and auto-registers in the global registry.
Returning rich output
Return a partialRunOutput to include usage, tool calls, or structured data — missing fields are filled with defaults:
Native streaming
By default,stream() runs to completion and yields the text as a single chunk. Provide your own generator for true streaming:
Configuration
| Property | Type | Required | Default | What it controls |
|---|---|---|---|---|
name | string | Yes | — | Registry key and route path (/agents/:name/...) |
run | (input, opts) => Promise<string | Partial<RunOutput>> | Yes | — | The agent’s logic |
stream | (input, opts) => AsyncIterable<StreamChunk> | No | run-then-yield fallback | Native streaming |
instructions | string | No | — | Shown in registry descriptions and swagger |
modelId / providerId | string | No | — | Metadata for discovery cards and API key routing |
register | boolean | No | true | Auto-register in the global registry |
eventBus | EventBus | No | fresh instance | Bring your own bus for shared observability |
Observability for free
defineExternalAgent emits the standard run lifecycle events (run.start, run.complete, run.error) on its event bus, so Tracer, MetricsExporter, and StructuredLogger work unchanged:
Registry names are labels (v2.3.2+)
Registering an agent with an existing name replaces the previous entry (last-write-wins) — names are labels, not unique keys. This means the same agent definition can be constructed repeatedly (loops, factories, concurrent requests) withoutDuplicate agent name errors. Gateways resolve a name to the most recently registered instance.
register: false (on AgentConfig or ExternalAgentConfig) for ephemeral agents that should skip the registry entirely.
Cross-references
- Express Transport — the routes every served agent gets
- Socket.IO Gateway — realtime serving
- Observability — event-bus-driven tracing and metrics