provideAgent()
provideAgent() registers the singleton agent configuration for every injectAgent() call in an Angular application. Call it once in bootstrapApplication or an ApplicationConfig to wire up the LangGraph API URL, assistant id, thread persistence, and transport.
injectAgent() itself takes no arguments โ all configuration flows through provideAgent().
#Configuration options
| Option | Type | Description |
|---|---|---|
apiUrl | string | LangGraph Platform API base URL. |
assistantId | string | LangGraph assistant id to bind to. |
threadId | Signal<string | null> | string | null | Thread ID to connect to. Pass a Signal for reactive thread switching. |
onThreadId | (id: string) => void | Called when a new thread is auto-created by the transport. |
initialValues | Partial<T> | Initial state values before the first stream response arrives. |
throttle | number | false | Throttle signal updates in milliseconds. false to disable. (default 16) |
toMessage | (msg: unknown) => BaseMessage | Custom message deserializer for non-standard message formats. |
transport | AgentTransport | Optional transport instance. Defaults to FetchStreamTransport when omitted. |
clientOptions | LangGraphClientOptions | LangGraph SDK client tuning (e.g. maxRetries). See Client tuning below. |
telemetry | AgentRuntimeTelemetrySink | false | Optional app-owned telemetry sink. No telemetry is emitted unless this is provided. |
filterSubagentMessages | boolean | When true, subagent messages are filtered from the main messages signal. |
subagentToolNames | string[] | Tool names that indicate a subagent invocation. |
#Singleton model
A single provideAgent({...}) call configures the entire application. Every injectAgent() call resolves to the same configured agent.
#Test transports
transport is an object that implements AgentTransport, not an Angular class token. Create an instance before passing it to provideAgent().
Swap out the live transport for MockAgentTransport in tests by changing only
the transport field on provideAgent(). injectAgent() call sites stay
unchanged across environments.
#Client tuning (retry budget)
The LangGraph SDK retries connection failures โ including the run stream โ before throwing. With the defaults, a hard connection failure can take several seconds (multiple retries) to surface as an error, which delays your error UI. Tune the retry budget with clientOptions:
To configure it once for the whole app, provide the LANGGRAPH_CLIENT_OPTIONS token. Both the default FetchStreamTransport and the LangGraphThreadsAdapter read it, so the retry budget is set in one place:
Precedence (first defined wins, whole-object โ no per-field merge):
- A call-site
agent({ clientOptions }) - The per-agent
provideAgent({ clientOptions }) - The app-wide
LANGGRAPH_CLIENT_OPTIONStoken - The SDK default
If a dropped connection takes ~15s to show an error, the SDK is exhausting its
retry budget. Set maxRetries: 0 to fail fast, or a small number to keep a few
retries with quicker surfacing. The resulting failure is classified as a
retryable connection AgentError.
#Typed state via AgentRef
By default injectAgent() returns an agent typed as Record<string, unknown>. To thread a concrete state shape through Angular DI without restating the generic at every call site, create a typed AgentRef with createAgentRef<TState>() and pass it as the first argument to both provideAgent() and injectAgent():
The optional debugName ('trip' above) is surfaced in Angular DI error messages. AgentRef is exported from @threadplane/chat, so the same typed handle works across adapters.