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 theuseStream hook in your React application:
Basic usage
To stream from a deep agent with subagents, configureuseStream with filterSubagentMessages and pass streamSubgraphs: true when submitting:
Deep agent `useStream` parameters
Deep agent `useStream` parameters
In addition to the standard
useStream parameters, deep agent streaming supports: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.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.Deep agent `useStream` return values
Deep agent `useStream` return values
In addition to the standard return values, deep agent streaming provides:
A map of all subagents, keyed by tool call ID. Each subagent includes its messages, status, tool calls, and result.
An array of currently running subagents (status is
"pending" or "running").Get a specific subagent by its tool call ID.
Get all subagents triggered by a specific AI message. Useful for associating subagents with the message that spawned them.
Filter subagents by their
subagent_type (e.g., "researcher", "writer").Subagent stream interface
Each subagent in thestream.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
UsegetSubagentsByMessage 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 thetoolCalls 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.
Related
- Streaming overview — Server-side streaming with deep agents
- Subagents — Configure and use subagents with deep agents
- LangChain frontend streaming — General
useStreamdocumentation - useStream API Reference — Full API documentation
- Agent Chat UI — Pre-built chat interface for LangGraph agents
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.