Store¶
Cross-thread durable memory. See the Cross-thread memory guide.
agentflow.store
¶
Store: durable, cross-thread application memory (distinct from checkpoints).
A checkpointer persists one thread's execution state for resume; a store holds
durable key-value data shared across threads (profiles, facts, long-term
memory). See :mod:agentflow.store.base for the protocol.
Store
¶
Bases: Protocol
Durable, namespaced key-value memory shared across threads.
Source code in agentflow/store/base.py
put
async
¶
put(namespace: Namespace, key: str, value: Any, *, ttl: float | None = None, if_absent: bool = False) -> Item
Upsert value at (namespace, key) and return the stored item.
ttl is a lifetime in seconds from now; None means no expiry. An
upsert preserves the original created_at and refreshes
updated_at.
When if_absent is True the write is conditional: it succeeds only if
no live item exists at (namespace, key), otherwise it raises
:class:~agentflow.errors.StoreConflict. An expired item counts as
absent, so its key can be reclaimed. This is an atomic create — two
writers racing the same key give exactly one winner and one conflict —
which is how a single-flight claim is built (see
:class:~agentflow.prebuilt.IdempotentOp). if_absent ignores no
other semantics: a successful conditional write behaves like a first
insert (fresh created_at).
Source code in agentflow/store/base.py
delete
async
¶
search
async
¶
search(namespace_prefix: Namespace, *, limit: int = 100, offset: int = 0) -> list[Item]
Return items whose namespace starts with namespace_prefix,
ordered by namespace then key, skipping expired items. limit and
offset paginate.
Source code in agentflow/store/base.py
list_namespaces
async
¶
Return the distinct namespaces that currently hold items, filtered
to those starting with prefix and ordered lexicographically.
Source code in agentflow/store/base.py
Item
dataclass
¶
One stored value plus its addressing and timestamps.
created_at / updated_at are ISO-8601 strings (UTC). expires_at,
when set, is the ISO time after which the item is considered gone; a store
must not return an expired item from get or search.
Source code in agentflow/store/base.py
MemoryStore
¶
Keeps items in a nested dict keyed by namespace then key. Not durable.
Expiry is lazy: an expired item is skipped on read and dropped when next touched, so no background sweeper is needed.
Source code in agentflow/store/memory.py
PostgresStore
¶
Durable namespaced key-value store backed by a PostgreSQL table.
Pass either a dsn or an existing asyncpg pool via pool.
table names the store table (created on first use).
Source code in agentflow/store/postgres.py
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 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 | |
close
async
¶
Close the connection pool (only if this store created it).