An agent that forgets everything between sessions is not an agent. It is a stateless completion endpoint with amnesia, and if you have used one on a real project you know the specific flavour of that: it re-asks questions you already answered, re-discovers things you told it in March, and makes the same mistake twice, apologising each time.

The fix is not obvious, and the two easy answers are both bad.

The first is one big memory file you keep appending to. It works for about a week, then it is forty thousand characters of stale notes, half of it contradicted by later entries, and it blows past your context window on every request.

The second is a vector database, which gets you good retrieval and poor maintenance. Nobody can read it, hand-edit it, or diff it in git, and it does not tell you where a fact came from.

There is a third option, and it is the one I have been running for a while: boring, plain files, and it works.

One index file. One pointer per topic. Everything else lives in a file. The index is a table of contents, not a journal.

The idea: separate the index from the content

Everything else follows from that one decision.

IndexLibrary
LoadedEvery turnOn demand
SizeA couple thousand charactersUnlimited
StructureFlat pointer listChapters, files, directories
PurposeAnswers "where is it?"Answers "what is it?"

Collapse those two together and you get either a bloated index or a library you have to search every time.

ALWAYS LOADED the pointer file a table of contents a couple dozen short entries no prose, no detail a cap it cannot exceed or it stops being written THE TREE chapters of plain files almost none of it loaded operating/ rules, identity projects/ one dir each log/ one file per day events/ dated, slugged people/ one file each state/ where things stand archive/ never deleted scripts/ keeps it honest pointer the index holds the map. the library holds the answer. only the map is paid for on every turn.
The always-loaded file is a table of contents. Each pointer opens into one branch of the library.

This is what the index actually looks like. A real one, shortened:


Operating discipline - read before acting -> library/operating/RULES.md
Who the agent is, what it values -> library/operating/SELF.md
Machine-specific facts, paths, quirks -> library/operating/ENVIRONMENT.md
The full project map -> library/operating/PROJECTS_INDEX.md
Active task, open loops, priorities -> library/state/CURRENT_STATE.md
Daily logs, append-only, one per day -> library/log/INDEX.md
Significant incidents, dated and slugged -> library/events/INDEX.md

Seven lines. That is the entire always-loaded surface. Follow any one of those pointers and you land on a page that tells you everything about that subject.

Now look at what is not in there. There is no explanation of the operating rules, no summary of the environment, no version of the story. If you wanted the story, you follow the pointer, and the map stays a map.

The one-line test for membership is blunt, and it is the rule that makes the whole thing work:

If it needs more than one line here, it belongs in a file.

A pointer that summarises its target is a paraphrase, and paraphrases drift. Two copies of a rule means one is going to be wrong, and the wrong one is the one in the always-loaded block.

The second store: the journal

The index answers "where is it?" The journal answers "what happened."

One file per day, appended as the day unfolds and never reconstructed the next morning. It is never loaded automatically; you read it when you need the texture of something, not the fact of it.

THE INDEX always loaded, has a hard cap pointer pointer pointer pointer the cap anything past the cap is trimmed and nobody is told what was dropped so the file must stay pointer-only THE JOURNAL one file per day, append-only, no cap appended as it happens, never rewritten the index says where to look. the journal holds what happened. the journal is what lets the pointer file stay small. trim the pointer file and you lose the map. trim the journal and you lose the record.
Two stores with very different rules. The capped one is trimmed when it fills. The journal has no cap and is only read on demand.

Append-only here is a feature, not laziness. A daily log that gets edited after the fact becomes a summary, and summaries lose the details that make them useful three months later. The constraint preserves the texture for free.

The format is deliberately loose. A timestamp and a short note is enough. It costs almost nothing to write, so you actually write it.

These two stores solve each other's problem, and that is the whole architecture.

The journal is what lets the index stay small, because the journal is where the detail actually goes. At the end of a session the useful parts get promoted into topic files, and the index gets one new line saying where that topic lives now. The day's log stays where it is, untouched.

And the journal saves you when the index gets trimmed. Trimming only costs you the map. The record is still in the journal. You can rebuild the map.

Without the journal, one file is doing two incompatible jobs. It has to hold the summary of what you know and the evidence for what happened. The summary is small and wants to be in context every turn. The evidence is large and wants to sit still. They fight, the small one wins, and the large one gets dropped.

Chapters, because flat directories do not scale

The library is not one big folder. It is chapters, each with its own small index.

The reason is simple. A flat directory of five thousand files is unsearchable by an agent that does not want to list the whole thing. A chapter index is a table listing each file with a one-line description, small enough to read completely. The agent scans it, picks the right file, and opens one thing instead of two hundred.

That is the same principle as the index itself, applied one level down. A map that points at content, at every scale.

I settled on eight chapters. Operating rules, identity, environment and the project map, read on every cold start. People, one file each. Projects, one directory each. Daily logs. Significant events, dated and slugged. Current state, a snapshot rather than a record, and the only chapter that gets rewritten. An archive for superseded versions. And the maintenance scripts that keep the rest of it honest.

Two of those deserve a note.

The daily log and the event file do different jobs. A day produces log entries. Some days produce events, the ones worth finding later by name, and the rule for promoting one is simple: if you would want to find it in six months, it is an event.

The archive is the one people skip, and it matters more than it looks. A memory file records what was believed at a time. When a fact changes, the interesting question is not just what is true now, but what we believed before, and why we changed. An agent that can answer that can reason about why a decision was made. Deleting the old version destroys that, and destroys your ability to recover when a change turns out to be wrong.

The three rules

The structure is detail. These three are what make it work.

The index is a pointer index, not a journal. Prevents drift and bloat, and it forces "where do I put this?" to have a real answer.

