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.
class StreamOrchestratorCurrently active subagents (where status === "running").
Use this to track and display subagents that are actively executing. Completed or errored subagents are not included.
// Show loading indicators for active subagents
stream.activeSubagents.map(subagent => (
<SubagentCard
key={subagent.id}
type={subagent.toolCall.args.subagent_type}
isLoading={true}
/>
));The current branch of the thread. Used for navigating between different conversation branches.
Last seen error from the stream, if any.
Reset to undefined when a new stream starts.
Current interrupt, if the stream is interrupted.
Convenience alias for interrupts[0].
For workflows with multiple concurrent interrupts, use interrupts instead.
All current interrupts from the stream. When using Send() fan-out with per-task interrupt() calls, multiple interrupts may be pending simultaneously.
Whether the stream is currently running.
true while streaming, false when idle or completed.
Whether the thread is currently being loaded.
true during initial thread data fetch.
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.
// 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");The ID of the thread to fetch history and current values from.
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.
stream.toolCalls.map(({ call, result }) => (
<ToolCallCard
name={call.name}
args={call.args}
result={result}
/>
));The current state values of the stream. Updated as streaming events are received.
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.
Remove all pending runs from the queue and cancel them on the server.
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.
Trigger queue draining. Framework adapters should call this when isLoading or queue size changes.
Retrieve stream-level metadata for a given message.
Return the current version number, incremented on each state change.
Useful as a cache key for external sync (e.g. useSyncExternalStore).
Look up a single subagent stream by its tool call ID.
Retrieve all subagent streams associated with a specific AI message.
Retrieve all subagent streams matching a given tool name / type.
Get tool calls (with results) that belong to a specific AI message.
Trigger initial history fetch for the current thread ID. Should be called once after construction when the initial threadId is known.
Stream output from a run in real-time, until the run is done.
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.
Update the current branch and notify listeners.
Update thread ID from an external source (e.g. reactive prop change). Clears the current stream and triggers a history fetch.
Abort the current stream and invoke the onStop callback
if one was provided in the options.
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.
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.
Register a listener that is called whenever the orchestrator state changes.
Switch to a different thread. If the thread ID actually changed, the current stream is cleared and listeners are notified.
Register additional stream modes that should be included in future stream requests. Modes are deduplicated automatically.
Attempt to reconnect to a previously running stream. Returns true if a reconnection was initiated.