"Give the agent memory" is a request every framework answers, and the answer is usually a vector store plus a summary. After watching a few of these work and a few of them not, here are the three patterns I come back to, and the one that reliably wastes money.
The three that work
A file the agent writes. Not a database, not embeddings: a plain Markdown file in the project directory, with the facts the agent has established. "The auth middleware lives in src/middleware.ts and it reads the session cookie, not a header." That is the whole memory.
It works because it is cheap, it is diffable, it survives the session, and the agent can read it with the same tool it reads any other file. A grep over a Markdown file is exact; a search over embeddings is approximate. For facts of the form "where is X", a file wins.
A structured summary the agent maintains. The agent keeps a short document of the current state of the task: what has been tried, what the plan is, what is known. It is rewritten rather than appended, so it does not grow without bound.
This is what the compaction command in the coding agents does, and it is the single most effective memory feature, because it changes the size of every subsequent request rather than one of them.
Retrieval over a corpus you control. For facts that are genuinely many and genuinely fuzzy — "how did we handle rate limiting in the payments service" — embeddings are the right tool. The condition is that the corpus is worth indexing and that you can measure recall on it.
The one that does not
Appending everything to a conversation log and re-sending it. The transcript grows, the cost per request grows with it, and the signal-to-noise ratio falls, so the model is reading more noise on every turn.
The failure is not the cost. It is that the model's attention over a long conversation is not uniform, and the early turns of a long session are the ones it follows least. A memory that appends is a memory that stops working exactly when the session is long enough to need it.
The rule
Match the memory to the question. "Where is X" gets a file. "What is the state of this task" gets a maintained summary. "What did we do about Y" gets retrieval. The thing that does not work is one mechanism for all three.