# Memory System

The memory layer in Agenvoy has three tiers for conversation memory plus a cross-session error memory tier.

| Tier | Backed by | Scope |
|---|---|---|
| 1. Context window (16 messages + summary) | `history.json` + `summary.json` | session |
| 2. Semantic search (recent) | ToriiDB `DBSessionHist` (vector) | session |
| 3. Full-text archive (all history) | SQLite FTS5 via go-sqlkit | session |
| Error memory | ToriiDB `error_memory` (90d TTL) | cross-session |

Operator notes (SQLite `note` + `note_fts5`, the `find_note` tool, `/v1/note*`) were removed in v1.0.23; there is no global note tier any more.

## Storage layout

| Store | Content | Lifecycle |
|---|---|---|
| `history.json` | Recent messages (hot, LLM reads every turn) | Auto-compacted at 4 MiB |
| ToriiDB `DBSessionHist` | Recent messages with embeddings | Cleaned on compact (entries < cutoff removed) |
| SQLite `messages` | All messages ever written (dual-write) | Cleared on reset / remove-session |
| SQLite `message_meta` | `start_at` — compact cutoff timestamp | Cleared on reset / remove-session |
| `summary.json` | Rolling summary blob | Survives reset |
| ToriiDB `error_memory` | Resolved tool error records with their fix, written by `write_error` (`error_history(mode=write)` was Removed in v1.3.11) | 90d TTL (refresh on hit) |

## Migration note

Sessions and error memory used to live under per-session JSON files. They now live in the embedded stores under `~/.config/agenvoy/.store/` — ToriiDB (`db_0` tool cache, `db_1` chat vectors, `db_2` error memory, `db_3` online markers) and `history.db` for session config, the message archive, action history, file history and usage. Notes moved from ToriiDB into the SQLite `note` table in v0.35.3 and were removed altogether in v1.0.23, including the notes migration at daemon start; the `state` table was dropped in v0.35.3. `bot.json` / `bot.md` / `config.json` / `status.json` / `usage.log` / `summary.meta.json` were migrated in at daemon startup up to v1.1.1; v1.1.2 removed those migrations along with the SQLite column upgrades for databases older than v1.0, so an install that old should pass through v1.1.1 first. Do not reintroduce JSON paths.
