windlass.agent.checkpoint¶
checkpoint
¶
Checkpointing — durable agent state.
An agent run is a sequence of model calls and tool executions. Checkpointing snapshots that state after every step, which buys three things:
- Resumability. A run interrupted for human approval, or by a crash, picks up where it stopped instead of starting over (and re-paying for every token already spent).
- Multi-turn conversations. A
thread_idmaps to accumulated state, so the next message continues the same run. - Time travel. Every step is retained, so you can inspect exactly what the agent believed at step 3 when debugging why step 4 went wrong.
Two backends ship: in-memory (fast, per-process) and SQLite (durable, shared between processes, stdlib-only).
Example
saver = MemoryCheckpointer() saver.put("thread-1", {"step": 1, "messages": []}) saver.get("thread-1")["step"] 1
Checkpointer
¶
Bases: ABC
Stores and retrieves agent state by thread.
Implementations must be safe to use from multiple threads, since one agent instance typically serves many concurrent conversations.
put
abstractmethod
¶
Save a state snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
Conversation / run identifier. |
required |
state
|
dict[str, Any]
|
JSON-serialisable state. |
required |
Raises:
| Type | Description |
|---|---|
SerializationError
|
When the state cannot be stored. |
Source code in src\windlass\agent\checkpoint.py
get
abstractmethod
¶
history
abstractmethod
¶
Return recent snapshots, newest first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
Conversation identifier. |
required |
limit
|
int
|
Maximum snapshots to return. |
20
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
Snapshots, newest first. |
Source code in src\windlass\agent\checkpoint.py
delete
abstractmethod
¶
MemoryCheckpointer
¶
Bases: Checkpointer
Keeps checkpoints in a dict.
Fast and dependency-free, but per-process and lost on restart. Right for tests, notebooks and single-process services; wrong for anything that needs a resumed run to survive a deploy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_history
|
int
|
Snapshots retained per thread. Older ones are dropped. |
50
|
Example
saver = MemoryCheckpointer() saver.put("t", {"step": 1}) saver.put("t", {"step": 2}) saver.get("t")["step"], len(saver.history("t")) (2, 2)
Source code in src\windlass\agent\checkpoint.py
put
¶
Append a snapshot, trimming the oldest beyond max_history.
Source code in src\windlass\agent\checkpoint.py
get
¶
Return the newest snapshot, or None.
history
¶
Return recent snapshots, newest first.
delete
¶
SQLiteCheckpointer
¶
Bases: Checkpointer
Persists checkpoints to a SQLite database.
Survives restarts and is shared between processes on one machine — enough for a single-node deployment, and it needs nothing beyond the standard library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Database file. Parent directories are created. |
'.windlass/checkpoints.db'
|
max_history
|
int
|
Snapshots retained per thread. |
50
|
Raises:
| Type | Description |
|---|---|
SerializationError
|
When the database cannot be opened. |
Note
Each call opens its own connection. That costs a little per write and buys thread safety without a connection pool — the right trade at the rate an agent checkpoints.
Example
import tempfile, pathlib db = pathlib.Path(tempfile.mkdtemp()) / "state.db" saver = SQLiteCheckpointer(db) saver.put("t", {"step": 7}) SQLiteCheckpointer(db).get("t")["step"] 7
Source code in src\windlass\agent\checkpoint.py
put
¶
Insert a snapshot and prune old ones.
Raises:
| Type | Description |
|---|---|
SerializationError
|
When the state is not JSON-serialisable or the write fails. |
Source code in src\windlass\agent\checkpoint.py
get
¶
history
¶
Return recent snapshots, newest first.
Source code in src\windlass\agent\checkpoint.py
delete
¶
Discard a thread's snapshots.
Source code in src\windlass\agent\checkpoint.py
threads
¶
Return the known thread ids.