RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Fredoline Eruo
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /Courses
  5. /LangGraph for Local Agents
  6. /Ch. 15
LangGraph for Local Agents

15. Persistence

Chapter 15 of 18 · 20 min
KEY INSIGHT

Checkpointers are interchangeable backends. `MemorySaver` for development, `SqliteSaver` for single-machine deployment, and `PostgresSaver` for distributed production. Session artifacts that need to survive beyond the current session should be stored separately in a dedicated database.

Persistence beyond development checkpointing requires a durable storage backend. LangGraph's checkpointer interface supports multiple backends: MemorySaver (development), SqliteSaver (single-machine production), and PostgresSaver (multi-machine production). The same code pattern works across all backends—swap the checkpointer and the rest of your code is unchanged.

# Development
from langgraph.checkpoint.memory import MemorySaver
checkpointer = MemorySaver()

# Single-machine production
from langgraph.checkpoint.sqlite import SqliteSaver
checkpointer = SqliteSaver.from_conn_string("./checkpoints.db")

# Multi-machine production
from langgraph.checkpoint.postgres import PostgresSaver
checkpointer = PostgresSaver.from_conn_string(os.environ["DATABASE_URL"])

To persist session state across server restarts with SQLite:

app = builder.compile(checkpointer=SqliteSaver.from_conn_string("./sessions.db"))

# Save a session
config = {"configurable": {"thread_id": "user_42_session_1"}}
app.invoke({"task": "research the new LLM releases"}, config=config)

# Resume on next server start
resume_config = {"configurable": {"thread_id": "user_42_session_1"}}
app.invoke(Command(resume={}), config=resume_config)

For true long-term memory beyond the current session, store final state artifacts in a dedicated database (Postgres, SQLite, or a vector store) and read them in at the start of new sessions:

def load_historical_context(thread_id: str) -> dict:
    conn = sqlite3.connect("sessions.db")
    cursor = conn.execute(
        "SELECT state FROM sessions WHERE thread_id = ? ORDER BY checkpoint_id DESC LIMIT 1",
        (thread_id,)
    )
    row = cursor.fetchone()
    return json.loads(row[0]) if row else {}

Local verification checkpoint

Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.

Local verification checkpoint

Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.

EXERCISE

Compile a graph with SqliteSaver. Run it with a thread_id, shut down and restart Python, then resume the same thread from disk. Verify the checkpoint history is present after restart.

← Chapter 14
Error Handling
Chapter 16 →
Streaming Agent Output