← THE LIBRARY

Engineering / Agent state / FIELD GUIDE

Make a LangGraph agent survive restarts with a SQLite checkpointer

Save every step of a LangGraph agent to SQLite, pause for a person, resume in a new process, then read and fork the saved history.

Checked 22 Oct 2026

Pinned source guide with authored example files. Original project by LangChain; guide and labeled adaptations by Agent Setup Kits.

Use case
Stateful agent, resumable
Architecture
Single agent, 3-node graph
Trigger
Manual, start and resume
Runs
Your machine, no API key
License
MIT
Human approval
interrupt() before send

First step

bash
python agent.py start  --thread demo-1 --message "My invoice is wrong"

Copy this first step, then read the setup and the human approval notes before you go further.

01 / PURPOSE

The autonomous job

Triage one support message, draft a reply and stop for a person to approve or reject it. The pause is saved to SQLite, so the decision can come from a different process later and the run continues where it stopped.

02 / SYSTEM

Architecture and handoffs

Single agent as a three-node LangGraph graph: triage, draft_reply, approve. The graph is compiled with SqliteSaver, which writes a checkpoint after every step under a thread_id. The approve node calls interrupt(), which saves and stops the run; Command(resume=...) supplies the decision. inspect_checkpoints.py reads get_state and get_state_history and forks a run with update_state. The model is a rule-based stand-in, so the kit needs no API key.

System for Make a LangGraph agent survive restarts with a SQLite checkpointer Your process + one SQLite file start / resume triage, draft checkpoint each step interrupt: approve? swap saver later HUMAN Developer AGENT LangGraph graph SERVICE Stand-in model SERVICE checkpoints.sqlite SERVICE Postgres (next step) ASK
Built from this kit's roles, tools and boundaryHumanAgentServiceBoundary
01 / HUMAN

Developer

Starts runs, approves or rejects drafts, inspects and forks history

HandoffSupplies the decision that resumes the run

02 / AGENT

Support graph agent

Triages the message, drafts a reply and pauses for approval

HandoffEnds with a sent or not-sent result

03 / SERVICE

SqliteSaver

Saves and loads checkpoints for each thread

HandoffReturns saved state to the graph on resume

Model
None by default: fake_llm() is fixed rules with no network. Replace it with any chat model call when the flow works.
Memory
SQLite file checkpoints.sqlite, keyed by thread_id. Each step is a checkpoint you can list, read, resume from or fork. Upstream positions SQLite for local development, testing, or lightweight deployments; for several workers, Postgres (langgraph-checkpoint-postgres) is the production next step.

03 / CONNECTIONS

Tools and triggers

Tool access described by this edition
ToolPurposeAccess
SqliteSaver (checkpoints.sqlite)Persist graph state after every stepLocal file in the working folder
interrupt / Command(resume=...)Pause for a person and resume with their decisionThe graph cannot pass the approve node without a resume value

What starts the work

  • Manual A developer runs python agent.py start, then python agent.py resume with a decision, in the same or a new process.
Permissions in this edition
ControlDecision
Write and read checkpoints.sqlite in the working folderYes
Pause and resume runs by thread_idYes
Edit saved state and fork a runYes
Enforced by the graph: the approve node calls interrupt(), so the run cannot finish without a resume value.Ask
The decision is whatever value the resume call passes; the kit accepts only approve or reject on the command line.Ask
Not access control: anyone who can run the script or write the SQLite file can resume or edit a thread.Ask
'sent' is a flag in state; the kit sends nothing anywhere.Ask
Your Python process and one SQLite file. The stand-in model makes no network calls. The checkpoint file holds every message and draft in plain form.Yes

04 / BOUNDARIES

Capabilities and safety

Credentials
None in the kit. If you add a real model, keep its key in the environment. Treat checkpoints.sqlite as sensitive: it stores full state.
Shutdown
Stop the process at any time; the last checkpoint stays on disk. Delete checkpoints.sqlite to clear all threads.

Capabilities

  • Write and read checkpoints.sqlite in the working folder
  • Pause and resume runs by thread_id
  • Edit saved state and fork a run

05 / SETUP

The files behind the workflow.

Original-project files retain their attribution and license; our installation notes, dependency profiles and custom wrappers are identified separately.

  1. Install the pinned packages

  2. Start a run and stop at the pause

  3. Resume in a new process

  4. Read the saved history

  5. Fork and resume a branch

requirements.txtView file +

Pins langgraph 1.2.16, langgraph-checkpoint 4.3.0 and langgraph-checkpoint-sqlite 3.1.2

Download requirements.txt ↓

langgraph==1.2.16
langgraph-checkpoint==4.3.0
langgraph-checkpoint-sqlite==3.1.2

