injectAgent()
injectAgent() is the LangGraph adapter for Angular. It connects to a LangGraph Platform assistant, consumes the LangGraph SDK event stream, and projects the result into the runtime-neutral Agent contract used by @threadplane/chat.
Call it in an Angular injection context, usually as a component field initializer. The returned object exposes Angular Signals for UI state and async methods for user actions.
#Overloads
#No-arg form
Returns the default-typed agent. state() and value() are Record<string, unknown>. Use this form when your component does not need to read typed state fields.
#Typed ref form (recommended for typed state)
Pass a typed ref handle created with createAgentRef<T>() from @threadplane/chat. Returns a LangGraphAgent<T> where state() and value() are typed as T. The same ref is passed to provideAgent() to bind the configuration.
createAgentRef<T>(debugName?) is exported from @threadplane/chat; the ref carries the state shape T. For typed interrupt payloads, pass the BagTemplate as the second generic at the inject site — injectAgent<T, Bag>(ref) — as shown in the Interrupts guide.
Pair it with provideAgent() at bootstrap to configure the API URL, assistant id, thread persistence, and transport:
#Runtime-neutral surface
These fields are stable across runtime adapters and are what chat components consume.
| Field | Type | Description |
|---|---|---|
messages() | Message[] | Runtime-neutral chat messages with role, content, optional toolCallId, citations, reasoning, and raw extras. |
status() | 'idle' | 'running' | 'error' | UI lifecycle status. LangGraph loading and reloading both map to running. |
isLoading() | boolean | Convenience signal for active streaming. |
error() | unknown | Latest runtime error, when present. |
toolCalls() | ToolCall[] | Tool calls projected into the chat contract. |
state() | Record<string, unknown> | Latest state values projected as a plain object. |
submit(input, opts?) | Promise<void> | Submit a user message, resume payload, and/or state patch. |
stop() | Promise<void> | Stop the active run. |
regenerate(index) | Promise<void> | Remove the assistant message at index and all following messages, then rerun from the preceding user message. |
interrupt() | AgentInterrupt | undefined | Optional current interrupt, when the backend pauses for human input. |
subagents() | Map<string, Subagent> | Optional subagent streams keyed by tool-call id. |
#LangGraph-specific surface
injectAgent() also returns LangGraph-specific signals and helpers for apps that need the raw platform model:
value()andhasValue()for raw state values.langGraphMessages(),langGraphToolCalls(), andlangGraphHistory()for raw SDK-shaped data.history(),branch(),setBranch(), andexperimentalBranchTree()for checkpoint and time-travel UIs.queue(),joinStream(), andswitchThread()for persisted threads and queued runs.getSubagent(),getSubagentsByType(), andgetSubagentsByMessage()for subgraph/subagent inspection.
#Submit and resume
Use the runtime-neutral submit shape for normal chat input:
Resume an interrupt with resume; combine it with state when the resume action also needs to update graph state:
LangGraph run options are still accepted as the second argument:
#Regenerate semantics
regenerate(assistantMessageIndex) has replace semantics. It keeps the user message before the selected assistant message, removes the selected assistant message and every later message, synchronizes that rollback with LangGraph state when possible, then reruns with no new user message appended.
The method throws when the selected index is not an assistant message, when no preceding user message exists, or while another response is already loading.
injectAgent() must be called during construction, inside an injection
context (e.g. a component constructor, field initializer, or a function
passed to runInInjectionContext). Calling it outside an injection context
will throw.