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
  • Stream
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 UiUtilsServerStream
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/reactuseMessages
Function●Since v1.0

useMessages

Subscribe to a scoped messages stream. Pass stream and optionally a subagent/subgraph snapshot (or any namespaced target).

Contract:

  • At the root (no target) this returns stream.messages directly — no extra subscription is opened. stream.messages is the live merge of messages-channel token deltas and values.messages snapshots (see UseStreamReturn.messages), so token-by-token streaming here depends on the backend emitting messages channel events. Backends that only emit values updates will render full turns at once rather than streaming.
  • For any other namespace, the mount triggers a ref-counted messages subscription scoped to that namespace. Unmounting the last component that watches this namespace closes the subscription automatically.

Messages are always BaseMessage class instances from @langchain/core/messages.

Copy
useMessages(
  stream: AnyStream,
  target: SelectorTarget
): BaseMessage<MessageStructure<MessageToolSet>, MessageType>[]

Parameters

NameTypeDescription
stream*AnyStream
targetSelectorTarget
View source on GitHub