TOOL WIKI · MEMORY & STATE
SQLite
Stores structured records in an application-local database file.
Jump to a section 10 sections
EXAMPLE USE CASE
Resume a local run from a stored checkpoint
A returning user’s preference or an unfinished run needs an explicit owner, storage lifetime and recall rule.
- Input
- Tenant a, run-104, step 2 and a packed-status payload.
- Expected output
- The same checkpoint after reopening the database.
- Success check: A second run reopens the same database and reads step 2 with the packed payload.
- Try a failure: The other tenant must have no row for this run ID.
Example scope: Actual file-backed persistence; a checkpoint is execution state, not a long-term inferred preference.
Separate working conversation state from candidate long-term facts.
candidateTo 02 · Write policyRetain only permitted information and preserve where it came from.
retainTo 03 · SQLiteLocal prototypes, desktop agents, and small persistent workflows. Plan for concurrency, backups, and the limits of the deployment environment.
recordsTo 05 · Context builderUse verified tenant and subject identifiers when retrieving memory.
queryBack to 03 · SQLiteChoose useful records within the current context budget.
contextBack to 01 · InteractionApply corrections and deletion to records, derived indexes, and caches.
maintainBack to 03 · SQLite
Local prototypes, desktop agents, and small persistent workflows. Plan for concurrency, backups, and the limits of the deployment environment.
When to consider it
- Local prototypes, desktop agents, and small persistent workflows.
A design decision to make
- Plan for concurrency, backups, and the limits of the deployment environment.
Prerequisites and setup
- Python 3.11+; sqlite3 is included in the standard library.
python3 -m venv .venv
source .venv/bin/activateTry a small integration
memory.py
import sqlite3
con = sqlite3.connect("state.sqlite")
con.execute("CREATE TABLE IF NOT EXISTS checkpoints (tenant TEXT, run TEXT, step INTEGER, payload TEXT, PRIMARY KEY (tenant,run))")
with con:
con.execute("INSERT INTO checkpoints VALUES (?,?,?,?) ON CONFLICT(tenant,run) DO UPDATE SET step=excluded.step,payload=excluded.payload",
("a","run-104",2,'{"status":"packed"}'))
row = con.execute("SELECT step,payload FROM checkpoints WHERE tenant=? AND run=?",("a","run-104")).fetchone()
assert row[0] == 2
assert con.execute("SELECT * FROM checkpoints WHERE tenant=? AND run=?",("b","run-104")).fetchone() is None
print(row)Run and check the result
python memory.py- A second run reopens the same database and reads step 2 with the packed payload.
- The other tenant has no checkpoint. A checkpoint records execution position, not an inferred long-term preference.
Common failures
- Database locked: keep transactions short and understand SQLite’s single-writer behavior.
- A process-local file is not automatically shared durable storage across serverless instances.
Production decisions
- Define allowed memory types, evidence/provenance, correction, expiry and user deletion before accepting automatic writes.
- Derive user and tenant scope from authenticated application state. Test cross-user recall, expired facts and deletion from every derived index.
- Back up using SQLite-aware APIs; decide on WAL mode, busy timeouts, file ownership and a migration path before adding concurrent writers.
Keep exploring
Explore the same layer
Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.