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/reactUseStream
Interface●Since v0.2

UseStream

Copy
interface UseStream

Bases

Omit<StreamBase<StateType, GetToolCallsType<StateType>, GetInterruptType<Bag>, SubagentStates>, "messages">

Properties

property
activeSubagents: SubagentStreamInterface<SubagentStates[keyof SubagentStates], GetToolCallsType<StateType>, keyof SubagentStates & string>[]

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

property
assistantId: string

The ID of the assistant to use.

property
branch: string

The current branch of the thread.

property
client: Client

LangGraph SDK client used to send request and receive responses.

property
error: unknown

Last seen error from the stream.

property
experimental_branchTree: Sequence<StateType>

Tree of all branches for the thread.

property
getMessagesMetadata: (message: BaseMessage, 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.

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 the AI message (and therefore conversation turn) that spawned them.

Copy
// Render subagents after each 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. When called with a literal type name that matches a key in SubagentStates, returns streams with properly inferred state types.

Copy
// With DeepAgent type inference
const stream = useStream<typeof agent>(...);
const researchers = stream.getSubagentsByType("researcher");
// researchers[0].values is typed with ResearcherMiddleware state
property
getToolCalls: (message: AIMessage<GetToolCallsType<StateType>>) => ToolCallWithResult<GetToolCallsType<StateType>>[]

Get tool calls for a specific AI message.

property
history: ThreadState<StateType>[]

Flattened history of thread states of a thread.

property
interrupt: Interrupt<GetInterruptType<Bag>> | undefined

Get the interrupt value for the stream if interrupted. Convenience alias for interrupts[0].

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.

property
isThreadLoading: boolean

Whether the thread is currently being loaded.

property
joinStream: (runId: string, lastEventId?: string, options?: __type) => Promise<void>

Join an active stream.

property
messages: BaseMessage<MessageStructure<MessageToolSet>, MessageType>[]

Messages accumulated during the stream as @langchain/core class instances.

property
queue: QueueInterface<StateType, SubmitOptions<StateType, GetConfigurableType<Bag>>>

Server-side submission queue. Pending runs created via multitaskStrategy: "enqueue" when submitting while the agent is busy.

property
setBranch: (branch: string) => void

Set the branch of the thread.

property
stop: () => Promise<void>

Stops the 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.

property
submit: (values: GetUpdateType<Bag, StateType> | null | undefined, options?: SubmitOptions<StateType, GetConfigurableType<Bag>>) => Promise<void>

Create and stream a run to the thread.

property
switchThread: (newThreadId: string | null) => void

Switch to a different thread, clearing the current stream state. Pass null to reset to no thread (a new thread will be created on next submit).

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

Tool calls paired with their results. Useful for rendering tool invocations and their outputs together.

property
toolProgress: ToolProgress[]

Progress of tool executions during streaming.

property
values: StateType

The current state values of the stream.

View source on GitHub