LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
LangGraph SDK
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • 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
LangGraph SDK
ClientAuthReactLoggingReact UiServer
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-sdkreactUseStream
Interface●Since v0.0

UseStream

Copy
interface UseStream

Bases

StreamBase<StateType, GetToolCallsType<StateType>, GetInterruptType<Bag>, SubagentStates>

Properties

property
activeSubagents: SubagentStreamInterface<SubagentStates[keyof SubagentStates], GetToolCallsType<StateType>, 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
assistantId: string

The ID of the assistant to use.

property
branch: string

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

property
client: Client

LangGraph SDK client used to send requests and receive responses.

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
getMessagesMetadata: (message: Message<GetToolCallsType<StateType>>, index?: number) => MessageMetadata<StateType> | undefined

Get the metadata for a message, such as first thread state the message was seen in and branch information.

property
getSubagent: (toolCallId: string) => SubagentStreamInterface<SubagentStates[keyof SubagentStates], GetToolCallsType<StateType>, keyof SubagentStates & string> | undefined

Get subagent stream by tool call ID.

Use this when you have a specific tool call ID and need to access its corresponding subagent stream.

Copy
// In a tool call component
const subagent = stream.getSubagent(toolCall.id);
if (subagent) {
  return <SubagentProgress subagent={subagent} />;
}
property
getSubagentsByMessage: (messageId: string) => SubagentStreamInterface<SubagentStates[keyof SubagentStates], GetToolCallsType<StateType>, keyof SubagentStates & string>[]

Get all subagents triggered by a specific AI message.

Useful for rendering subagent activities grouped by conversation turn. Each AI message that contains subagent tool calls will have its triggered subagents returned by this method.

Copy
// Render subagents inline after the AI message that triggered them
{stream.messages.map((msg) => (
  <div key={msg.id}>
    <MessageBubble message={msg} />
    {msg.type === "ai" && "tool_calls" in msg && (
      <SubagentPipeline
        subagents={stream.getSubagentsByMessage(msg.id)}
      />
    )}
  </div>
))}
property
getSubagentsByType: (type: TName) => SubagentStreamInterface<SubagentStates[TName], GetToolCallsType<StateType>, TName>[]

Get all subagents of a specific type.

Returns streams with properly inferred state types based on subagent name. When called with a literal string that matches a subagent name, TypeScript will infer the correct state type for that subagent.

Copy
// Get all researcher subagents with typed state
const researchers = stream.getSubagentsByType("researcher");

researchers.forEach(researcher => {
  // researcher.values is typed based on ResearchMiddleware
  console.log("Research messages:", researcher.values.messages.length);
  console.log("Status:", researcher.status);
});

// Get all writer subagents
const writers = stream.getSubagentsByType("writer");
// writers have different state type based on WriterMiddleware
property
getToolCalls: (message: AIMessage<GetToolCallsType<StateType>>) => ToolCallWithResult<GetToolCallsType<StateType>>[]

Get tool calls for a specific AI message.

Use this to find which tool calls were initiated by a particular assistant message, useful for rendering tool calls inline with messages.

Copy
messages.map(message => {
  if (message.type === "ai") {
    const calls = stream.getToolCalls(message);
    return (
      <>
        <MessageBubble message={message} />
        {calls.map(tc => <ToolCallCard key={tc.call.id} {...tc} />)}
      </>
    );
  }
  return <MessageBubble message={message} />;
});
property
history: ThreadState<StateType>[]

Flattened history of thread states of a thread. Contains all states in the current branch's history.

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
joinStream: (runId: string, lastEventId?: string, options?: __type) => Promise<void>

Join an active stream that's already running.

property
messages: Message<GetToolCallsType<StateType>>[]

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

property
setBranch: (branch: string) => void

Set the branch of the thread.

property
stop: () => Promise<void>

Stops the currently running stream.

property
subagents: Map<string, SubagentStreamInterface<SubagentStates[keyof SubagentStates], GetToolCallsType<StateType>, 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
submit: (values: GetUpdateType<Bag, StateType> | null | undefined, options?: SubmitOptions<StateType, GetConfigurableType<Bag>>) => Promise<void>

Create and stream a run to the thread.

property
toolCalls: ToolCallWithResult<GetToolCallsType<StateType>>[]

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.

View source on GitHub