LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
  • Stream
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
WebChannelsPregelPrebuiltRemoteStream
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/langgraphwebmessagesDeltaReducer
Function●Since v0.3

messagesDeltaReducer

Experimental. Batch reducer for use with DeltaChannel.

Processes all writes in one pass — dedup by ID and RemoveMessage tombstoning — without calling messagesStateReducer.

This reducer is batching-invariant, as required by DeltaChannel: reducer(reducer(state, xs), ys) === reducer(state, xs.concat(ys)).

Raw object / string inputs are coerced to typed BaseMessage objects so that HTTP-driven graphs work without a separate coercion step. This is not full messagesStateReducer parity — REMOVE_ALL_MESSAGES, unknown-id RemoveMessage errors, and missing-id UUID assignment are not handled here.

Copy
messagesDeltaReducer(
  state: BaseMessage<MessageStructure<MessageToolSet>, MessageType>[],
  writes: Messages[]
): BaseMessage<MessageStructure<MessageToolSet>, MessageType>[]

Parameters

NameTypeDescription
state*BaseMessage<MessageStructure<MessageToolSet>, MessageType>[]

The current accumulated list of messages.

writes*Messages[]

Batch of writes, each a single message-like or an array.

Example

Copy
import { DeltaChannel, messagesDeltaReducer } from "@langchain/langgraph";

const channel = new DeltaChannel(messagesDeltaReducer);
View source on GitHub