Skip to content
目录

Checkpointer 层详解

Checkpointer 在超步边界(或配置点)把 channel 状态 + 元数据 写成 checkpoint,用 thread_id 区分会话,用 checkpoint_id 链式版本。


1. 解决什么问题

需求Checkpointer
多轮对话记忆同一 thread 恢复最后 checkpoint
崩溃恢复从最近快照继续
时间旅行 / 分支保留 checkpoint 链
HITL暂停在 checkpoint,人工改 state 再 resume

2. 核心概念

概念含义
thread_id会话/线程标识
checkpoint一次快照(channel 值、下一步待执行信息等)
checkpoint_id快照 ID,可 parent 形成链
serde序列化(JSON、msgpack 等)

3. BaseCheckpointSaver

实现需提供(语义):

  • put / get / list checkpoint
  • 与 graph 配置绑定(checkpointer= on compile)
  • 可选 Store(长期 KV,与 checkpoint 互补)

常见实现:MemorySaver(开发)、Postgres / SQLite(生产)。


4. 与 Pregel 的协作

每个 superstep 结束后,若配置持久化,引擎调用 saver 写入。
invoke / stream 结束时也可落盘。
恢复:getState / invokecheckpoint_id 或 thread 最新点。


5. 序列化注意

  • State 需 可 serde;含函数、不可序列化对象会失败。
  • 大 payload 影响 DB 与延迟;可存引用 id 而非全文。

6. 与「事件溯源」对比

采用 checkpoint 快照 而非无限事件日志:实现与恢复路径更简单;代价是存储步级全量(可压缩/裁剪策略另论)。见 08


7. 总结

Checkpointer = 可恢复的图状态数据库;生产选型 Postgres 类实现,开发用 Memory。

MIT License.