Memory and storage
This page is about what troupekit remembers, and where. An agent can remember facts about the person it talks to, across runs. A run remembers its own progress as checkpoints, so it can resume. Underneath, troupekit stores five things: run checkpoints, memory logs, blobs, a job queue and a usage ledger. Troupe::builder() keeps all five in memory by default, and in one SQLite file once you call sqlite(path).
Long-term memory
If you want an agent to remember a user between runs, give it memory. With the knowledge feature on, .memory(AgentMemory::new(user, session)) gives the agent facts about one user and a summary of one session. It also gets five tools to read and change them: remember_fact, forget_fact and recall_facts for facts, and update_session_summary and read_session_summary for the summary. By default, the facts and the summary are also added to the start of every run's input, so the agent sees them without calling a tool.
Your code picks user and session, never the model. That is what keeps users apart: a model cannot ask for another user's facts, because it never chooses whose facts it sees. This test stores a fact for ada, then checks that bob cannot recall it and ada can:
#![allow(unused)]
fn main() {
let dir = tempfile::tempdir().unwrap();
let remember = calling("remember_fact", json!({"key": "color", "value": "blue"}));
let ada = || AgentMemory::new("ada", "s1").sqlite(db(&dir));
rememberer(remember, ada()).run("note it").await.unwrap();
let recall = || calling("recall_facts", json!({}));
let bob = AgentMemory::new("bob", "s1").sqlite(db(&dir));
let seen = rememberer(recall(), bob).run("what?").await.unwrap();
assert!(!seen.contains("blue"), "{seen}");
let seen = rememberer(recall(), ada()).run("what?").await.unwrap();
assert!(seen.contains("blue"), "{seen}");
}
calling and rememberer are helpers in the same test file: calling scripts a model that calls one tool, and rememberer builds an agent with the given memory.
| Method | Meaning | Default |
|---|---|---|
sqlite(path) | the SQLite file facts and summaries live in | required, unless the agent has .knowledge(..), whose store is used |
preamble(on) | prepend facts and summary to each run | true |
fact_caps(bytes, facts, log) | bytes per fact, facts per user, fact log length | 1024, 200, 1000 |
max_summary_bytes(n) | session summary size | 4096 |
preamble_budget_tokens(n) | preamble size; facts that do not fit are left out | 800 |
user and session are 1 to 256 bytes each, checked at build.
Run checkpoints
A checkpoint is the saved state of a run after a step. .checkpoints(storage) picks where an agent or graph keeps them, and that choice decides whether a run can be resumed:
| Storage | Resume |
|---|---|
Storage::memory(), the default | no: each run gets a fresh in-memory store |
Storage::sqlite(path) | yes, with resume(run_id), also from a later process; the file is opened at build |
Storage::custom(store) | depends on the store: any Arc<dyn CheckpointStore>, such as one the host already opened |
The SQLite store
SqliteStore puts everything in one file: checkpoints with their history, memory logs, blobs, the job queue and the usage ledger. It runs SQLite in WAL mode and carries its own schema migrations. When you open a file written by an older troupekit, it is migrated on open. A file from a newer version is refused, because an older build cannot know what the newer schema means.
| Setting | Default |
|---|---|
durability | Durability::Full: every commit uses fullfsync and survives power loss. Normal is faster and can lose the last commits on power loss, never on a process kill. |
max_state_bytes | 64 MiB per checkpoint state |
max_blob_bytes | 64 MiB per blob |
max_history_steps | 100 000 |
max_history_bytes | 1 GiB of state returned by one history call |
busy_timeout_ms | 5 000 |
secure_delete | on: deleted rows, including a removed chunk's text and vector, are overwritten |
key | none; with the sqlcipher feature, opens the file encrypted with SQLCipher |
The defaults favour safety over speed. Durability::Full survives power loss; switch to Normal only if losing the last few commits on power loss is acceptable for your app.
Open a store with SqliteStore::open(path), or with SqliteStore::builder(path) to change the settings, and hand it to Troupe::builder().sqlite_with(builder) or Storage::custom(..).