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/svelteuseMessages
Function●Since v0.4

useMessages

Subscribe to a scoped messages stream.

Contract:

  • At the root (no target, or a static target that resolves to the root namespace) returns a handle whose .current delegates to stream.messages — the always-on root projection. No extra subscription is opened.
  • For any non-root namespace, mount triggers a ref-counted messages subscription scoped to that namespace. The subscription is released automatically when the owning component teardown fires (and the registry closes the underlying server subscription when the last consumer leaves).
  • A reactive target (getter form) re-binds the subscription on change. A getter that flips between root and scoped is supported: the root case short-circuits to the initial value because dynamic root delegation isn't meaningful — pass a static undefined/null target for root handles.

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

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

Parameters

NameTypeDescription
stream*AnyStream
targetValueOrGetter<SelectorTarget>
View source on GitHub