"""Read, and optionally fork, what the checkpointer saved for one thread. python inspect_checkpoints.py --thread demo-1 latest state python inspect_checkpoints.py --thread demo-1 --history every checkpoint python inspect_checkpoints.py --thread demo-1 --fork-draft "New text" --fork-draft finds the checkpoint that was waiting for approval, writes a new draft on top of it with update_state(), and leaves the run paused at the approval step again. Older checkpoints are kept, not overwritten. """ import argparse import os os.environ.setdefault("LANGGRAPH_STRICT_MSGPACK", "true") from langgraph.checkpoint.sqlite import SqliteSaver # noqa: E402 from agent import DB_PATH, build # noqa: E402 p = argparse.ArgumentParser() p.add_argument("--thread", required=True) p.add_argument("--history", action="store_true") p.add_argument("--fork-draft") a = p.parse_args() config = {"configurable": {"thread_id": a.thread}} with SqliteSaver.from_conn_string(DB_PATH) as saver: graph = build(saver) if a.history: for snap in graph.get_state_history(config): cid = snap.config["configurable"]["checkpoint_id"] step = snap.metadata.get("step") print(f"step={step} id={cid[-8:]} next={snap.next} keys={sorted(snap.values)}") elif a.fork_draft: paused = next(s for s in graph.get_state_history(config) if s.next == ("approve",)) new_config = graph.update_state(paused.config, {"draft": a.fork_draft}, as_node="draft_reply") snap = graph.get_state(new_config) print("forked from:", paused.config["configurable"]["checkpoint_id"][-8:]) print("new checkpoint:", new_config["configurable"]["checkpoint_id"][-8:]) print("draft now:", snap.values["draft"]) print("next:", snap.next) else: snap = graph.get_state(config) print("values:", snap.values) print("next:", snap.next)