toAgent()
toAgent() is the lower-level adapter function that wraps a raw AG-UI AbstractAgent into the runtime-neutral Agent contract used by @threadplane/chat components.
Most applications should use provideAgent() instead — it constructs the HttpAgent source and calls toAgent() internally. Reach for toAgent() directly when you instantiate or customize the AbstractAgent yourself, for example to integrate a non-HTTP AG-UI transport.
#ToAgentOptions
| Option | Type | Description |
|---|---|---|
telemetry | AgentRuntimeTelemetrySink | false | Optional app-owned telemetry sink. No telemetry is emitted unless this is provided. |
#AgUiAgent
toAgent() returns an AgUiAgent, which extends the neutral Agent contract with one additional signal:
| Field | Type | Description |
|---|---|---|
customEvents() | Signal<CustomStreamEvent[]> | Custom events accumulated during a run. Resets at the start of each new run. |
The standard Agent signals (messages, status, isLoading, error, toolCalls, state, interrupt) and actions (submit, stop, regenerate) are all present.
#CustomStreamEvent
CustomStreamEvent is the element type of AgUiAgent.customEvents:
Custom events are surfaced from AG-UI CUSTOM protocol events whose name is not on_interrupt. The on_interrupt event is routed to the interrupt signal instead.
Read the accumulated events after a run by calling the signal — inside an effect, it re-runs as new events arrive:
#Lifecycle note
The returned AgUiAgent does not manage its own lifetime. When using DI via provideAgent(), the provider's destroy hook handles cleanup. When calling toAgent() directly, treat the returned agent's lifecycle as tied to the AbstractAgent instance you constructed.