用途:解决 LangGraph 智能体状态持久化问题,避免“每轮都重新自我介绍”等记忆丢失现象,并覆盖检查点相关的常见陷阱(P16、P17、P18、P20、P22、P40、P51)。
主要能力:按环境选择检查点器(开发用 MemorySaver,单机用 SqliteSaver,生产同步用 PostgresSaver,异步/FastAPI 用 AsyncPostgresSaver);在应用边界强制校验 thread_id;将状态约束为 JSON 安全的基本类型;Postgres 建表与升级迁移;用 get_state_history 与 update_state 做时间旅行与重放调试。
必要用法:安装 pip install langgraph langchain-core(>=1.0,<2.0),Postgres 需 pip install langgraph-checkpoint-postgres 及 Postgres 13+,异步再加 asyncpg。每次调用传入 config={"configurable": {"thread_id": ...}},并用 require_thread_id 中间件在缺失时抛错。状态用 TypedDict,字段仅限 str、int、float、bool、None、list、dict 等,datetime 用 isoformat()、Decimal 用 str() 转换。PostgresSaver 需在启动时及每次升级 langgraph 后调用 checkpointer.setup(),并用 canary 线程断言状态未丢失。
适用场景:多轮对话记忆、多租户隔离、人工审批中断、生产事故回溯与 A/B 重放。
限制:MemorySaver 仅进程内,重启即丢,不可用于多 worker 后端;检查点存储每步约 1-10 KB;Deep Agent 的 state["files"] 可能无限增长需清理节点;同步与异步检查点器不可混用。具体价格、平台支持等资料暂未提供。