Intermediate9 min

useStream: Real-Time Agent UI

The useStream React hook renders LangGraph agent output in real-time — per-node status indicators, streaming tokens, and custom events from tools. Works with StateGraph, create_agent, and create_deep_agent.

Quick Reference

  • useStream from @langchain/react — React hook for real-time LangGraph agent output
  • Shows per-node execution status: pending, running, completed, errored
  • Streams LLM tokens as they generate — typing effect for chat UIs
  • Receives custom events from runtime.stream_writer or get_stream_writer()
  • Works with any LangGraph backend: local, Agent Server, or remote
  • Supports custom transports for non-HTTP connections

What useStream Does

useStream connects a React component to a running LangGraph agent and provides real-time state updates. As the agent executes — calling the LLM, running tools, updating state — useStream delivers each update to your UI. No polling, no WebSocket setup, no manual state management.

What You GetHowUI Pattern
Node execution statusPer-node pending/running/completed/erroredProgress indicators, step tracker
LLM token chunksStreamed as they generateTyping effect in chat bubbles
Tool call progressCustom events from toolsProgress bars, status messages
Final stateComplete state after agent finishesFinal response rendering
Interrupt payloadsWhen agent pauses for human inputApproval dialogs, form inputs