Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when loading from checkpoint #777

Open
fserafini-DQ opened this issue Jan 12, 2025 · 0 comments
Open

Error when loading from checkpoint #777

fserafini-DQ opened this issue Jan 12, 2025 · 0 comments

Comments

@fserafini-DQ
Copy link

Hello, I have the error below when I try to retrieve the state from a postgres (or sqlite) checkpoint saver.

I debugged a bit and what I have found is that in the file node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js the loader import { load } from "@langchain/core/load"; only load the importMap for the namespace "langchain_core" and not for the namespace "langchain", which is required by the object produced by the ChatOpenAI constructor. If I change the loader to import { load } from "langchain/load";, it works.

This is an extract of the code that produce the error:

import { ChatOpenAI } from "@langchain/openai";
import { PostgresSaver } from "@langchain/langgraph-checkpoint-postgres";

async function createGraph() {
  const graph = new StateGraph(GraphState)
  ...

  const checkpointer = PostgresSaver.fromConnString("postgresql://dev:dev@localhost:5432/dev");
  await checkpointer.setup();
  const app = graph.compile({ checkpointer });
  return app;
}

async function main(query: string) {
  const app = await createGraph();

  const llm = new ChatOpenAI({
    modelName: "gpt-4o",
    temperature: 0,
  }).bindTools(tools);

  const config = {
    configurable: { thread_id: "1" },
    streamMode: "values" as const,
  };

  const stream = await app.stream({
    query,
    llm,
  }, config);

  for await (const event of stream) {
  ...
  }
}

const query = "...";
main(query);

The error:

node:internal/process/promises:391
    triggerUncaughtException(err, true /* fromPromise */);
    ^

Error: Invalid namespace: $ -> {"lc":1,"type":"constructor","id":["langchain","chat_models","openai","ChatOpenAI"],"kwargs":{"model":"gpt-4o","temperature":0,"openai_api_key":{"lc":1,"type":"secret","id":["OPENAI_API_KEY"]}}}
    at Object.reviver (file:///Users/federico/Workspace/langtool-template/node_modules/@langchain/core/dist/load/index.js:117:19)
    at load (file:///Users/federico/Workspace/langtool-template/node_modules/@langchain/core/dist/load/index.js:161:20)
    at _reviver (file:///Users/federico/Workspace/langtool-template/node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:67:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async _reviver (file:///Users/federico/Workspace/langtool-template/node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:28:33)
    at async _reviver (file:///Users/federico/Workspace/langtool-template/node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:28:33)
    at async file:///Users/federico/Workspace/langtool-template/node_modules/@langchain/langgraph-checkpoint-postgres/dist/index.js:114:13
    at async Promise.all (index 0)
    at async PostgresSaver._loadBlobs (file:///Users/federico/Workspace/langtool-template/node_modules/@langchain/langgraph-checkpoint-postgres/dist/index.js:110:25)
    at async PostgresSaver._loadCheckpoint (file:///Users/federico/Workspace/langtool-template/node_modules/@langchain/langgraph-checkpoint-postgres/dist/index.js:103:29)

Node.js v20.18.1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant