Skip to content

AIMessage content erased when doing updateState #1949

@Specy

Description

@Specy

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangGraph (or the specific integration package).

Example Code

import { END, MemorySaver, MessagesValue, START, StateGraph, StateSchema, } from '@langchain/langgraph';
import { AIMessage, HumanMessage } from '@langchain/core/messages';

const state = new StateGraph(
    new StateSchema({
        messages: MessagesValue,
    }),
);
const checkpointer = new MemorySaver();

const g = state
    .addNode('answerNode', (state) => {
        console.log(state);
        return {};
    })
    .addEdge(START, 'answerNode')
    .addEdge('answerNode', END)
    .compile({
        checkpointer,
    });

const id = {
    configurable: {
        thread_id: 'thread1',
    },
};
const messages = [
    new HumanMessage({
        contentBlocks: [{ type: 'text', text: 'Hello' }],
    }),
    new AIMessage({
        contentBlocks: [{ type: 'text', text: 'Hi there!' }],
    }),
    new HumanMessage({
        contentBlocks: [{ type: 'text', text: 'How are you' }],
    }),
];
async function run() {
    await g.updateState(id, {
        messages,
    });

    await g.invoke({}, id);
}

run();

Error Message and Stack Trace (if applicable)

{
  messages: [
    HumanMessage {
      "id": "a94629d1-02b3-4c2e-b8c2-863e08e26042",
      "content": [
        {
          "type": "text",
          "text": "Hello"
        }
      ],
      "additional_kwargs": {},
      "response_metadata": {
        "output_version": "v1"
      }
    },
    AIMessage {
      "id": "ddb6123c-5419-43b6-8467-2bd04880c942",
      "content": [], //<----------------
      "additional_kwargs": {},
      "response_metadata": {
        "output_version": "v1"
      },
      "tool_calls": [],
      "invalid_tool_calls": []
    },
    HumanMessage {
      "id": "656f0ebd-edd5-49c3-b763-ddd829c28526",
      "content": [
        {
          "type": "text",
          "text": "How are you"
        }
      ],
      "additional_kwargs": {},
      "response_metadata": {
        "output_version": "v1"
      }
    }
  ]
}

Description

When using langgraph, doing a .updateState while updating messages erases content inside of AIMessage.

System Info

Details

Node version: v24.6.0
Operating system: win32 x64
Package manager: npm
Package manager version: N/A

+-- @ai-sdk/perplexity@3.0.18
+-- @aws-sdk/client-s3@3.985.0
+-- @aws-sdk/lib-storage@3.985.0
+-- @aws-sdk/s3-request-presigner@3.985.0
+-- @cartesia/cartesia-js@2.2.9
+-- @elevenlabs/elevenlabs-js@2.34.0
+-- @googleapis/youtube@31.0.0
+-- @langchain/anthropic@1.3.15
+-- @langchain/core@1.1.19
+-- @langchain/google-vertexai@2.1.15
+-- @langchain/groq@1.0.4
+-- @langchain/langgraph@1.1.4
+-- @langchain/openai@1.2.5
+-- @langchain/textsplitters@1.0.1
+-- @langchain/xai@1.3.1
+-- @llamaindex/llama-cloud@1.4.0
+-- @mendable/firecrawl-js@4.12.0
+-- @mistralai/mistralai@1.14.0
+-- @mozilla/readability@0.6.0
+-- @msgpack/msgpack@3.1.3
+-- @nestjs/axios@4.0.1
+-- @nestjs/cli@11.0.16
+-- @nestjs/common@11.1.13
+-- @nestjs/config@4.0.3
+-- @nestjs/core@11.1.13
+-- @nestjs/event-emitter@3.0.1
+-- @nestjs/jwt@11.0.2
+-- @nestjs/platform-express@11.1.13
+-- @nestjs/platform-socket.io@11.1.13
+-- @nestjs/schedule@6.1.1
+-- @nestjs/schematics@11.0.9
+-- @nestjs/swagger@11.2.6
+-- @nestjs/testing@11.1.13
+-- @nestjs/websockets@11.1.13
+-- @prisma/adapter-pg@7.3.0
+-- @prisma/client@7.3.0
+-- @qdrant/js-client-rest@1.16.2
+-- @types/bcrypt@6.0.0
+-- @types/cookie@1.0.0
+-- @types/express@5.0.6
+-- @types/jest@30.0.0
+-- @types/mime-types@3.0.1
+-- @types/multer@2.0.0
+-- @types/node@25.2.1
+-- @types/supertest@6.0.3
+-- @types/ws@8.18.1
+-- @typescript-eslint/eslint-plugin@8.54.0
+-- @typescript-eslint/parser@8.54.0
+-- @typescript/native-preview@7.0.0-dev.20260207.1
+-- ai@6.0.77
+-- apify-client@2.22.0
+-- axios@1.13.4
+-- bcrypt@6.0.0
+-- class-transformer@0.5.1
+-- class-validator@0.14.3
+-- cross-env@10.1.0
+-- dotenv@17.2.4
+-- eslint-config-nestjs@0.8.0
+-- eslint-config-prettier@10.1.8
+-- eslint-plugin-prettier@5.5.5
+-- eslint@10.0.0
+-- filenamify@7.0.1
+-- form-data@4.0.5
+-- groq-sdk@0.37.0
+-- ioredis@5.9.2
+-- jest@30.2.0
+-- langchain@1.2.18
+-- llama-cloud-services@0.5.4
+-- llamaindex@0.12.1
+-- load-esm@1.0.3
+-- mime-types@3.0.2
+-- mozilla-readability@0.1.3
+-- nestjs-spelunker@1.3.2
+-- openai@6.18.0
+-- openapi-client-axios@7.8.0
+-- p-limit@7.3.0
+-- pdf-parse@2.4.5
+-- prettier@3.8.1
+-- prisma@7.3.0
+-- prompts@2.4.2
+-- reflect-metadata@0.2.2
+-- remark-gfm@4.0.1
+-- remark-preset-lint-recommended@7.0.1
+-- remark-stringify@11.0.0
+-- remark@15.0.1
+-- rxjs@7.8.2
+-- sanitize-filename@1.6.3
+-- socket.io@4.8.3
+-- source-map-support@0.5.21
+-- supertest@7.2.2
+-- tiktoken@1.0.22
+-- ts-jest@29.4.6
+-- ts-loader@9.5.4
+-- ts-node@10.9.2
+-- ts-results@3.3.0
+-- tsconfig-paths@4.2.0
+-- typescript-eslint@8.54.0
+-- uuidv7@1.1.0
+-- voyageai@0.1.0
+-- ws@8.19.0
+-- yaml@2.8.2
+-- zod-from-json-schema@0.4.2
`-- zod@4.3.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions