import { ... } from "@langchain/langgraph-sdk/ui";Calculates the depth of a subagent based on its namespace. Counts the number of "tools:" segments in the namespace.
Converts plain message objects within each history state's values to proper BaseMessage class instances. Returns a new array with shallow-copied states whose messages have been coerced.
Ensures all messages in an array are BaseMessage class instances. Messages that are already class instances pass through unchanged. Plain message objects (e.g. from API values/history) are converted via tryCoerceMessageLikeToMessage.
Extracts the parent tool call ID from a namespace.
For nested subagents, the namespace looks like: ["tools:parent_id", "tools:child_id", ...]
Extracts the tool call ID from a namespace path.
Namespaces follow the pattern: ["tools:call_abc123", "model_request:xyz", ...] This function extracts "call_abc123" from the first "tools:" segment.
Checks if a namespace indicates a subagent/subgraph message.
Subagent namespaces contain a "tools:" segment indicating they originate from a tool call that spawned a subgraph.
Identity converter that keeps @langchain/core class instances. Used by framework SDKs to expose BaseMessage instances instead of plain dicts.
Transport used to stream the thread.
Only applicable for custom endpoints using toLangGraphEventStream or toLangGraphEventStreamResponse.
Tracks pending server-side runs created via multitaskStrategy: "enqueue".
Uses the same subscribe/getSnapshot pattern as StreamManager to integrate with framework-specific reactivity systems.
Manages subagent execution state.
Tracks subagents from the moment they are invoked (AI message with tool calls) through streaming to completion (tool message result).
Minimal interface to structurally match AgentMiddleware from langchain. We can't import AgentMiddleware due to circular dependencies, so we match against its structure to extract type information.
Minimal interface matching the structure of AgentTypeConfig from @langchain/langgraph. This allows type inference from ReactAgent without requiring the langchain dependency.
Minimal interface matching the structure of a CompiledSubAgent from deepagents. Used for structural type matching without importing deepagents.
Minimal interface matching the structure of DeepAgentTypeConfig from deepagents. Extends AgentTypeConfigLike to include subagent type information.
A single queued submission entry representing a server-side pending run.
Each entry corresponds to a run created on the server via
client.runs.create() with multitaskStrategy: "enqueue".
Reactive interface exposed to framework consumers for observing and managing the server-side submission queue.
Base interface for stream-like objects. Contains common properties shared between UseStream and SubagentStream.
Subagent API surface parameterised by the subagent interface type.
Framework adapters supply a class-message variant of
SubagentStreamInterface (where messages is BaseMessage[]
from @langchain/core) so that consumers always work with class
instances. The default parameter keeps the SDK's plain Message
interface for direct SDK usage.
Minimal interface matching the structure of a SubAgent from deepagents. Used for structural type matching without importing deepagents.
Base interface for a single subagent stream. Tracks the lifecycle of a subagent from invocation to completion.
Extends StreamBase to share common properties with UseStream, allowing subagents to be treated similarly to the main stream.
Prefer using SubagentStream which supports passing an agent type directly for automatic type inference.
Represents a tool call that initiated a subagent.
Transport used to stream the thread.
Only applicable for custom endpoints using toLangGraphEventStream or toLangGraphEventStreamResponse.
Payload for the stream method of the UseStreamTransport interface.
Base stream interface shared by all stream types.
Contains core properties for state management, messaging, and stream control that are common to CompiledStateGraph, ReactAgent, and DeepAgent streams.
This interface provides the foundation that all stream types build upon:
values, isLoading, error)messages)interrupt)submit, stop)branch, history)Stream interface for ReactAgent instances created with createAgent.
Extends UseGraphStream with tool calling capabilities. Tool calls are automatically typed based on the agent's tools configuration.
Use this interface when streaming from an agent created with createAgent.
For subagent streaming capabilities, use UseDeepAgentStream with createDeepAgent.
This interface is subject to change.
Options for configuring an agent stream.
Use this options interface when calling useStream with a ReactAgent
created via createAgent.
This interface is subject to change.
Stream interface for DeepAgent instances created with createDeepAgent.
Extends UseAgentStream with subagent streaming capabilities. Subagent streams are automatically typed based on the agent's subagent configuration, enabling type-safe access to subagent state and messages.
Use this interface when streaming from an agent created with createDeepAgent
that orchestrates multiple specialized subagents.
This interface is subject to change.
Options for configuring a deep agent stream.
Use this options interface when calling useStream with a DeepAgent
created via createDeepAgent. Includes all agent options plus
subagent-specific configuration.
Widens an update type so that its messages field also accepts
@langchain/core BaseMessage class instances (single or array).
Framework SDKs apply this to submit so callers can write:
stream.submit({ messages: new HumanMessage("hello") });
stream.submit({ messages: [new HumanMessage("hello")] });Base state type for subagents. All subagents have at least a messages array, similar to the main agent.
Default subagent state map used when no specific subagent types are provided. Maps any string key to Record<string, unknown>.
Extract the AgentTypeConfig from an agent-like type.
Extract the DeepAgentTypeConfig from a DeepAgent-like type.
Helper type to extract middleware from a SubAgent definition. Handles both mutable and readonly middleware arrays.
Extract the tool call type from a StateType's messages property. This is the primary way to specify tool call types when using useStream.
Extract the tool call type from a StateType's messages property. This is the canonical way to get typed tool calls in useStream.
Tool call types are now extracted from the messages property of StateType, rather than being specified separately in the Bag.
Maps a ThreadState<StateType>[] so that the messages field inside
values is typed as BaseMessage[] instead of Message[].
Extract tool calls type from an agent's tools. Converts the tools array to a discriminated union of tool calls.
This handles both tuple types (e.g., readonly [Tool1, Tool2]) and
array-of-union types (e.g., readonly (Tool1 | Tool2)[]) which is how
createAgent captures tool types.
Extract the Subagents array type from a DeepAgent.
Helper type to extract and merge states from an array of middleware. Recursively processes each middleware and intersects their state types.
Handles both readonly and mutable arrays/tuples explicitly.
Helper type to extract a subagent by name from a DeepAgent.
Extract all subagent names as a string union from a DeepAgent.
Infer the state type for a specific subagent by extracting and merging its middleware state schemas, plus the base agent state (messages).
Check if a type is agent-like (has ~agentTypes phantom property).
This property is present on ReactAgent instances created with createAgent.
Check if a type is a DeepAgent (has ~deepAgentTypes phantom property).
This property is present on DeepAgent instances created with createDeepAgent.
Create a map of subagent names to their state types.
This is useful for type-safe getSubagentsByType calls.
The execution status of a subagent.
"pending" - The subagent has been invoked but hasn't started processing yet.
This is the initial state when a tool call is detected but before any
streaming events are received from the subgraph.
"running" - The subagent is actively executing and streaming updates.
The subagent transitions to this state when the first update event is
received from its namespace.
"complete" - The subagent has finished execution successfully.
A tool message with the result has been received, and the result
property contains the final output.
"error" - The subagent encountered an error during execution.
The error property on the SubagentStream contains error details.
Represents a single subagent stream.
Supports two usage patterns:
import type { agent } from "./agent";
// Automatically infers state and tool call types from the agent
const subagent: SubagentStream<typeof agent> = ...;
type ResearcherState = { research_notes: string };
const researcher: SubagentStream<ResearcherState, MyToolCall> = ...;Infer the Bag type from an agent, defaulting to the provided Bag.
Currently returns the provided Bag for all types. Can be extended in the future to extract Bag from agent types.
Infer the node names from a compiled graph.
Extracts the ~NodeType phantom property from CompiledGraph instances,
providing a union of all node names defined in the graph.
Infer the per-node return types from a compiled graph.
Extracts the ~NodeReturnType phantom property from CompiledGraph instances,
which is a mapped type of { [nodeName]: ReturnType } for each node.
Infer the state type from an agent, graph, or direct state type.
Detection order:
~agentTypes) → InferAgentState~RunOutput) → Extract RunOutput~OutputType) → Extract OutputTypeInfer subagent state map from a DeepAgent.
For DeepAgent, creates a map of subagent names to their state types. For non-DeepAgent, returns DefaultSubagentStates.
Infer tool call types from an agent.
For agents, extracts typed tool calls from the agent's tools. For non-agents, returns DefaultToolCall.
Resolves the appropriate stream interface based on the agent/graph type.
This type automatically selects the correct stream interface based on
the type of agent or graph passed to useStream:
DeepAgent (~deepAgentTypes) → UseDeepAgentStream
ReactAgent (~agentTypes) → UseAgentStream
CompiledGraph / Default → BaseStream
Resolves the appropriate options interface based on the agent/graph type.
This type automatically selects the correct options interface based on the type of agent or graph:
DeepAgent → UseDeepAgentStreamOptions
filterSubagentMessages optionReactAgent → UseAgentStreamOptions
CompiledGraph / Default → UseGraphStreamOptions