PostgresSaver thows multiple errors with createAgent #383

Open
opened 2026-02-15 18:16:22 -05:00 by yindo · 0 comments
Owner

Originally created by @mvertopoulos on GitHub (Dec 3, 2025).

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


let checkpointer;

(function () {

    const { createAgent, summarizationMiddleware } = require('langchain');

    /*const { MemorySaver } = require('@langchain/langgraph');
    const checkpointer = new MemorySaver();*/

    if (!checkpointer) {
      const { PostgresSaver } = require('@langchain/langgraph-checkpoint-postgres');
      const connString = 'postgresql://ptdb:ptdb@pt_postgres:5432/ptdb?sslmode=disable';
      checkpointer = PostgresSaver.fromConnString(connString);
      await checkpointer.setup();
    }

    const agent = createAgent({
      model: 'gpt-4o',
      tools: [],
      middleware: [
        summarizationMiddleware({
          model: 'gpt-4o-mini',
          trigger: { tokens: 4000 },
          keep: { messages: 20 },
        }),
      ],
      checkpointer,
    });

    const config = { configurable: { thread_id: '1' } };
    await agent.invoke({ messages: 'hi, my name is bob' }, config);
    await agent.invoke({ messages: 'write a short poem about cats' }, config);
    await agent.invoke({ messages: 'now do the same but for dogs' }, config);
    const finalResponse = await agent.invoke({ messages: "what's my name?" }, config);

    console.log(finalResponse.messages.at(-1)?.content);
    // Your name is Bob!

})();

Error Message and Stack Trace (if applicable)

On first attempt of running the script, the first agent.invoke throws this error:

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Timeout'
    |     property '_idlePrev' -> object with constructor 'TimersList'
    --- property '_idleNext' closes the circle
    at JSON.stringify (<anonymous>)
    at ConfigurableModel._getModelInstance (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/langchain/dist/chat_models/universal.cjs:190:25)
    at ConfigurableModel.invoke (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/langchain/dist/chat_models/universal.cjs:264:28)
    at baseHandler (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/langchain/dist/agents/nodes/AgentNode.cjs:134:89)
    at async #run (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/langchain/dist/agents/nodes/AgentNode.cjs:84:20)
    at async AgentNode.invoke (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/langchain/dist/agents/RunnableCallable.cjs:36:23)
    at async RunnableSequence.invoke (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/core/dist/runnables/base.cjs:945:21)
    at async Object._runWithRetry (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/langgraph/dist/pregel/retry.cjs:48:13)
    at async PregelRunner._executeTasksWithRetry (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/langgraph/dist/pregel/runner.cjs:140:24)
    at async PregelRunner.tick (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/langgraph/dist/pregel/runner.cjs:61:49) {
  pregelTaskId: 'ac1ba9da-84fb-55b1-95a7-03d36466907e'
}

On second attempt of running the script, the same line throws this error:

Chat error: TypeError: Cannot read properties of undefined (reading '__input__')
    at Object._applyWrites (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/langgraph/dist/pregel/algo.cjs:96:33)
    at PregelLoop._first (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/langgraph/dist/pregel/loop.cjs:450:41)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async PregelLoop.tick (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/langgraph/dist/pregel/loop.cjs:298:59)
    at async CompiledStateGraph._runLoop (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/langgraph/dist/pregel/index.cjs:1135:11)
    at async createAndRunLoop (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/langgraph/dist/pregel/index.cjs:1038:5)

Description

I am trying to use LangChain's createAgent function with a PostgresSaver checkpointer. But, I am getting multiple errors:

  • On the first time that I run the script the await agent.invoke({ messages: 'hi, my name is bob' }, config); call throws:
TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Timeout'
    |     property '_idlePrev' -> object with constructor 'TimersList'
    --- property '_idleNext' closes the circle

However, I do see some records written in the created tables in postgres (checkpoints, checkpoint_writes, checkpoint_migrations and checkpoint_blobs).

  • The second time I run the script the same line throws:
