The first sign that my assistant's memory was broken was a database row that measured 507 characters. It should have held a conversation turn. It held a six-character [USER] tag, a space, and exactly 500 characters of a question.
I run Hermes on a Mac mini that stays on. Hermes is the agent harness; Mnemosyne is an existing memory plugin I installed inside it. The project was the setup, the fixes, and the rules around what gets stored. Most days the model is deepseek-v4.1-flash on a $10 a month OpenCode Go plan. In my setup, Hermes is supposed to write each turn into Mnemosyne's SQLite database. When I queried the table, the conversation rows had my side and nothing from the assistant. A long brief I'd sent was remembered as its first paragraph. The summaries were summarizing questions with no answers attached.
That one row led me through the whole system. A chat window makes memory look automatic: you type, the reply references something from yesterday, and it feels like the model knows you. It doesn't. The model is a stateless function that turns text into more text, and everything that looks like memory is the harness around it deciding what to send, what to save, and what to throw away.
Without memory, every session starts with me explaining the homelab, the site stack, the model policy, and the way I like replies. With it, the first message can be "the P520 won't boot" and the assistant already knows what the P520 is. That's the practical difference, and it's why I kept digging after the 507-character row.
The model is the part that predicts tokens. The harness is everything else: the prompt assembly, the tools, the conversation history, the compaction, the databases, the cron jobs. When people say a model remembers, they usually mean the harness resends something. When memory breaks, the model is almost never the thing that broke.
The model has no memory
Every request to the API Hermes uses is a fresh call. The model reads the text in the request, writes a reply, and stops. Its weights don't change during the conversation. There's no hidden state carrying your last message forward, and no folder inside the model where yesterday's conversation is sitting. Some providers now offer conversation state as a service, where the API stores the thread and rebuilds the prompt on the next call. The weights still don't change, and the text still has to be stored somewhere.
The context window is the only text the model can attend to during a call. It holds a fixed number of tokens, sometimes whole words and sometimes pieces of words, and everything in it competes with everything else for the model's attention. A thousand tokens is roughly 750 words. The limit covers the input and the output together. A new session starts with no conversation history, so whatever the assistant knows has to be assembled before the call.
Harnesses work around this with four moves. They replay the conversation so a follow-up has something to refer to. They compress older turns when the history gets too long. They retrieve relevant text from outside the window and paste it in. And they store facts in files or databases that survive a restart. Hermes does all four.
Compaction is the lossy one. When the request reaches 12% of the model's context window, Hermes summarizes older turns and drops the originals from the prompt. I set the threshold low to keep requests cheap; the cost is that a detail from twenty turns ago can disappear without a trace. The summary is supposed to keep what matters, but it's a guess about what future turns will need.
Hermes builds the request as a stack. At the base is the system prompt: the instructions that define the assistant. Then the tool definitions: JSON descriptions of every function the model is allowed to call. Then the conversation history. Then the new user message, sometimes with a retrieved memory block inserted above it. The provider may serialize these sections in a different order, but this is how Hermes assembles them.
Memory can enter at any of those layers. SOUL.md, MEMORY.md, and USER.md go into the system prompt. Skills go into the system prompt as an index. Mnemosyne goes in as a block attached to the user message. The vault and the transcripts don't go in unless the model calls a tool to fetch them.
The model can only work with what the harness assembled. Once the prompt is a document, the design questions change: what to write down, where to put it, when to fetch it, and how to correct it. Those are database and policy questions, and they're most of the work.
Why a bigger window isn't memory
The first instinct with any memory problem is to get a bigger context window. It helps, but it doesn't solve the problem, for three reasons.
The first is cost. Every token in the window has to be in the request; caching can change what the provider charges to process a repeated prefix, but it doesn't remove the text from the prompt. A long prompt is paid for again and again, and attention cost grows faster than length, so long prompts are slower as well as more expensive. A bigger window doesn't make the text free.
The second is attention. Models don't read a long prompt evenly. Long-context benchmarks keep finding that information near the start and end of a prompt gets used more reliably than information buried in the middle, and a prompt full of irrelevant text makes the relevant text harder to find. People have started calling the general degradation "context rot." The model doesn't have a highlight function; it has to infer from the text what matters, and a lot of noise makes that inference worse.
The third is persistence. The window ends when the request ends. A bigger window lets you send more history in one call, but it doesn't decide what to keep for the next call, and it doesn't survive a new session. You can have a million-token window and still start tomorrow with nothing.
Fine-tuning isn't a good answer for facts you need to edit. You could train facts into the weights, but then you can't inspect a single fact, correct it, or delete it without another training run. Memory needs to be editable, and weights are not an editable database.
So the hard part isn't storing text. It's choosing which text to send. That's a selection problem, and it's the reason a memory system looks more like a search engine with a write policy than like a bigger hard drive.
Four kinds of memory
The vocabulary I use comes from cognitive science, but the engineering is simpler than the names suggest. I keep four kinds of memory, and each one lives in a different place because it has a different job.
| Kind | What it holds | Where it lives | Why there |
|---|---|---|---|
| Working | The current turn and recent messages | The context window, plus a short-lived table in Mnemosyne | Fast access, expires quickly |
| Episodic | What happened, when, and with whom | Mnemosyne's summaries and raw turns | Chronological recall without replaying everything |
| Semantic | Stable facts and decisions | MEMORY.md, USER.md, canonical facts, the vault | One authoritative answer per fact |
| Procedural | How to do a task | Skills | Loaded only when the task matches |
Working memory is the smallest and the fastest. It's the current conversation plus a table of recent turns with a seven-day lifetime, so the agent can search what was said this week without carrying the whole week in every prompt.
Episodic memory is the diary. It's the consolidation pass that turns recent turns into summaries, and the raw turns underneath. It answers "what did we do about the P520" without needing the exact transcript.
Semantic memory is the facts. Some of them are stable enough to paste into every prompt: the machine names, the network layout, the way I like replies. Some of them are canonical slots with exactly one value: which model Hermes runs, where the vault lives, which machine is the Proxmox host. The vault is the long-form version: project notes, device decisions, the writeups I publish.
Procedural memory is the how-to. Skills are files that describe a workflow, with the commands and pitfalls that make it repeatable. I have 241 of them, 98 MB with their references and scripts. Hermes injects their names and one-line descriptions, about 3,000 tokens, and loads a full file only when a task matches, so the size of the library doesn't set the size of the prompt.
Most agent frameworks I've used end up with at least three of these, whether or not they name them, and the categories are less important than keeping them separate. If you put a procedure in the always-on memory file, you pay for it on every turn and it still doesn't give you the commands. If you put a stable fact only in a transcript, retrieval has to guess that it matters. Each kind of memory wants a different storage and a different lifetime.
The three files that ride along
The always-on layer is three Markdown files: SOUL.md, MEMORY.md, and USER.md.
SOUL.md sets the assistant's tone, defaults, and the rules I don't want to repeat. It's 2,715 characters. MEMORY.md carries the setup: machine names, network layout, conventions, cron behavior. USER.md is about me: school, preferences, the way I like replies.
MEMORY.md is 2,164 characters against a 2,200 cap. USER.md is 1,370 against a 1,375 cap. Both are close to the limit; neither has room for another line. The cap is a write limit, not a truncation; nothing cuts an existing file down automatically.
The cap forces a decision about what belongs in every prompt. These files are pasted into every request, so a sentence added there is paid for on every turn. I can write a new line in seconds; deciding which old line to delete is the work. Project details go in the vault, procedures go in skills, and a story about one debugging session goes in Mnemosyne. The files hold only what applies everywhere.
The order matters too. SOUL.md is stable, so it sits at the front of the prompt. The memory files and the skills index change rarely. The recalled memory block and the timestamp change on every call, so they sit at the end. When a provider supports prefix caching, the stable part can be served from cache and only the tail gets rebuilt.
The diary in SQLite
The three files hold about 1,600 tokens between them, and the two capped ones are pressed against their caps, so anything that happened last Tuesday has to live somewhere else. That's Mnemosyne. It's a memory plugin for Hermes, version 0.7.7, backed by a 28 MB SQLite file on the Mac mini.
SQLite is a single file with a SQL database inside. No server, no daemon, no network. The whole memory store is one file I can back up with SQLite's own backup command, or open with a CLI. The file doesn't depend on Hermes being installed.
A memory store is infrastructure, and if I can't inspect it I can't debug it. When the 507-character row showed up, I opened the database and looked at it. I didn't need a dashboard, an API, or a support ticket. I needed a SQL query.
SQLite has limits. It allows multiple readers but one writer at a time, so it's a bad fit for a team of agents writing concurrently. For one person and a handful of processes, it's fine. If this were a shared service, I'd want a server with row-level locking and permissions. At my scale, a file is the right amount of machinery.
Each memory is stored as text and as an embedding. An embedding is a list of 384 numbers produced by a small local model, bge-small-en-v1.5. Text with similar meaning gets similar numbers. The P520 is my Proxmox host; a memory that says "the P520 won't boot" and one that says "the Proxmox host is down" land close together even though they share almost no words. The numbers are quantized to int8 to keep the file small, and the embedding model runs locally, so indexing a memory doesn't call an API.
Meaning alone misses exact strings like a model name or an error code. So recall is hybrid: half vector similarity, 30% SQLite full-text search, 20% the importance score set when the memory was written. The vector side handles paraphrase, the full-text side catches exact words, and importance is a prior for memories I marked as worth keeping. FTS5 tokenizes text, so a punctuation-heavy error code can still slip through.
The automatic prefetch gives recent memories a boost and drops weak matches. It pulls at most five memories.
When I send a message in a normal chat, Hermes searches Mnemosyne before it calls the model. It uses my message as the query and pulls back the top five. The canonical slots are the single-value facts I mentioned: which machine Hermes runs on, what model it uses, where the vault lives. When one matches, it gets appended to the same block. The result is pasted into my message under a ## Mnemosyne Context heading.
The transcript keeps my original message. The block exists for that one call, and the next turn searches again. That's important: the memory block isn't a permanent edit to the conversation. It's a temporary attachment, rebuilt from scratch each time.
The write path is the hard part
Retrieval gets the attention because it's visible, but the write path is where the system failed for me.
Every turn is stored in a working-memory table, about 2,200 rows right now, with a seven-day lifetime. Every ten turns and at the end of a session, a consolidation pass called sleep takes recent turns and writes episodic summaries, 835 so far. The summaries are what survive after the raw turns expire.
That's the theory. The 507-character row was the practice. Hermes had been storing my side of the conversation, cut off at 500 characters, and nothing from the assistant. The bug wasn't in the model or the embedding. It was in the code that decided what a "turn" was.
The fix was to store both sides, with a higher cap of 4,000 characters each. That's a config change, but it changes the shape of the database: the file will grow faster, the summaries will have answers to work with, and the retrieval queries will have more text to match. I don't know yet whether the summaries get better. That's the next thing to measure.
Sleep is a maintenance job over text. It groups recent turns, writes summaries, and lets old working rows expire. It doesn't train the model, and it doesn't invent facts. The compression is lossy by design. A summary that kept every detail would be as big as the transcript, and the point of the summary is to fit in a future prompt. The raw transcript is the fallback when the summary isn't enough. That's why the transcripts are a separate store instead of being deleted after consolidation.
A retrieval system over a database that only contains half the conversation is still a broken memory system.
The vault is the canon
Two stores are too big to inject: the vault and the transcripts. They're on-demand, and the agent has to choose to call them.
The vault is my Obsidian notes, about 700 of them, indexed into 8,700 chunks. The index embeds each chunk with a small sentence model, fuses that with BM25 keyword search, then reranks the strongest candidates with a cross-encoder. A cross-encoder reads the query and each candidate together and gives a more accurate score. The result comes back through an MCP tool called search_vault.
MCP, the Model Context Protocol, is a standard way for an agent to call external tools. The model doesn't get the whole vault; it gets a tool description and the ability to ask for a search. That keeps the prompt small and makes the vault's size irrelevant until the agent actually needs something.
RAG, the general name for this pattern, is search then paste. The quality depends on how the notes are chunked, how good the embeddings are, how the ranking works, and whether the model uses what it gets. A bad chunk can split a decision in half. A bad query can miss the note that matters. A good reranker can save a mediocre first pass, but it can't find a note that was never indexed.
The vault is the source of truth because it's human-readable, git-backed, and I can read it without any agent running. It holds project notes, device decisions, and the writeups I publish. The vault is where a decision lives after I've written it down, not in a chat log. I'd rather the agent look things up than have Mnemosyne's version of a decision quietly override what I wrote down.
That's a deliberate hierarchy. Mnemosyne is the conversation, and the vault is the note I wrote after I made the decision. The rule is that the vault wins when they disagree. That's a convention I enforce when I edit memories, not something SQLite enforces; if I update the vault and leave the old memory in place, both versions can still reach the prompt.
The transcripts are the raw record. state.db is a 1 GB SQLite file with 816 sessions and 96,000 messages, indexed with FTS5 for full-text search. session_search can find an exact phrase from a conversation months ago. It isn't memory in the sense of distilled facts. It's the record you go back to when the summary isn't enough.
The three stores do different jobs. Mnemosyne holds the conversation and the episodes, the vault holds the decisions, and the transcripts hold the evidence. Collapsing them into one store would make the diagram cleaner, but they have different sizes, different lifetimes, and different privacy rules.
One database, three harnesses
I use more than one coding agent. Claude Code and Codex need the same context Hermes has, or I end up repeating myself in three terminals.
The first attempt was a separate self-hosted service called Honcho. It had its own database, its own embeddings, and a background worker that was supposed to derive facts from conversations. I wired it into Hermes, Claude Code, and Codex. When I checked, it had two conclusions, both from smoke tests, and neither was useful. A second memory store was another thing to maintain, so I retired it.
The replacement is the SQLite file that was already there. Claude Code and Codex are pointed at Mnemosyne over MCP using mnemosyne mcp --transport stdio, so there's no sync job and no second embedding model to keep in step. Each harness starts its own local process, and all of them point at the same database. There's no network service to keep alive.
The model can change without the memory changing. When Hermes falls back from deepseek-v4.1-flash to haiku, the same files and the same database are used to build the next prompt.
The MCP connection gives them the same database, but Hermes's automatic prefetch doesn't come with it. In Claude Code and Codex, recall is a tool call the agent has to make. I added the server to Claude Code; I haven't run a full recall there. Codex is configured the same way, but a headless test run had its tool call refused by its approval policy, so shared access is configured rather than fully exercised. The setup is new, and the current state is provisional.
Getting three harnesses to the same database was the easy part. Deciding who can write what is harder. If two agents can write, who wins when they disagree? If one agent stores a secret, does the other one get it? If a memory is wrong, which harness is allowed to delete it? A shared file gets all three agents to the same data, but it doesn't answer who is allowed to write what.
For one person with three agents, a shared file and a rule that I'm the only one who edits the canonical facts is enough. For a team, I'd want per-agent namespaces, a write log, and an approval path. That's more machinery than I need right now, but it's the direction the system would have to go.
What runs while I sleep
Every night, sleep runs across all sessions. A shell script then snapshots the database with sqlite3 .backup, checks PRAGMA integrity_check, gzips the result, and keeps a local copy for a month plus a second copy on a NAS for two months. The first run produced a snapshot just over 10 MB.
The .backup command matters because SQLite can hold committed changes in a WAL file. Copying the main .db while the agent is running can miss the newest writes; the backup command takes a consistent snapshot that includes them. The integrity check runs before the copy is kept, so a truncated file doesn't get compressed and filed away as if it were good.
It's a shell script, not an agent job, so it uses zero LLM tokens. That's deliberate. A backup is a deterministic operation, and putting a model in the loop would add cost, latency, and a new way to fail. The vault gets a separate git commit every 15 minutes, which is also scripted.
I haven't restored from the backup yet, so I don't know how long recovery takes. The next time I touch the script I want to restore into a scratch directory and time it. Until then, I know the file exists and passes an integrity check.
What it costs before I type
I expected the memory files to be the expensive part. They're the smallest of the three fixed memory pieces. The 42 Mnemosyne tool definitions are the biggest fixed cost. Their names, descriptions, and argument formats tell the model what it can call, even on a turn when it calls nothing, and they take up about 7,500 tokens of the window by a rough characters-divided-by-four count.
That's more than the skills index and the three memory files combined. Most of those tools are administrative: sync, import, export, diagnose, persona, scratchpad, media. I use maybe six of them in a normal week. The chart only covers the fixed memory pieces I measured; base instructions, built-in tools, and the conversation fill the rest of the window.
The flat plan changes the accounting a little. I'm not watching a per-token invoice the way I would on a metered API, but the context is still the constraint: a larger fixed prompt means less room for the conversation, more tokens to process, and more latency.
Prompt caching is the other side of the ledger. The stable prefix, SOUL.md and the fixed guidance, can be reused across requests. The tail, the retrieved memories and the timestamp, gets rebuilt. That's why the order is stable first and volatile last. If I put the memory block at the top, every turn would look like a new prefix and the cache would do nothing.
How it fails
The failure modes decide whether the system is useful.
The first is stale facts. A stale fact looks like this: MEMORY.md says Hermes runs on one model, the canonical slot says another, and the old value keeps getting retrieved because nobody updated it. Memory doesn't expire just because it's wrong. Something has to mark it invalid.
The second is contradiction. One file says the vault is in one place, a Mnemosyne memory says it's somewhere else, and both get pasted into the same prompt. The model has to choose, and it may choose the wrong one. Canonical slots help, but only if every writer goes through them.
The third is a retrieval miss. The query is an exact error code, the embedding doesn't see the match, and the note that would solve the problem never makes it into the window. Hybrid search helps because BM25 can catch the words, but it isn't a guarantee.
The fourth is over-retrieval. Five memories come back, two are irrelevant, and the model follows the wrong one because it was in the prompt. More memories can make an answer worse. The top-five limit keeps the prompt focused, and saving tokens is a side effect.
The fifth is poisoning. A wrong fact gets written once, retrieved forever, and gradually becomes part of the system's story about itself. The fix is the unglamorous part: validate memories, invalidate the bad ones, and delete the ones that shouldn't exist. If you can't inspect and delete a memory, you don't control it.
The sixth is privacy. A memory store is a log of everything the agent has seen, and logs accumulate secrets. The database stays local, but any memory that gets retrieved is sent to the model provider as part of the prompt. Local storage doesn't mean local inference. The rule is no API keys in prompts, and I don't publish the transcripts. That's a policy, not a technical guarantee, which is why it has to be checked.
The seventh is growth. At 28 MB the database is easy to copy and query. At 28 GB the backup time and the query plans would both be different problems. Working memory expires after seven days for a reason. A memory system that only adds eventually becomes too big to search well.
Most of these are things the harness has to enforce. The model can't tell you that a fact is stale, that two memories contradict each other, or that a memory contains a secret.
What I'd change next
The obvious change is the tool list. Mnemosyne's plugin has a tools allowlist. I can expose the six tools I actually use and leave the rest out. That's a config change rather than a code change, and it cuts the biggest fixed cost in the prompt.
The second change is an evaluation. I have hit-rate diagnostics but no way to tell whether the right fact lands in the top five. I want 30 question-and-fact pairs from real sessions, a nightly check of whether the right fact shows up, and an alert when the rate drops. Without that, every memory tweak is a guess.
The third is cleanup. MEMORY.md and USER.md are pressed against their caps, and some of what's in them probably also lives in Mnemosyne as canonical facts. I need to decide which layer owns each fact and delete the duplicate. The rule I'm working toward: if it applies to every session, it goes in the files. If it applies to one project, it goes in the vault. If it's a detail from a conversation, it stays in Mnemosyne.
The fourth is a restore drill. I want to restore the nightly backup into a scratch directory, run a few queries, and time it. I'll know the backup works when a restore finishes and the queries return the right rows.
I'll start with the tool list, then run the eval, then raise the compression threshold once I have the model's real context length.