LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
  • Stream
LangGraph SDK
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Server
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
LangGraph Checkpoint Redis
  • Shallow
  • Store
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
  • Cli
LangGraph API
LangGraph CLI
LangGraph CUA
  • Utils
LangGraph Supervisor
LangGraph Swarm
⌘I

Chat LangChain

What can I help with?

Enter to send·Shift+Enter new line

Menu

LangGraph
WebChannelsPregelPrebuiltRemoteStream
LangGraph SDK
ClientAuthReactLoggingReact UiServer
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
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 v1.4

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)).

A RemoveMessage carrying the REMOVE_ALL_MESSAGES sentinel id clears all messages accumulated so far (prior state plus earlier writes in the same batch) and keeps only the messages that follow it, mirroring messagesStateReducer. Clearing happens in the same single linear pass, so the batching-invariant still holds.

Raw object / string inputs are coerced to typed BaseMessage objects so that HTTP-driven graphs work without a separate coercion step, and message chunks are converted to their non-chunk class. This is not full messagesStateReducer parity — 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