Agent Setup Kits authored

agent.pyView file +

Three-node graph with SqliteSaver and an interrupt() approval step; start and resume commands

Download agent.py ↓

"""A three-node LangGraph agent whose state survives restarts in SQLite.

triage -> draft_reply -> approve (pauses for a person) -> END

Every step is saved by SqliteSaver under a thread_id. Stop the process at
the approval pause, start it again with the same thread_id, and the run
continues from the saved checkpoint.

The model is a stand-in function so the kit runs with no API key. Replace
fake_llm() with a real chat model call when the flow works for you.

Run:
  python agent.py start  --thread demo-1 --message "My invoice is wrong"
  python agent.py resume --thread demo-1 --decision approve
"""
import argparse
import os
from typing import TypedDict

os.environ.setdefault("LANGGRAPH_STRICT_MSGPACK", "true")

from langgraph.checkpoint.sqlite import SqliteSaver  # noqa: E402
from langgraph.graph import END, START, StateGraph  # noqa: E402
from langgraph.types import Command, interrupt  # noqa: E402

DB_PATH = "checkpoints.sqlite"


class State(TypedDict, total=False):
    message: str
    category: str
    draft: str
    decision: str
    sent: bool


def fake_llm(prompt: str) -> str:
    """Stand-in for a model call: fixed rules, no network."""
    text = prompt.lower()
    if prompt.startswith("CLASSIFY:"):
        return "billing" if ("invoice" in text or "charge" in text) else "general"
    return "Thanks for writing in. A teammate will check this and reply today."


def triage(state: State) -> State:
    return {"category": fake_llm("CLASSIFY: " + state["message"])}


def draft_reply(state: State) -> State:
    return {"draft": fake_llm("REPLY: " + state["message"])}


def approve(state: State) -> State:
    # interrupt() saves a checkpoint and stops the run here. The value
    # passed to Command(resume=...) comes back as the return value.
    decision = interrupt({"category": state["category"], "draft": state["draft"]})
    return {"decision": decision, "sent": decision == "approve"}


def build(checkpointer):
    g = StateGraph(State)
    g.add_node("triage", triage)
    g.add_node("draft_reply", draft_reply)
    g.add_node("approve", approve)
    g.add_edge(START, "triage")
    g.add_edge("triage", "draft_reply")
    g.add_edge("draft_reply", "approve")
    g.add_edge("approve", END)
    return g.compile(checkpointer=checkpointer)


def main():
    p = argparse.ArgumentParser()
    p.add_argument("action", choices=["start", "resume"])
    p.add_argument("--thread", required=True)
    p.add_argument("--message", default="My invoice is wrong")
    p.add_argument("--decision", choices=["approve", "reject"], default="reject")
    a = p.parse_args()
    config = {"configurable": {"thread_id": a.thread}}
    with SqliteSaver.from_conn_string(DB_PATH) as saver:
        graph = build(saver)
        if a.action == "start":
            out = graph.invoke({"message": a.message}, config)
        else:
            out = graph.invoke(Command(resume=a.decision), config)
        if "__interrupt__" in out:
            print("PAUSED for approval:", out["__interrupt__"][0].value)
        else:
            print("FINISHED:", {k: out[k] for k in ("category", "decision", "sent")})
        print("next nodes:", graph.get_state(config).next)


if __name__ == "__main__":
    main()

Agent Setup Kits authored; uses documented SqliteSaver, interrupt and Command APIs

inspect_checkpoints.pyView file +

Read latest state, list history and fork a run with update_state

Download inspect_checkpoints.py ↓

"""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)

Agent Setup Kits authored

postgres_next_step.pyView file +

The same graph on PostgresSaver (not run)

Download postgres_next_step.py ↓

"""Production next step: the same graph on Postgres instead of SQLite.

Not run in the kit's check. Follows the langgraph-checkpoint-postgres
README at the pinned commit. Install first:

    pip install "langgraph-checkpoint-postgres==3.2.0" "psycopg[binary]"

