Checkpointing¶
The checkpoint model and the checkpointer implementations. See the Checkpointing guide.
agentflow.checkpoint
¶
Checkpointing: durable run state, resume, and time-travel.
Checkpoint
dataclass
¶
One persisted point in a run's history.
next is the frontier of node names to run when resuming. An empty
next with interrupted=False means the run finished. When
interrupted is True the run is suspended: interrupt_node requested
it and interrupt_payload is what a human must resolve; next still
holds the frontier to resume once an answer is supplied.
A suspend has a kind (:attr:suspend_kind). "human" waits for an
external :meth:resume with a value (human-in-the-loop). "timer" waits
only for the clock: :attr:wake_at is the earliest ISO time the run should
be resumed, and resuming re-runs the suspending node (which polls again).
Both share the interrupt machinery — a timer wait is an interrupt whose
resolver is the clock, not a person.
Source code in agentflow/checkpoint/base.py
suspend_kind
property
¶
"human" or "timer" while suspended, else None.
Derived so the on-disk shape stays compatible: a suspend with
wake_at set is a timer wait; a suspend without it waits for a human.
Checkpointer
¶
Bases: Protocol
Persists and retrieves checkpoints by thread and step.
Source code in agentflow/checkpoint/base.py
put
async
¶
put(cp: Checkpoint, *, if_revision: int | None = None) -> str
Persist cp and return an id (thread + step is sufficient).
When if_revision is given, the write is conditional: it succeeds
only if the currently stored revision for (cp.thread, cp.step)
equals if_revision (or nothing is stored and if_revision is 0),
otherwise it raises :class:~agentflow.errors.CheckpointConflict. This
gives optimistic concurrency for two resumes racing the same step.
None (default) is an unconditional upsert.
Source code in agentflow/checkpoint/base.py
get
async
¶
get(thread: str, step: int | None = None) -> Checkpoint | None
Return the checkpoint at step, or the latest when step is
None. Returns None if the thread has no checkpoints. The returned
checkpoint's revision reflects how many times that step was
written (0 if the backend doesn't track it).
Source code in agentflow/checkpoint/base.py
history
¶
history(thread: str) -> AsyncIterator[Checkpoint]
list_threads
async
¶
list_threads(*, limit: int = 100, offset: int = 0) -> list[ThreadInfo]
Return a summary of each stored thread (latest step + status),
ordered by thread id. Enables control-plane enumeration of runs
without reading full state. limit/offset paginate.
Source code in agentflow/checkpoint/base.py
delete_thread
async
¶
prune
async
¶
Delete checkpoints for thread older than a bound; return the
count removed. before_step deletes steps strictly less than it;
older_than is an ISO timestamp compared against each checkpoint's
ts. At least one bound should be given.
Source code in agentflow/checkpoint/base.py
ThreadInfo
dataclass
¶
A one-line summary of a thread for control-plane listing.
Derived from the thread's latest checkpoint so a caller can enumerate runs (running / interrupted / finished) without reading full state.
Source code in agentflow/checkpoint/base.py
MemoryCheckpointer
¶
Keeps checkpoints in a dict keyed by thread. Not durable.
Source code in agentflow/checkpoint/memory.py
FileCheckpointer
¶
Persist checkpoints under root/<thread>/<step>.json.
Single-writer contract: this checkpointer is safe for one process writing a
given thread at a time. Individual file writes are atomic (temp + replace),
so a reader never sees a partial file, but there is no cross-process lock
or revision check — two processes writing the same thread can interleave
steps and corrupt history. For multi-process or concurrent-runner durability
use :class:~agentflow.checkpoint.sqlite.SqliteCheckpointer, which enforces
atomic per-(thread, step) revisions in a transaction.
Files and directories are created owner-only (0o600/0o700) by default so a
persisted run's state is not world-readable. Pass secure_permissions=
False to disable (e.g. on filesystems that don't support it).
redact optionally masks sensitive values in the persisted state
before writing. WARNING: a redacted checkpoint cannot be resumed to the
exact original state — masked values are lost. Use redaction only for
archival/debug copies, not for the checkpointer you resume from. Default is
no redaction.
Source code in agentflow/checkpoint/file.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
SqliteCheckpointer
¶
Durable checkpointer backed by a SQLite database file.
Source code in agentflow/checkpoint/sqlite.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
PostgresCheckpointer
¶
Durable checkpointer backed by a PostgreSQL table.
Pass either a dsn (postgresql://user:pw@host:port/db) or an existing
asyncpg pool via pool. table names the checkpoints table (it is
created on first use). redact optionally masks sensitive values in the
persisted state (see :class:~agentflow.checkpoint.file.FileCheckpointer
for the resume-fidelity caveat).
Source code in agentflow/checkpoint/postgres.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
close
async
¶
Close the connection pool (only if this checkpointer created it).
RedisCheckpointer
¶
Durable checkpointer backed by a Redis server.
Pass either a url (redis://host:port/db) or an existing async
client via client. prefix namespaces all keys.
Source code in agentflow/checkpoint/redis.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |