Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Agents · Function

add_messages

addMessages is a LangGraph reducer that combines an existing message list with incoming messages. It supports standard messages and special modifiers such as RemoveMessage.

How it works

addMessages is a prebuilt reducer for combining LangGraph message-state updates. It appends new messages, handles updates to existing messages, supports RemoveMessage instances, and returns LangChain message objects.

Syntax

addMessages(left: Messages, right: Messages): BaseMessage<MessageStructure<MessageToolSet>, MessageType>[]

Parameters

NameTypeDescription
leftMessagesThe existing messages to merge.
rightMessagesThe new messages or message modifiers to merge.

Returns

BaseMessage<MessageStructure<MessageToolSet>, MessageType>[]

Key points

  • addMessages combines the current messages with messages returned by a graph node.
  • It supports standard messages and special modifiers, including RemoveMessage.
  • The function returns an array of BaseMessage values.
  • The API reference identifies its declaration in the LangGraph core message type definitions.

Common mistakes

  • The reducer also accepts special message modifiers such as RemoveMessage, not only ordinary messages.
  • Use it as a state reducer when message updates should be merged instead of replacing the current list.

Example: Append messages with addMessages

import { addMessages } from "@langchain/langgraph";
import { AIMessage, HumanMessage } from "@langchain/core/messages";

const current = [new HumanMessage({ content: "Hello", id: "1" })];
const updated = addMessages(
  current,
  [new AIMessage({ content: "Hi there!", id: "2" })],
);

console.log(updated.map((message) => message.content));

The reducer merges an existing message list with new messages and returns the combined list.

When to use it

Message-state reduction

Define a graph state field containing conversation history and merge node outputs into it.

Appending conversation messages

Add newly generated human or AI messages without manually concatenating arrays.

Message modification

Apply message operations such as RemoveMessage while reducing state updates.

  • Messages
  • RemoveMessage
  • BaseMessage
  • MessageStructure
  • MessageToolSet

Source: addMessages | LangGraph.js API Reference. Checked 2026-10-15.