Agent Memory in Practice: What Building CaBrain Taught Me About Long-Term Recall
- Published on
- Reading time
- 12 min read
AI agents become far more useful when they can remember across sessions — but storing every message in a vector database is not memory. Building CaBrain pushed me toward hybrid retrieval, salience, hot/cold memory, reconsolidation and an entity graph exposed over MCP. #AIAgents #AgentMemory #CaBrain #MCP #RAG #AIEngineering
Agent Memory in Practice: What Building CaBrain Taught Me About Long-Term Recall
An AI agent can have excellent tools, a strong model and a carefully designed prompt — then start the next session as if none of yesterday happened.
That limitation changes what an agent can realistically own.
A useful long-running agent needs more than conversation history. It needs a way to retain what matters, retrieve it when relevant, connect related entities and update old knowledge when reality changes.
That is the problem I have been working on with CaBrain, the memory layer I built for AI agents.
CaBrain is not an attempt to make a model “remember everything.” The architecture goes in the opposite direction: retain selectively, retrieve through more than one signal, preserve relationships and let memory change over time.
Building it changed how I think about agent memory.
Conversation history is context, not long-term memory
The simplest form of agent memory is to keep sending previous messages back to the model.
That works for a while.
Then the context grows, irrelevant details compete with useful facts, cost and latency increase, and eventually older information has to be removed or summarized.
Conversation history answers:
What happened recently in this thread?
Long-term memory needs to answer different questions:
- What did we learn weeks ago that matters now?
- Which fact is associated with this company, project or person?
- Has an older fact been replaced by a newer one?
- Which memories are important enough to retain?
- How are two apparently separate facts connected?
That requires a memory system outside the prompt.
A vector database alone is not memory
A common first implementation is:
Message → embedding → vector database → similarity search
This is useful, but I do not consider it a complete memory architecture.
Semantic similarity is only one retrieval signal.
An agent may need an exact identifier, a project name, a technical term or a relationship that is not the most semantically similar text to the current query.
That pushed CaBrain toward hybrid retrieval rather than vector-only recall.
Hybrid recall: semantic and lexical signals together
CaBrain combines vector retrieval with lexical/BM25-style retrieval and ranking rather than assuming one search method will win every time.
Semantic search is strong when the wording changes but the meaning remains similar.
Lexical search is strong when exact words matter.
For example, a memory query about “the database isolation approach for workspaces” may need to find a note that never uses exactly that sentence. Semantic retrieval helps.
A query containing a specific repository, issue key, company name or technology may benefit from exact lexical matching.
Combining the signals gives the memory layer more ways to find the right evidence.
In CaBrain, the retrieval pipeline also supports reranking so initial candidates can be reordered before they reach the agent.
The important lesson for me was simple:
Memory retrieval should optimize for usefulness, not allegiance to one retrieval technique.
Retrieval quality matters more than memory volume
It is tempting to treat memory as a storage problem: retain more and the agent becomes smarter.
In practice, retaining everything can make recall worse.
A useful memory system has two different responsibilities:
- Decide what deserves to be retained.
- Retrieve the right subset later.
If every transient observation, duplicate statement and low-value message becomes permanent memory, the retrieval layer has to fight through noise forever.
So memory architecture also needs salience.
Salience: not every observation deserves the same future
Some information is structurally important:
- A durable user preference.
- A technical architecture decision.
- A company relationship.
- A project constraint.
- A decision and its reason.
- A fact that will affect future actions.
Other information may be useful only briefly.
CaBrain's design treats retention as something that can be selective rather than assuming every input should become permanent knowledge.
This is one reason I think “store the whole chat” is the wrong mental model for agent memory.
The memory layer should act more like an organ that consolidates useful experience than an append-only transcript archive.
Hot and cold memory solve different jobs
Another useful distinction is between information that needs to remain immediately accessible and information that can live deeper in long-term storage.
I think about this as hot and cold memory.
Hot memory contains information likely to matter in the active operating horizon.
Cold memory can retain older context without forcing it into every interaction.
The exact lifecycle depends on the agent, but the architectural point is broader: memory does not need one retention tier.
A sales-research agent, coding agent and personal assistant can have very different definitions of what should stay hot.
Memory policy should follow the job the agent is doing.
Reconsolidation: memory should be editable
Real knowledge changes.
A company changes leadership. A project moves infrastructure. A preference changes. A technical decision is reversed. An opportunity moves from discovered to contacted.
If memory is append-only, the agent can retrieve multiple contradictory facts with no understanding of which one is current.
That is why CaBrain includes the idea of reconsolidation: retained knowledge can be updated as new information arrives.
The goal is not to rewrite history invisibly. The system should preserve enough structure to understand what changed while making the current state usable.
This becomes especially important for agents operating over months rather than minutes.
Temporal memory changes the question
Once memory can evolve, the useful question is no longer only:
What do I know about Company X?
It can become:
What changed about Company X, and in what order?
That distinction matters in systems such as opportunity intelligence.
A funding event, a new technical leader, a hiring pattern and a product launch may be weak signals individually. Ordered over time, they can explain why a company may need something now.
Long-term agent memory becomes much more useful when it can support state plus change, not only similarity search over old text.
Entities are more durable than chunks
RAG systems often think in chunks because chunks are convenient retrieval units.
Agents frequently need to think in entities:
- Person.
- Company.
- Repository.
- Technology.
- Product.
- Issue.
- Event.
A paragraph can mention several of these at once.
If the memory layer stores only independent text fragments, relationships have to be rediscovered repeatedly by the model.
CaBrain therefore includes an entity graph alongside recall.
The graph lets the system represent and traverse relationships rather than relying only on semantic proximity.
For example:
Company → uses → Technology
Company → published → Job
Person → leads → Company
Repository → depends on → Package
Those edges can become useful context for an agent without asking the model to reconstruct the world from disconnected chunks every time.
Vector search and graphs answer different questions
I do not see graph memory as a replacement for vector retrieval.
They solve different retrieval problems.
Vector/lexical recall asks:
Which retained memories are relevant to this request?
Graph traversal asks:
What is connected to this entity, and through which relationships?
A capable agent may need both.
This is a recurring pattern in CaBrain: avoid forcing one storage or retrieval abstraction to solve every problem.
Memory should have explicit operations
If memory is an agent capability, I want the agent to interact with it deliberately rather than treating it as invisible prompt magic.
CaBrain exposes memory operations over MCP, including capabilities for recall, retention, retrieval, editing and forgetting, plus graph traversal operations.
Conceptually, that gives an agent tools such as:
- Recall relevant knowledge.
- Retain a durable fact.
- Inspect a known memory.
- Correct or update retained information.
- Forget information that should no longer be retained.
- Traverse relationships around an entity.
This makes memory part of the agent's tool architecture.
The model can reason about when it needs memory instead of receiving an uncontrolled dump on every turn.
MCP makes the memory layer reusable
One reason I exposed CaBrain through MCP is that I did not want long-term memory tied to one agent implementation.
A coding agent, research agent or another MCP-capable client can reach the same memory service through a common tool boundary.
That separation matters architecturally:
Agent/Model → MCP → CaBrain → Retrieval + Memory + Entity Graph
The agent can change without rebuilding the memory layer.
The model provider can change without moving the retained knowledge into a new proprietary format.
That makes memory infrastructure a reusable service rather than a feature buried inside one chatbot.
PostgreSQL is a useful center of gravity
CaBrain's storage architecture uses PostgreSQL with vector and lexical-search capabilities rather than requiring every memory concern to live in a separate database product.
That gives the system a strong transactional data layer while supporting vector retrieval and BM25-style search around it.
Redis can support faster operational paths where appropriate, while embedding and reranking services can remain separate components.
The lesson is not that every agent-memory system should use exactly this stack.
It is that introducing AI does not automatically require replacing proven data infrastructure.
Use specialized components where they earn their place.
Memory needs namespaces and boundaries
Long-term memory becomes dangerous if every agent can recall everything.
Different agents, products, clients or users need boundaries around what they can retain and retrieve.
A memory system should know which corpus or namespace a memory belongs to and enforce that boundary before the model sees the result.
This is particularly important for multi-tenant systems and agents working across different business contexts.
Prompt instructions are not an isolation mechanism.
Memory access control belongs in the application and data layer.
Remembering is only half the problem
An agent can retrieve a relevant memory and still misuse it.
The model needs to distinguish between:
- Current operational truth.
- Historical memory.
- User preference.
- Inference.
- External evidence.
If an order status lives in a live database, memory should not override the database.
If a company changed its pricing yesterday, an old retained note should not become the source of truth.
Memory is context. It is not automatically authority.
That distinction prevents a long-term memory system from becoming a sophisticated source of stale facts.
Memory should support provenance
When an agent recalls something important, it is useful to know where it came from and when it was captured.
For evidence-heavy agents, provenance becomes part of trust.
A remembered statement can be much more useful when the system can associate it with source, capture time, entity and later updates.
This is especially important in research, opportunity intelligence and systems that make decisions from changing external information.
Do not inject every memory into every prompt
One of the easiest ways to make long-term memory expensive is to retrieve too much and insert it all into the model context.
Recall should be selective.
The memory layer can retrieve candidates, rank them and return only what the current task needs.
For some requests, graph neighbors may be more useful than text memories. For others, a small set of highly relevant retained facts is enough.
The objective is not maximum recall volume.
It is minimum sufficient context.
Memory changes agent evaluation
Once an agent has long-term memory, evaluating one isolated prompt is no longer enough.
You also need to ask:
- Did it retain something it should not have?
- Did it fail to retain something important?
- Did it recall the correct memory later?
- Did stale memory override current truth?
- Did a memory update replace or reconcile an older fact correctly?
- Did retrieval cross a namespace boundary?
- Did the entity graph create a useful or incorrect relationship?
Memory creates a new class of failure modes.
That means it needs its own evaluation strategy.
A practical memory architecture
A simplified architecture I find useful is:
Observation → Retention decision → Structured metadata/entity extraction → Memory storage
Then later:
Task → Recall query → Hybrid retrieval → Reranking → Graph context where useful → Selected memories → Agent reasoning
And when reality changes:
New evidence → Existing memory/entity → Reconsolidation/update → Current state + history
The details can vary, but separating these stages makes the system easier to reason about.
What I would not do again
I would not begin an agent-memory project by asking only which vector database to use.
That question arrives too early.
I would first define:
- What deserves to be remembered?
- For how long?
- Who is allowed to recall it?
- Which source is authoritative when memory conflicts with live data?
- How will exact and semantic retrieval work together?
- Do relationships between entities matter?
- How will old knowledge be updated?
- How will the agent deliberately retain, recall and forget?
- How will memory quality be evaluated?
- How portable should the memory layer be across agents and models?
Only then would I choose the storage and retrieval components.
The bigger lesson from CaBrain
Building CaBrain pushed me away from thinking about memory as “RAG over chat history.”
For long-running agents, memory is its own subsystem.
It has a lifecycle.
It has retrieval policy.
It has access boundaries.
It has relationships.
It changes over time.
And it should remain separate enough from the model that the agent can evolve without losing its accumulated knowledge.
That is why I describe CaBrain as a memory organ for AI agents rather than simply another vector store.
The interesting part is not remembering more.
It is remembering the right things, connecting them correctly and recalling them at the moment they become useful.
Building an AI agent that needs durable memory across sessions, tools or workflows?
I design agent systems around controlled tool access, long-term memory, retrieval, entity relationships and production boundaries — including architectures that expose those capabilities over MCP.
Related: AI Agents, RAG vs Fine-Tuning vs AI Agents, Private AI, AI Automation and CaBrain.
Comments (0)