Skip to content

Conversation

postbird
Copy link

@postbird postbird commented Jul 7, 2025

Add a new checkpoint implementation based on Mysql.

Follow up the table structure of checkpoint-postgresql, adding the adaptation for mysql.

I passed all the tests using Vitest's test scripts and conducted actual application tests for the local agent (including human-in-the-loop).

For usage:

import { MySQLSaver } from "@langchain/langgraph-checkpoint-mysql";

const writeConfig = {
  configurable: {
    thread_id: "1",
    checkpoint_ns: "",
  },
};
const readConfig = {
  configurable: {
    thread_id: "1",
  },
};

// you can optionally pass a configuration object as the second parameter
const checkpointer = MySQLSaver.fromConnString("mysql://...");

// or you can initialize the sequelize instance first
// const sequelize = new Sequelize({
//   database: 'testdb',
//   username: 'root',
//   password: '123456',
//   host: '127.0.0.1',
//   port: 3306,
//   dialect: 'mysql',
// });

// const checkpointer = new MySQLSaver(sequelize);

// You should call .setup() the first time you use the checkpointer:
await checkpointer.setup();

// or you can set the table manually by using the sql in `/src/migration.sql`

const checkpoint = {
  v: 1,
  ts: "2024-07-31T20:14:19.804150+00:00",
  id: "1ef4f797-8335-6428-8001-8a1503f9b875",
  channel_values: {
    my_key: "meow",
    node: "node",
  },
  channel_versions: {
    __start__: 2,
    my_key: 3,
    "start:node": 3,
    node: 3,
  },
  versions_seen: {
    __input__: {},
    __start__: {
      __start__: 1,
    },
    node: {
      "start:node": 2,
    },
  },
  pending_sends: [],
};

// store checkpoint
await checkpointer.put(writeConfig, checkpoint, {}, {});

// load checkpoint
await checkpointer.get(readConfig);

// list checkpoints
for await (const checkpoint of checkpointer.list(readConfig)) {
  console.log(checkpoint);
}

Copy link

changeset-bot bot commented Jul 7, 2025

⚠️ No Changeset found

Latest commit: f8ea777

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@postbird
Copy link
Author

postbird commented Jul 7, 2025

Different from the postgresql implementation:

  • Use sequelize@6 as the ORM framework, and provide the DDL sqls.
  • Use JSON to replace JSONB
  • Use LONGBLOB to replace `BINARY
  • Support mysql 5.7+ (for JSON type)

@postbird
Copy link
Author

postbird commented Jul 7, 2025

The testing includes human-in-the-loopand resume operation.

Locally testing result in DB:

checkpoints

image

checkpoint_writes

image

checkpoint_migrations

image

checkpoint_blobs

image

@postbird postbird closed this Sep 3, 2025
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

Successfully merging this pull request may close these issues.

1 participant