1 Nov 2026
The agent forgot the project overnight
A new session starts blank. Whatever the agent knew yesterday is gone, unless you put it back in the text.

You can spend an hour with an agent and walk away sure it knows the project. It has the repo layout, it knows you want TypeScript, it knows the staging server falls over every Friday. Next morning, new session, and it asks what framework you use.
Those facts were never stored. The weights are whatever training left behind, and a chat does not rewrite them. Each request only reads the text you attach. Leave yesterday out of that text and the reply has nothing to go on.
Chat apps hide the gap by resending earlier messages. The model sees the transcript, so it sounds continuous. Close the window and that transcript is gone, unless the app saved it and loaded it again.
The window is a budget
Every model has a ceiling on how much text one request can hold. The unit is tokens, roughly three quarters of a word in English. System instructions, the chat so far, file contents, tool output, and the model's own replies all spend that budget.
A coding agent that opens a few large files and runs the tests can spend it in one sitting. Then something gets cut. Some tools drop the oldest messages. Some fold them into a summary. The reason you picked a database three hours ago can sit in the part that was cut, and the agent will suggest the option you already turned down.
A larger window pushes the cutoff further out. You still pay for every token on every request, in the bill and in how long the reply takes. A long pile of text is also harder for the model to use than a short one. Keeping every message, forever, is a poor way to run a project that lasts months.
Where the notes can live
Most agents that last more than a day use two of these, sometimes three.
Recent messages
Store the chat and send the latest stretch with each request. Enough when the task finishes today. The log grows, so you trim it eventually.
A running summary
When the history gets long, ask the model to write down what still matters and replace the old messages with that summary. The session can continue. A sloppy sentence in the summary gets copied forward. "The user wants a REST API" is a different fact from "we might need a REST API later," and the first version will be treated as settled.
Search over old material
Store past notes somewhere you can query. Often that is a vector database: text turned into embeddings, lists of numbers, so a later question can find a note even when the wording changed. The request carries a handful of matches. The database can hold years of them. This is the setup people mean by RAG, retrieval-augmented generation.
It fits documentation, support tickets, a long archive of notes. The setup work is real: how you split documents, which embedding model, how many results to return. A match can look related and still be the wrong note. The model will build on it anyway.
A file of facts
Some memories are just facts. A name, the language you want, the staging URL, the command that runs the tests. A JSON file, a bit of YAML, or a row in an ordinary database is a better home for those than semantic search. Coding tools often load an instruction file from the repo at the start of every session: conventions, build commands, the folders to treat carefully. You can open the file and see what the agent was told.
When a client asks us for an agent that should still know the project next week, this file is where we start. It sits in the repo and gets loaded into the system prompt. Anyone on the team can correct a line. Search over old tickets comes later, once the file is clearly too small for what they need remembered.
Picking one
A task that starts and ends in one sitting can live on the chat history. A memory system is wasted there.
A project that comes back across sessions is mostly covered by the facts file and an instruction file. The first time the agent does something odd, you can read the file instead of guessing what it believed.
A large body of old material, docs or tickets or months of notes, is a retrieval job. Budget time for it. Chunking and result count will need tuning after the first week, not just on day one.
A mix is common. The instruction file holds conventions that rarely change. A few fields hold current state, such as which branch is active. Retrieval covers the long tail.
Enough to ship
Python, no vendor SDK. Facts live in agent_memory.json. At the start of a session they are appended to the system prompt.
import json
from pathlib import Path
MEMORY_FILE = Path("agent_memory.json")
def load_memory() -> dict:
if MEMORY_FILE.exists():
return json.loads(MEMORY_FILE.read_text())
return {}
def save_memory(memory: dict) -> None:
MEMORY_FILE.write_text(json.dumps(memory, indent=2))
def remember(key: str, value: str) -> None:
memory = load_memory()
memory[key] = value
save_memory(memory)
def forget(key: str) -> None:
memory = load_memory()
memory.pop(key, None)
save_memory(memory)
def build_system_prompt(base_prompt: str) -> str:
memory = load_memory()
if not memory:
return base_prompt
facts = "\n".join(f"- {k}: {v}" for k, v in memory.items())
return f"{base_prompt}\n\nKnown facts about this project:\n{facts}"
Call build_system_prompt when a session starts and pass the result as the system message. When something should stick, call remember. When it goes stale, call forget.
Store staging_server once, as "falls over every Friday, restart the worker first." The next session already has it.
What deserves a line in the file
Saving is easy. Choosing is the part that goes wrong.
Save every aside and half the file is wrong within a week. The agent then follows last month's deploy target. Save too little and you repeat the same corrections. Keep a fact when it is stable, specific, and likely to matter in a later session. A coding style usually qualifies. The bug you fixed this morning usually does not, unless it shows a pattern you will hit again.
Facts change. The team left Heroku. A leftover line that says deploy there will send the agent the wrong way. Put an edit and a delete in from the start, and have someone read the file on a schedule. Treat it as configuration.
If anyone can write into memory the agent reads, one bad line can change what it does. Keep write access narrow. A stored fact deserves the same suspicion you would give input that arrived from outside.
Personal data persists, which is the whole point of memory. Decide the categories that must never be stored, and reject them in code. A line in the prompt that says please do not save this will not hold.
Test it on a new session
Memory is easy to fake by accident. If the test conversation still fits in the window, the agent looks like it remembers, and you have only checked the chat history.
Run it. Store a fact. End the session completely. Start another. Ask something that depends on that fact. Try a few facts, then delete one and ask again. The agent should stop using it.
Log the text injected into each request. When an answer is strange, read that log first. These bugs usually sit in what was loaded.
Three facts is a fine first version
If you are adding this in the next few days, write down the three to five things you keep repeating. Put them in a file. Load the file into the system prompt. Watch a couple of sessions before you reach for a vector database.
The Friday server stays remembered only if you write it down and send it again.