Skip to main content
The useStream React hook provides built-in support for deep agent streaming. It automatically tracks subagent lifecycles, separates subagent messages from the main conversation, and exposes a rich API for building multi-agent UIs. Key features for deep agents:
  • Subagent tracking — Automatic lifecycle management for each subagent (pending, running, complete, error)
  • Message filtering — Separate subagent messages from the main conversation stream
  • Tool call visibility — Access tool calls and results from within subagent execution
  • State reconstruction — Restore subagent state from thread history on page reload

Installation

Install the LangGraph SDK to use the useStream hook in your React application:

Basic usage

To stream from a deep agent with subagents, configure useStream with filterSubagentMessages and pass streamSubgraphs: true when submitting:
Learn how to deploy your deep agents to LangSmith for production-ready hosting with built-in observability, authentication, and scaling.
In addition to the standard useStream parameters, deep agent streaming supports:
filterSubagentMessages
boolean
default:"false"
When true, subagent messages are excluded from the main stream.messages array. Access them instead via stream.subagents.get(id).messages. This keeps the main conversation clean.
subagentToolNames
string[]
default:"['task']"
The tool names that spawn subagents. By default, deep agents use the task tool to delegate work to subagents. Only change this if you’ve customized the tool name.
In addition to the standard return values, deep agent streaming provides:
subagents
Map<string, SubagentStream>
A map of all subagents, keyed by tool call ID. Each subagent includes its messages, status, tool calls, and result.
activeSubagents
SubagentStream[]
An array of currently running subagents (status is "pending" or "running").
getSubagent
(toolCallId: string) => SubagentStream | undefined
Get a specific subagent by its tool call ID.
getSubagentsByMessage
(messageId: string) => SubagentStream[]
Get all subagents triggered by a specific AI message. Useful for associating subagents with the message that spawned them.
getSubagentsByType
(type: string) => SubagentStream[]
Filter subagents by their subagent_type (e.g., "researcher", "writer").

Subagent stream interface

Each subagent in the stream.subagents map exposes a stream-like interface:

Rendering subagent streams

Subagent cards

Build cards that show each subagent’s streaming content, status, and progress:

Map subagents to messages

Use getSubagentsByMessage to associate subagent cards with the AI message that triggered them:

Subagent pipeline with progress

Show a progress bar and grid of subagent cards:

Rendering tool calls

Display tool calls and results from within subagent execution using the toolCalls property:

Thread persistence

Persist thread IDs across page reloads so users can return to their deep agent conversations:
When a page reloads, useStream reconstructs subagent state from thread history. Completed subagents are restored with their final status and result, so users see the full conversation history including subagent work.

Type safety

For Python type safety, use type annotations when accessing stream state:

Complete examples

For full working implementations that combine all the patterns above, see these examples in the LangGraph.js repository:

Deep agent example

Parallel subagents with a grid layout, streaming content, progress tracking, and synthesis detection.

Deep agent with tool calls

Tool call visibility, thread persistence, expandable subagent cards, and automatic reconnection on page reload.

Connect these docs to Claude, VSCode, and more via MCP for real-time answers.