Field note
Your AI Agent Doesn't Need One Giant Memory
Let’s talk honestly about one of the easiest ways to make an AI agent confusing, expensive, and slightly dangerous: putting every piece of information into one giant memory bucket.
Imagine asking your agent to remember a formatting preference. A week later, it retrieves an old brainstorming thought, a half-finished conversation, and three contradictory versions of the same fact.
It remembered everything. It understood almost nothing.
So, do agents need more memory? Or do they need better boundaries?
0. Memory Is Not One Thing
When we say “memory”, we often mean several different systems at once:
- A preference that should be available every time.
- A durable fact that should be searchable later.
- A full document that needs its original wording and citations.
- A conversation that explains how a decision happened.
Those things have different sizes, lifetimes, privacy risks, and retrieval patterns. Treating them as the same thing is like storing a sticky note, a database row, a book, and a security camera recording in one folder and calling it a filing system.
A more useful design looks like this:
+--------------------------------------------------+
| Agent request / current task |
+--------------------------+-----------------------+
|
selective retrieval
|
+------------------+------------------+
| | |
Built-in memory Semantic memory Knowledge vault
small + stable searchable facts full source material
| | |
+------------------+------------------+
|
Conversation history
audit trail / context
The important word is selective. The agent should not load all four layers for every question.
1. Layer One: Small Built-in Memory
The first layer is intentionally boring. That is a feature.
It contains stable facts and preferences that are useful almost everywhere:
- preferred response language
- coding or formatting preferences
- a public username
- a recurring constraint, such as “never merge pull requests automatically”
This memory should stay small enough to inspect by hand. If it becomes a novel, it is no longer built-in memory. It is a badly indexed knowledge base.
A simple representation might look like this:
preferences:
language: en
code_style: "show runnable examples"
workflow:
pull_requests: "open for review; do not merge"
Why keep this layer small? Because it is injected frequently. Every extra line increases prompt size, noise, and the chance that an old detail gets mistaken for a current instruction.
A good rule is:
If the agent needs it on almost every task, and a human can verify it in a few seconds, it may belong here.
2. Layer Two: Searchable Long-Term Semantic Memory
The second layer is where durable details live. It is searchable instead of automatically present.
This is a good place for structured facts such as:
- a project convention that is still relevant
- a decision and the reason behind it
- a known dependency relationship
- a user preference that matters in a specific domain
- a lesson learned from a previous failure
A system such as Mnemosyne can be used as a generic example of this layer: not as a magical brain, but as a store that indexes durable memories and retrieves only the relevant ones.
The key is that a memory record needs more than just text. It needs a lifecycle.
{
"fact": "The service uses table-driven tests for validation logic.",
"scope": "project-a",
"source": "engineering decision",
"status": "active",
"validated_at": "2026-08-01",
"supersedes": null
}
The exact schema can differ, but the ideas matter:
- Scope: Where is this fact valid? A personal preference is not automatically a team rule.
- Source: Why do we believe it?
- Status: Is it active, stale, disputed, or deleted?
- Validation: When was it last checked?
- Supersession: Which newer fact replaces it?
Without these fields, semantic memory quietly turns into a pile of confident-sounding sentences.
2.1 Memory Has a Lifecycle
A useful fact does not live forever just because it was once true.
proposed -> validated -> active -> stale
| |
+------> superseded
|
archived
For example, a note saying “the API returns XML” may be correct today and wrong after a migration. The system should be able to mark the old fact as superseded instead of retrieving both versions and hoping the model picks the right one.
This also makes debugging possible. When an agent gives a strange answer, we can ask:
- What memory did it retrieve?
- Why did that record match?
- What scope and status did it have?
- Was a newer record available?
That is much better than staring at a huge prompt and asking, “Which sentence confused it?”
3. Layer Three: The Knowledge Vault
A knowledge vault is for full documents and source material:
- design documents
- manuals
- research papers
- meeting notes
- source code or specifications
- original examples that must be quoted accurately
This is knowledge, not prompt memory.
The distinction is simple:
| Memory | Knowledge |
|---|---|
| A compact fact or preference | The complete source document |
| Optimized for quick retrieval | Optimized for fidelity and context |
| Can be updated or superseded | Preserves original material and provenance |
| Usually safe to summarize | Often needs citations or exact wording |
Suppose the vault contains a 40-page architecture document. The agent should not paste the whole document into every request. It should retrieve the relevant section, use it for the current task, and keep the source available when verification is needed.
A memory might say:
The authentication decision requires short-lived access tokens.
The vault should contain the decision record explaining why, including alternatives, trade-offs, and the date. One is a useful index card. The other is the evidence.
4. Layer Four: Conversation History
Conversation history is valuable, but it is not automatically permanent truth.
It tells us:
- what was asked
- what the agent answered
- which assumptions were made
- how a decision changed over time
- where an error entered the process
That makes it an audit trail.
But a conversation also contains jokes, guesses, temporary instructions, typos, and statements made before someone had all the facts. Saving every sentence as a durable memory would be a terrible default.
A safer flow is:
conversation -> candidate fact -> validation -> semantic memory
| |
+---------------- audit trail ----------------+
A message can be evidence for a memory without becoming the memory itself. This small distinction prevents a casual sentence from turning into a long-lived rule.
5. Compaction Is Not Memory
There is one more concept that often gets mixed into this architecture: compaction.
Compaction is not a fifth memory layer. It is a lossy context-window management technique. When a conversation gets too large for the model’s context window, we can replace some of the visible messages with a shorter summary so the current task can continue.
That summary is useful, but it is not the source of truth. The original conversation history remains the canonical audit trail. A compaction summary is a temporary context representation: a convenient reconstruction of what seems relevant right now, not an authoritative record of everything that happened.
original conversation / history
(canonical audit trail)
|
lossy compaction
v
temporary context summary
(for the current window)
The word lossy matters. A summary can omit a qualification, flatten a disagreement, or accidentally make a guess sound like a decision. If the detail matters, go back to the original history or a validated source document. Do not promote the summary into semantic memory just because it sounds confident.
So the architecture has four information layers or roles:
- built-in memory for small, stable preferences
- semantic memory for validated, searchable facts
- a knowledge vault for complete source material
- conversation history for the audit trail
Compaction sits beside those layers as context management. It changes what is loaded into the current prompt; it does not create a new kind of durable information.
6. Selective Retrieval Beats Prompt Stuffing
The tempting implementation is straightforward:
prompt = system_rules + all_memories + all_documents + full_history + question
It also becomes slow, costly, and hard to reason about.
A layered implementation asks what the current task actually needs:
context = []
context += load_builtin_memory()
context += semantic_search(query, scope=current_scope, limit=5)
context += vault_search(query, limit=2) if needs_source_material else []
context += recent_history(limit=10) if continuity_matters else []
answer = agent(question, context=context)
This is not a complete retrieval system, but it captures the important design choice: each layer has its own gate.
| Task | Built-in | Semantic | Vault | History |
|---|---|---|---|---|
| Format a short answer | Yes | Maybe | No | No |
| Continue yesterday’s debugging | Yes | Yes | Maybe | Yes |
| Explain a design decision | Yes | Yes | Yes | Maybe |
| Search an original manual | Maybe | Maybe | Yes | No |
Fewer irrelevant tokens usually means lower cost and less opportunity for contradictory context. More context is not automatically more intelligence.
7. Privacy Boundaries Are Part of the Architecture
Layering is also a privacy mechanism.
Not every memory should be visible to every task. A useful record should carry a scope, and retrieval should enforce it before the model sees the content.
def retrieve(query, scope):
records = semantic_search(query)
return [record for record in records
if record.scope in scope and record.status == "active"]
The real implementation needs stronger access control than this example, but the boundary should exist conceptually and technically.
Consider the difference between:
- a public writing preference
- a private personal detail
- a project-specific convention
- a document restricted to one audience
Putting them in one bucket makes accidental disclosure much more likely. Separate layers, scopes, and retrieval policies make the safe path the normal path.
8. Why This Is Easier to Debug and Cheaper
A single memory bucket creates several mysteries:
- Was the wrong fact stored?
- Was the right fact retrieved with the wrong scope?
- Did old history override a newer decision?
- Did a full document consume the context window unnecessarily?
With layers, each question has a smaller search space.
We can inspect:
- the always-loaded memory
- the semantic retrieval results
- the source snippets selected from the vault
- the history window included for continuity
We can also measure each layer separately: hit rate, stale-record rate, token usage, retrieval latency, and rejected scope violations.
That is the practical benefit. A layered architecture is not just cleaner on a diagram. It gives us knobs to tune instead of one giant prompt to fear.
9. The Rule I Keep Coming Back To
An agent should not remember everything. It should remember the right kind of thing in the right place.
- Keep stable, always-needed facts in a small built-in layer.
- Put durable, searchable facts in long-term semantic memory.
- Keep complete source material in a knowledge vault.
- Preserve conversations as an audit trail until a fact is validated.
- Retrieve selectively, with lifecycle and privacy checks.
So the next time someone proposes adding “memory” to an agent, ask a more precise question:
Is this a preference, a fact, a source document, or an audit record?
That question alone prevents a surprising amount of architectural chaos.
And yes, it usually makes the agent cheaper too. Spoiler: the biggest context window is not the same thing as the best memory system.