LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
  • Stream
LangGraph SDK
  • Ui
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Utils
  • Server
  • Stream
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
WebChannelsPregelPrebuiltRemoteStream
LangGraph SDK
UiClientAuthReactLoggingReact UiUtilsServerStream
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 v1.8

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>

Live byte stream.

Lazy: not materialised unless accessed. On first access the stream is seeded with every byte already accumulated (partialBytes) and then wired to future chunks. For URL-sourced blocks, first access triggers fetch() and pipes the response body through.

Repeated access returns the same ReadableStream reference — you can safely read it once, release the lock, and re-acquire a reader later (e.g. React StrictMode effect re-invokes). The standard ReadableStream.locked semantics prevent concurrent readers; use stream.tee() when you truly need multiple live consumers.

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: __type
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: InterruptPayload<unknown>[]

Interrupt payloads collected during the run, if any. Mirrors the in-process run.interrupts.

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: "messages"
property
queueEntries: readonly QueueEntry<StateType, SubmitOptions<StateType, GetConfigurableType<Bag>>>[]
property
queueSize: number
property
shouldReconnect: boolean
property
streamError: unknown
property
streamValues: StateType | null
property
subagents: AsyncIterable<SubagentHandle>
property
threadId: string

Thread ID this transport currently targets.

property
toolCalls: AsyncIterable<ClientAssembledToolCall<string, unknown, unknown>>
property
values: "values"

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>

Drop every queued submission. Server-side cancel arrives with A0.3.

method
dispose→ Promise<void>

Tear everything down.

Detaches the bound thread (so no further bind() calls reopen runtimes) and disposes every live runtime in parallel. Safe to call multiple times — subsequent calls find an empty registry and resolve immediately.

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→ T
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

Rebind this transport to a different thread.

client.threads.stream(threadId, { transport }) calls this (when implemented) whenever the framework binds or re-binds the active thread — including the lazily-minted id from the first submit() on a threadId: null controller. Implementing it lets an adapter be constructed once (optionally with no threadId) and reused as the active thread becomes known, so the framework doesn't have to tear down and rebuild a custom transport when the thread id appears.

Optional: adapters that bake threadId at construction can omit it, in which case the per-call threadId is ignored (prior behaviour).

method
stop→ Promise<void>

Disconnect the client from the active run and mark the controller idle. By default also cancels the run server-side; pass { cancel: false } or call disconnect to keep the agent running (join/rejoin).

method
submit→ Promise<void>

Submit input to the active thread.

To resume a pending interrupt, use respond instead.

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→ Promise<SubscriptionHandle<EventForChannel<TChannel>, YieldForChannel<TChannel>>>

Subscribe to raw wire channels and receive protocol events.

For assembled projections, use the lazy getters instead: thread.messages, thread.values, thread.toolCalls, thread.subgraphs, thread.subagents, thread.output.

method
switchThread

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

method
trackStreamMode

Custom transports do not negotiate stream modes with the server the way LangGraph Platform streams do, but framework adapters call this method on both orchestrator variants. Keep the API surface aligned as a no-op.

method
tryReconnect→ boolean

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

View source on GitHub