TypeError: Cannot read properties of undefined (reading '__input__')

Note: if I run the same script with the MemorySaver checkpointer, everything is working fine.

Also please note that both langchain (v1.1.3) and @langchain/langgraph-checkpoint-postgres (v1.0.0) are at their latest versions at the time of this writting.

System Info

Node version: v20.19.3
Operating system: linux x64
Package manager: npm
Package manager version: N/A

@langchain/core -> @1.1.2, , @"^1.1.1", @"1.1.2", @"^1.0.1", @"^1.0.0", @1.1.0, @"1.1.0"
langsmith -> @0.3.82, , @"~0.3.74", @"^0.3.64"
zod -> @3.25.76, , @"^3.25.76, @"^3.19.1", @"^3.25.76", @"^3.25, @"^3.25.32, @"^3.24.2", @3.25.67, @"3.25.67", @4.1.13, @"^4.1.5", @"^4.0.14"
@langchain/google-genai -> @2.0.2, , @"^2.0.0"
@langchain/google-vertexai -> @1.0.4, , @"^1.0.0"
@langchain/google-gauth -> @1.0.4, , @"1.0.4"
@langchain/google-common -> @1.0.4, , @"1.0.4"
@langchain/langgraph-checkpoint-postgres -> @1.0.0, , @"^1.0.0"
@langchain/langgraph-checkpoint -> @1.0.0, , @"^1.0.0"
@langchain/langgraph -> @1.0.3, , @"^1.0.3", @"^1.0.0"
@langchain/langgraph-sdk -> @1.1.0, , @"~1.1.0"
@langchain/openai -> @1.1.3, , @"^1.1.3"
langchain -> @1.1.3, , @"^1.1.2"

Note: Running on docker via WSL