(psycopg[binary] is for machines with no system libpq; the package itself
installs psycopg without extras.) Then set LANGGRAPH_POSTGRES_URI to a
Postgres database you control. Keep credentials in
the environment, not in this file.
"""
import os

from langgraph.checkpoint.postgres import PostgresSaver

from agent import build

DB_URI = os.environ["LANGGRAPH_POSTGRES_URI"]

with PostgresSaver.from_conn_string(DB_URI) as saver:
    saver.setup()  # the README says to call .setup() the first time
    graph = build(saver)
    config = {"configurable": {"thread_id": "demo-1"}}
    out = graph.invoke({"message": "My invoice is wrong"}, config)
    print(out.get("__interrupt__", out))

Agent Setup Kits authored; follows the checkpoint-postgres README

SOURCE.mdView file +

Original-project attribution, source hashes and adaptation notes

Download SOURCE.md ↓

# Source and attribution

LangGraph and its checkpointer libraries are built and maintained by
LangChain: https://github.com/langchain-ai/langgraph

Pinned packages and the release-tag commits they were checked at:
- langgraph 1.2.16, commit 41c9c22fdc83d68a2859d0c9a2b627c8615a792f
- langgraph-checkpoint 4.3.0, commit b7d053b256157ac6b8e8ff5a0783f8a446a9c89e
- langgraph-checkpoint-sqlite 3.1.2, commit 1074714c260486900d9bec9b5dd48e13883dd5df
- langgraph-checkpoint-postgres 3.2.0, commit d4149cc1f5384364d1a21092b4c2f582a6e7af8f

License: MIT (LICENSE-langgraph.txt is a verbatim copy of LICENSE at the
langgraph 1.2.16 commit).

agent.py, inspect_checkpoints.py and postgres_next_step.py were written by
Agent Setup Kits using the documented SqliteSaver, interrupt, Command,
get_state_history and update_state APIs. postgres_next_step.py follows the
checkpoint-postgres README and was not run. Checked 22 Oct 2026. Not
affiliated with or endorsed by LangChain.

Agent Setup Kits authored documentation for Pinned source guide with authored example files; upstream code and licenses remain attributed separately

LICENSE-langgraph.txtView file +

Upstream MIT license

Download LICENSE-langgraph.txt ↓

MIT License

Copyright (c) 2024 LangChain, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Verbatim copy of LICENSE at the langgraph 1.2.16 commit

LangGraph Postgres checkpointer: the production next step

The sqlite README describes SQLite as the choice "for local development, testing, or lightweight deployments." For a service with several workers, the next step is PostgresSaver from langgraph-checkpoint-postgres (3.2.0 at the time of checking). The graph doesn't change; only the saver does.

postgres_next_step.py shows the swap. Two points from the Postgres README:

  • Call .setup() the first time, to create the tables.
  • If you create the connection yourself instead of using from_conn_string, pass autocommit=True and row_factory=dict_row, or setup may not persist and reads fail.

Install with pip install "langgraph-checkpoint-postgres==3.2.0" "psycopg[binary]" if your machine has no system libpq. The Postgres README says the package installs psycopg 'without any extras'.

The script reads its connection string from LANGGRAPH_POSTGRES_URI. We did not run it.

06 / ORIGINAL WORK

Sources, pins, and license

This guide draws on LangGraph by LangChain, at the linked source revision. Agent Setup Kits is independent of the upstream project. Edition-specific changes are labeled in the file provenance.

LangGraph, by LangChain

Pinned source guide with authored example files

Open source
Sources this edition relies on
SourceWhat it supports
Immutable source revision (langgraph 1.2.16 tag) ↗Exact langgraph snapshot
libs/langgraph/pyproject.toml ↗version 1.2.16, requires-python >=3.10
libs/checkpoint-sqlite/README.md (checkpointsqlite 3.1.2 tag) ↗SqliteSaver.from_conn_string, AsyncSqliteSaver (langgraph.checkpoint.sqlite.aio, via aiosqlite), LANGGRAPH_STRICT_MSGPACK recommendation, use for local development, testing or lightweight deployments
libs/checkpoint-sqlite/pyproject.toml ↗version 3.1.2 and dependency ranges
Source revision (checkpoint 4.3.0 tag) ↗langgraph-checkpoint 4.3.0 snapshot
libs/checkpoint-postgres/README.md (checkpointpostgres 3.2.0 tag) ↗PostgresSaver.from_conn_string, .setup() on first use, psycopg installed without extras (psycopg[binary] as an option), autocommit and dict_row for manual connections
LICENSE ↗MIT license
Source versions and guide targets
ComponentPinSource
langgraph (PyPI)1.2.16Original source ↗
langgraph-checkpoint (PyPI)4.3.0Original source ↗
langgraph-checkpoint-sqlite (PyPI)3.1.2Original source ↗
langgraph-checkpoint-postgres (PyPI, next step)3.2.0Original source ↗

MIT

LangGraph and its checkpointer libraries are MIT. LICENSE-langgraph.txt is a verbatim copy; all other kit files are authored by Agent Setup Kits.

Read the original license ↗

Related guides

Part of: Which setup should I use to add human approval to an agent?

Your privacy choices

Choose optional tools. Rejecting them keeps the setup library available. Advertising consent stays off.

Choices stay in this browser for 90 days. You can change them using Privacy settings. Privacy and cookie details