LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
React SDK
Vue SDK
Svelte SDK
Angular SDK
LangGraph SDK
  • Ui
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Utils
  • Server
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
  • Store
LangGraph Checkpoint Redis
  • Shallow
  • Store
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
  • Cli
LangGraph API
LangGraph CLI
LangGraph CUA
  • Utils
LangGraph Supervisor
LangGraph Swarm
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangGraph
WebChannelsPregelPrebuiltRemote
React SDK
Vue SDK
Svelte SDK
Angular SDK
LangGraph SDK
UiClientAuthReactLoggingReact UiUtilsServer
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
Store
LangGraph Checkpoint Redis
ShallowStore
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
Cli
LangGraph API
LangGraph CLI
LangGraph CUA
Utils
LangGraph Supervisor
LangGraph Swarm
Language
Theme
JavaScript@langchain/langgraph-sdkuiStreamOrchestrator
Class●Since v2.0

StreamOrchestrator

Framework-agnostic orchestrator for LangGraph Platform streams.

Encapsulates all business logic shared across React, Vue, Svelte, and Angular: thread management, history fetching, stream lifecycle, queue management, branching, subagent management, and auto-reconnect.

Framework adapters subscribe to state changes via subscribe and map the orchestrator's getters to framework-specific reactive primitives.

Copy
class StreamOrchestrator

Constructors

constructor
constructor

Properties

property
historyLimit: number | boolean
property
messageManager: MessageTupleManager
property
pendingRuns: PendingRunsTracker<StateType, SubmitOptions<StateType, GetConfigurableType<Bag>>>
property
stream: StreamManager<StateType, Bag>
property
activeSubagents: SubagentStreamInterface<SubagentStates[keyof SubagentStates], ToolCall, keyof SubagentStates & string>[]

Currently active subagents (where status === "running").

Use this to track and display subagents that are actively executing. Completed or errored subagents are not included.

Copy
// Show loading indicators for active subagents
stream.activeSubagents.map(subagent => (
  <SubagentCard
    key={subagent.id}
    type={subagent.toolCall.args.subagent_type}
    isLoading={true}
  />
));
property
branch: string

The current branch of the thread. Used for navigating between different conversation branches.

property
branchContext: __type
property
error: unknown

Last seen error from the stream, if any. Reset to undefined when a new stream starts.

property
experimental_branchTree: Sequence<StateType>

Tree of all branches for the thread. This API is experimental and subject to change.

property
flatHistory: ThreadState<any>[]
property
historyData: UseStreamThread<StateType>
property
historyError: unknown
property
historyValues: StateType
property
interrupt: Interrupt<GetInterruptType<Bag>> | undefined

Current interrupt, if the stream is interrupted. Convenience alias for interrupts[0]. For workflows with multiple concurrent interrupts, use interrupts instead.

property
interrupts: Interrupt<GetInterruptType<Bag>>[]

All current interrupts from the stream. When using Send() fan-out with per-task interrupt() calls, multiple interrupts may be pending simultaneously.

property
isLoading: boolean

Whether the stream is currently running. true while streaming, false when idle or completed.

property
isThreadLoading: boolean

Whether the thread is currently being loaded. true during initial thread data fetch.

property
messageInstances: BaseMessage<MessageStructure<MessageToolSet>, MessageType>[]
property
messageMetadata: __type[]
property
messages: Message<ToolCall>[]

Messages accumulated during the stream. Includes both human and AI messages. AI messages include typed tool calls based on the agent's tools.

property
queueEntries: readonly QueueEntry<StateType, SubmitOptions<StateType, GetConfigurableType<Bag>>>[]
property
queueSize: number
property
shouldReconnect: boolean
property
streamError: unknown
property
streamValues: StateType | null
property
subagents: Map<string, SubagentStreamInterface<SubagentStates[keyof SubagentStates], ToolCall, keyof SubagentStates & string>>

All currently active and completed subagent streams.

Keyed by tool call ID for easy lookup. Includes subagents in all states: pending, running, complete, and error.

Copy
// Iterate over all subagents
stream.subagents.forEach((subagent, toolCallId) => {
  console.log(`Subagent ${toolCallId}: ${subagent.status}`);
});

// Get a specific subagent
const specific = stream.subagents.get("call_abc123");
property
threadId: string | null

The ID of the thread to fetch history and current values from.

property
toolCalls: ToolCallWithResult<ToolCall>[]

Tool calls paired with their results.

Each entry contains the tool call request and its corresponding result. Useful for rendering tool invocations and their outputs together.

Copy
stream.toolCalls.map(({ call, result }) => (
  <ToolCallCard
    name={call.name}
    args={call.args}
    result={result}
  />
));
property
values: StateType

The current state values of the stream. Updated as streaming events are received.

Methods

method
cancelQueueItem→ Promise<boolean>

Cancel and remove a specific pending run from the queue. If the run exists and a thread is active, the run is also cancelled on the server.

method
clearQueue→ Promise<void>

Remove all pending runs from the queue and cancel them on the server.

method
dispose

Tear down the orchestrator. Marks the instance as disposed, unsubscribes from the stream, and aborts any in-progress stream. After calling this method, no further notifications will be emitted.

method
drainQueue

Trigger queue draining. Framework adapters should call this when isLoading or queue size changes.

method
getMessagesMetadata→ MessageMetadata<StateType> | undefined

Retrieve stream-level metadata for a given message.

method
getSnapshot→ number

Return the current version number, incremented on each state change. Useful as a cache key for external sync (e.g. useSyncExternalStore).

method
getSubagent→ SubagentStreamInterface<Record<string, unknown>, DefaultToolCall, string> | undefined

Look up a single subagent stream by its tool call ID.

method
getSubagentsByMessage→ SubagentStreamInterface<Record<string, unknown>, DefaultToolCall, string>[]

Retrieve all subagent streams associated with a specific AI message.

method
getSubagentsByType→ SubagentStreamInterface<Record<string, unknown>, DefaultToolCall, string>[]

Retrieve all subagent streams matching a given tool name / type.

method
getToolCalls→ ToolCallWithResult<DefaultToolCall>[]

Get tool calls (with results) that belong to a specific AI message.

method
initThreadId

Trigger initial history fetch for the current thread ID. Should be called once after construction when the initial threadId is known.

method
joinStream→ AsyncGenerator<__type>

Stream output from a run in real-time, until the run is done.

method
reconstructSubagentsIfNeeded

Reconstruct subagent streams from history values when subagent filtering is enabled and the stream is not currently loading. This is a no-op if subagents are already populated.

method
setBranch

Update the current branch and notify listeners.

method
setThreadId

Update thread ID from an external source (e.g. reactive prop change). Clears the current stream and triggers a history fetch.

method
stop

Abort the current stream and invoke the onStop callback if one was provided in the options.

method
submit→ Promise<void>

Submit input values and start a new stream run.

Delegates to submitDirect. Override or wrap this method in framework adapters to add queuing or other middleware.

method
submitDirect→ Promise<void>

Start a new stream run against the custom transport.

This is the low-level submit entry point that handles thread ID resolution, optimistic value merging, and transport invocation. Prefer submit unless you need to bypass higher-level wrappers.

method
subscribe→ () => void

Register a listener that is called whenever the orchestrator state changes.

method
switchThread

Switch to a different thread. If the thread ID actually changed, the current stream is cleared and listeners are notified.

method
trackStreamMode

Register additional stream modes that should be included in future stream requests. Modes are deduplicated automatically.

method
tryReconnect→ boolean

Attempt to reconnect to a previously running stream. Returns true if a reconnection was initiated.

View source on GitHub