Read before write, every time. You do not know what is in a file you have not read, and it may have changed since you last looked. Agents break this one most, because the file looks familiar. Familiarity is not reading.

Archive, never delete. When a file changes materially, copy the old version into the archive first. Memory that is wrong is still memory. It records what you believed and when.

What the cap is actually buying you

The cap turned out to be the friend here.

The index is in every prompt. Every character in it is paid for on every request, forever. A two thousand character index is about five hundred tokens, cheap enough to keep always-on and small enough that it does not crowd out the conversation. The library is free. Reading a forty thousand character file costs ten thousand tokens, but only when you open it.

That asymmetry is the whole design. It means memory can grow without cost until someone actually needs to recall it.

And the same characters are competing with your actual question for the model's attention. There is no error here and nothing to fix. The model just attends a little less to everything, including the thing you asked.

I am not going to tell you that a smaller always-loaded file makes your agent smarter. Whether it does is a separate question, and I do not think anyone has answered it cleanly. Organising your memory buys you cheaper recall and fewer silent losses.

What you are buying is a system that does not quietly lose what you told it, and that stops charging you for the same paragraph on every request for the life of the project.

The recall path, and why order matters

A QUESTION what do I know about this free one hop THE INDEX names the chapter it lives in free one hop CHAPTER INDEX names the file inside one read one hop THE FILE holds the detail one read the top two are already loaded. they cost nothing extra to read. the detail is only paid for when it is actually needed. every character in the always-loaded file is paid for on every turn.
How a question walks down to the file that holds the answer. The first two levels are already loaded.

Order matters. Starting with a full-text search across the whole library returns two hundred hits and teaches you nothing. Start narrow and widen. Index first, because it is small and already loaded. Then the chapter index, because it tells you which file. Then the file. Only after that, transcripts and any structured facts.

The first two steps cost you nothing extra, because they are already in context. You pay for the detail only when you actually need it.

Why this is easier to do locally than it used to be

There is a version of this article I could not have written a few years ago, because the useful part of the stack was not yours to touch.

If you run an agent on your own machine, the memory file is a file. You can open it, diff it, grep it, and put it in git to watch what your agent learned change over a week. When something looks wrong, you can go and look for it.

That is a bigger deal than it sounds. Most of the time you find out an agent lost something is by noticing the absence weeks later. With a plain file on your disk, you can go and look for it.

And the append-only journal fits that model exactly. A text file. Writes to it are cheap, version-controllable, and readable by anything that can read a file.

None of this is exotic. A few directories and a set of rules. But the rules are the whole trick, and now that the model runs on your hardware, the rules are yours to write.

Give it to your agent

I have put this together as a working library, with the scripts that make the write path easy and a health check that catches rot before you notice it. Open source, all plain Markdown, nothing to install.

github.com/DuNorth595/ai_agent_memory

If you would rather build it from scratch, this is the prompt I would hand an agent. It asks the agent to propose the structure first and get it approved, because the layout and the rules are the parts you will actually live with.


I want to build long-term memory for an AI agent that survives across
sessions.

I want it to work like this:

1. There is ONE small file that gets loaded into context on every single
   turn. This file is an index. It holds short one-line entries that
   point at where the detail actually lives. It contains no prose and no
   detail of its own. If something needs more than one line there, it
   belongs in a file and the index gets a pointer to it.

2. There is a separate append-only journal. One file per day, written
   as the day unfolds, never rewritten. It records what actually
   occurred. It is never injected into context on every turn, it is read
   on demand.

3. There is a library of chapters, each with its own small index file,
   holding the real detail: operating rules and identity, one file per
   person, one directory per project, daily logs, significant events,
   current state, and an archive of superseded versions.

Help me set this up. Specifically:

- Propose the chapter layout and the file naming scheme.
- Write the bootstrap file that sets up the index and the directory
  structure, including a starter chapter index and a rules file.
- Write the rules the agent follows about when to add a pointer, when
  to skip it, when to supersede an existing pointer, and when to
  archive.
- Give me the exact text of the index file's header, so it explains
  itself to the agent every time it reads it.
- Set up the daily journal so it is created automatically at the start
  of a day and appended to as the session proceeds.
- Write a small health check that verifies every pointer in the index
  and the chapter indices resolves to a file that exists.

Rules I want you to follow:

- The index must stay small. If you approach its limit, do not add more
  to it. Move the content into a file and leave a pointer.
- Never put detail in the index. A pointer plus enough context to decide
  whether to follow it, and nothing more.
- The daily journal is append-only. Do not rewrite or summarise what is
  already in it. If you need a summary, write it to a new file.
- When a pointer contradicts an existing one, supersede it rather than
  deleting the old one. Give the old entry an end date.
- Archive before you overwrite. Never delete a memory file.
- Read a file before you write it, every time.

Before you write anything, show me the proposed layout and the rules
file so I can approve them. Then build it.

Two things I would change if I were handing it to someone else.

The first is the approval gate at the end. I would not let an agent build the layout and the rules in one shot without looking at the rules first, because the rules are the part that has to survive contact with a real project. Everything else is recoverable.

The second is that I would add, after running it for a while: write down the index size and check it periodically. Not because it should be growing, but because when it does grow, you want to know which topic caused it. That is usually a sign that a topic needs its own chapter, and that the pointer is doing work a folder should be doing.

The part I would want you to take away

The always-loaded file is a map. The detail lives in chapters of topic files and in an append-only daily journal that is never injected automatically. The map stays small enough that the cap never bites, the journal holds the record, and the two of them together survive far longer than either would alone.

If you only take one thing from this, make it that. It costs nothing to build, the cap comes with the platform either way, and once the map is right the rest of your memory system gets a lot easier to reason about.