SqliteCheckpointSaver
What it is
- A SQLite-backed checkpoint saver that extends
langgraph.checkpoint.memory.InMemorySaver. - Keeps LangGraph’s in-memory checkpoint state, but persists it to a local SQLite database after each write/delete operation.
- Thread-safe via an internal re-entrant lock (
threading.RLock).
Public API
Class: SqliteCheckpointSaver(InMemorySaver)
__init__(path: str, journal_mode: str = "WAL", busy_timeout_ms: int = 5000) -> None- Creates/opens a SQLite DB at
path, initializes schema, and loads previously persisted state (if present).
- Creates/opens a SQLite DB at
get_tuple(config: RunnableConfig) -> CheckpointTuple | None- Thread-safe wrapper around
InMemorySaver.get_tuple.
- Thread-safe wrapper around
list(config: RunnableConfig | None, *, filter: dict[str, Any] | None = None, before: RunnableConfig | None = None, limit: int | None = None)- Thread-safe generator wrapper around
InMemorySaver.list.
- Thread-safe generator wrapper around
put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata, new_versions: ChannelVersions) -> RunnableConfig- Stores a checkpoint via
InMemorySaver.putand then persists the full state to SQLite.
- Stores a checkpoint via
put_writes(config: RunnableConfig, writes, task_id: str, task_path: str = "") -> None- Stores writes via
InMemorySaver.put_writesand then persists the full state to SQLite.
- Stores writes via
delete_thread(thread_id: str) -> None- Deletes all checkpoints for a thread via
InMemorySaver.delete_threadand then persists the full state to SQLite.
- Deletes all checkpoints for a thread via
close() -> None- Closes the underlying SQLite connection.
Configuration/Dependencies
- Dependencies
langgraph.checkpoint.memory.InMemorySaversqlite3,pickle,threading,os,time
- SQLite behavior
- Creates a table
checkpoint_statewith a single row (id = 1) holding:storage(pickled),writes(pickled),blobs(pickled),updated_at(timestamp)
- PRAGMAs set on init:
journal_mode(default"WAL")busy_timeout(default5000ms)synchronous=NORMAL
- Creates a table
- Filesystem
- Ensures the directory for
pathexists (os.makedirs(os.path.dirname(path) or ".", exist_ok=True)).
- Ensures the directory for
Usage
from naas_abi_core.services.agent.SqliteCheckpointSaver import SqliteCheckpointSaver
# Create/open a persisted checkpoint store
saver = SqliteCheckpointSaver(path="./checkpoints.sqlite")
# Use 'saver' wherever a LangGraph checkpointer/saver is expected.
# (Checkpoint creation and config structure depend on LangGraph usage.)
# Always close when done
saver.close()
Caveats
- Uses
picklefor persistence; the loaded data is assumed to come from the same local process/database (not intended for untrusted input). - Persists the entire in-memory state on each
put,put_writes, anddelete_thread(may be costly for large stores). close()only closes the SQLite connection; it does not explicitly flush beyond the commits already performed during persistence.