Originally created by @mvertopoulos on GitHub (Dec 3, 2025). ### Checked other resources - [x] I added a very descriptive title to this issue. - [x] I searched the LangGraph.js documentation with the integrated search. - [x] I used the GitHub search to find a similar question and didn't find it. - [x] I am sure that this is a bug in LangGraph.js rather than my code. - [x] The bug is not resolved by updating to the latest stable version of LangGraph (or the specific integration package). ### Example Code ```javascript let checkpointer; (function () { const { createAgent, summarizationMiddleware } = require('langchain'); /*const { MemorySaver } = require('@langchain/langgraph'); const checkpointer = new MemorySaver();*/ if (!checkpointer) { const { PostgresSaver } = require('@langchain/langgraph-checkpoint-postgres'); const connString = 'postgresql://ptdb:ptdb@pt_postgres:5432/ptdb?sslmode=disable'; checkpointer = PostgresSaver.fromConnString(connString); await checkpointer.setup(); } const agent = createAgent({ model: 'gpt-4o', tools: [], middleware: [ summarizationMiddleware({ model: 'gpt-4o-mini', trigger: { tokens: 4000 }, keep: { messages: 20 }, }), ], checkpointer, }); const config = { configurable: { thread_id: '1' } }; await agent.invoke({ messages: 'hi, my name is bob' }, config); await agent.invoke({ messages: 'write a short poem about cats' }, config); await agent.invoke({ messages: 'now do the same but for dogs' }, config); const finalResponse = await agent.invoke({ messages: "what's my name?" }, config); console.log(finalResponse.messages.at(-1)?.content); // Your name is Bob! })(); ``` ### Error Message and Stack Trace (if applicable) On first attempt of running the script, the first `agent.invoke` throws this error: ```shell TypeError: Converting circular structure to JSON --> starting at object with constructor 'Timeout' | property '_idlePrev' -> object with constructor 'TimersList' --- property '_idleNext' closes the circle at JSON.stringify (<anonymous>) at ConfigurableModel._getModelInstance (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/langchain/dist/chat_models/universal.cjs:190:25) at ConfigurableModel.invoke (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/langchain/dist/chat_models/universal.cjs:264:28) at baseHandler (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/langchain/dist/agents/nodes/AgentNode.cjs:134:89) at async #run (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/langchain/dist/agents/nodes/AgentNode.cjs:84:20) at async AgentNode.invoke (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/langchain/dist/agents/RunnableCallable.cjs:36:23) at async RunnableSequence.invoke (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/core/dist/runnables/base.cjs:945:21) at async Object._runWithRetry (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/langgraph/dist/pregel/retry.cjs:48:13) at async PregelRunner._executeTasksWithRetry (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/langgraph/dist/pregel/runner.cjs:140:24) at async PregelRunner.tick (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/langgraph/dist/pregel/runner.cjs:61:49) { pregelTaskId: 'ac1ba9da-84fb-55b1-95a7-03d36466907e' } ``` On second attempt of running the script, the same line throws this error: ```shell Chat error: TypeError: Cannot read properties of undefined (reading '__input__') at Object._applyWrites (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/langgraph/dist/pregel/algo.cjs:96:33) at PregelLoop._first (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/langgraph/dist/pregel/loop.cjs:450:41) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async PregelLoop.tick (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/langgraph/dist/pregel/loop.cjs:298:59) at async CompiledStateGraph._runLoop (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/langgraph/dist/pregel/index.cjs:1135:11) at async createAndRunLoop (/tmp/3a01a962-3723-4db2-8145-0487a84871c2/api/node_modules/@langchain/langgraph/dist/pregel/index.cjs:1038:5) ``` ### Description I am trying to use LangChain's `createAgent` function with a PostgresSaver checkpointer. But, I am getting multiple errors: - On the first time that I run the script the `await agent.invoke({ messages: 'hi, my name is bob' }, config);` call throws: ```shell TypeError: Converting circular structure to JSON --> starting at object with constructor 'Timeout' | property '_idlePrev' -> object with constructor 'TimersList' --- property '_idleNext' closes the circle ``` However, I do see some records written in the created tables in postgres (`checkpoints`, `checkpoint_writes`, `checkpoint_migrations` and `checkpoint_blobs`). - The second time I run the script the same line throws: ```shell TypeError: Cannot read properties of undefined (reading '__input__') ``` ❗Note: **if I run the same script with the MemorySaver checkpointer, everything is working fine.** Also please note that both langchain (v1.1.3) and @langchain/langgraph-checkpoint-postgres (v1.0.0) are at their latest versions at the time of this writting. ### System Info Node version: v20.19.3 Operating system: linux x64 Package manager: npm Package manager version: N/A -------------------- @langchain/core -> @1.1.2, , @"^1.1.1", @"1.1.2", @"^1.0.1", @"^1.0.0", @1.1.0, @"1.1.0" langsmith -> @0.3.82, , @"~0.3.74", @"^0.3.64" zod -> @3.25.76, , @"^3.25.76, @"^3.19.1", @"^3.25.76", @"^3.25, @"^3.25.32, @"^3.24.2", @3.25.67, @"3.25.67", @4.1.13, @"^4.1.5", @"^4.0.14" @langchain/google-genai -> @2.0.2, , @"^2.0.0" @langchain/google-vertexai -> @1.0.4, , @"^1.0.0" @langchain/google-gauth -> @1.0.4, , @"1.0.4" @langchain/google-common -> @1.0.4, , @"1.0.4" @langchain/langgraph-checkpoint-postgres -> @1.0.0, , @"^1.0.0" @langchain/langgraph-checkpoint -> @1.0.0, , @"^1.0.0" @langchain/langgraph -> @1.0.3, , @"^1.0.3", @"^1.0.0" @langchain/langgraph-sdk -> @1.1.0, , @"~1.1.0" @langchain/openai -> @1.1.3, , @"^1.1.3" langchain -> @1.1.3, , @"^1.1.2" > Note: Running on docker via WSL
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#383