Skip to content

Memory Architectures in AI Agents: Building Agents That Remember Across Sessions

In 2026 agent memory is a layer separate from the context window. Short/long-term memory, Letta, Mem0, Cognee and KVKK-compliant production design.

SYK
Şükrü Yusuf KAYA
AI Expert · Enterprise AI Consultant

TL;DR — As of 2026, memory in AI agents is no longer a matter of "a longer context window"; it is a persistent layer designed architecturally, independent of the model's context window. In this article I compare short-term and long-term memory, Letta's operating-system-inspired layered approach, Mem0's two-phase pipeline, Cognee's graph-based persistent memory, and options like Zep and Redis, drawing on observations from the field. I then walk through production decisions on retention, consolidation, cost and evaluation, and most importantly, how to build a memory architecture compliant with Turkey's KVKK and the EU AI Act, step by step.

Why is everyone suddenly talking about "agent memory"?

In nearly every agent project I have run with enterprise clients over the past year, we hit the same wall: the demo works beautifully, then the user comes back the next day and the agent remembers nothing. Not their name, not their preferences, not the task you left half-finished yesterday, not even a correction you made five minutes ago. This is an architectural gap more than a technical flaw. A language model is, by definition, stateless. Every call is a fresh page with no history.

The idea that matured in 2026 is exactly this: memory is a separate component that lives around the model, not inside it. For a long time the assumption was "if we grow the context window, the problem is solved." Context windows did indeed grow. But a longer prompt is not a system that remembers. The context window is a temporary workspace; it evaporates at the end of each session. Memory, on the other hand, is a layer that stores information persistently across sessions, recalls it when needed, resolves contradictions, and learns over time.

Let me make this distinction crisp in one sentence, because most projects stumble right here:

"

The context window is the agent's short-term attention; memory is the experience the agent accumulates over a lifetime. The former is volatile like RAM, the latter persistent like disk.

The real difference between short-term and long-term memory

This distinction, borrowed from human cognition, has highly practical consequences in agent design. Mix the two up and either your cost explodes or your agent turns dumb.

Short-term memory holds the recent interactions within the current execution. It covers the flow of the conversation, the output of the tool just called, what the user said two messages ago. Frameworks like CrewAI typically solve this with ChromaDB and a local embedding model: interactions are vectorized and kept in a temporary store, becoming irrelevant once the session ends. The goal is coherence within a single task.

Long-term memory is persistent knowledge learned from past tasks. The preference the user stated three weeks ago ("I always want invoices as PDF"), the outcome of a support ticket resolved last month, the lessons the agent drew from its own mistakes. CrewAI often uses a persistent store like SQLite for this. Here the goal is cross-session continuity and personalization.

The most common mistake I see in the field is writing everything to long-term memory. The agent saves even a worthless sentence like "the user said hello" to persistent memory, and a few weeks later the memory store bloats with thousands of meaningless records and retrieval quality collapses. Memory is not a trash can; it requires a filter that decides what is worth remembering.

Let us gather memory types in one table

Think of the table below as a simplified version of what I draw on the whiteboard in client workshops. When designing an agent, do not start writing code before clarifying which memory type sits where.

Memory typeScope / durationTypical storeWhat it doesIts risk
Short-term (working)Single session / executionChromaDB + local embedding, context windowConversation coherence, tracking tool outputLost when session ends
Long-term (episodic)Cross-session, event-basedSQLite, vector DB"Last time we did this" type recallBloat, loss of relevance
SemanticPersistent, fact-basedKnowledge graph, vector DBStable facts about the user, preferencesContradiction management is hard
ProceduralPersistent, skill-basedSystem prompt, tool definitions"How to" knowledge, workflowsRequires update discipline
Consolidated summaryCompressed historySummary text + vectorCost reduction, carrying long historyLoss of detail

You do not have to use all five types in a single product. For most enterprise agents, the trio of short-term + semantic (preferences) + episodic (past tasks) is more than enough. Procedural memory is usually handled by the system prompt and the tool catalog anyway.

Letta: memory conceived like an operating system

What appeals to me most about Letta (the approach born from the former MemGPT project) is that it treats memory with an operating-system metaphor. The idea is simple but powerful: on a computer, RAM is limited while disk is vast. The operating system moves the pages needed at the moment into RAM and writes the rest back to disk. Letta does exactly this.

Here the main context is like RAM: the limited, expensive space the model currently sees. External storage is like disk: nearly unlimited but requiring an explicit "paging" operation to access. As the conversation lengthens, the agent manages its own memory; it writes important information to external storage, recalls it when needed, and keeps the main context clean. In other words, the model becomes its own memory manager.

The field advantage of this approach is that it gracefully manages context overflow in long, continuously running relationships (for example, an enterprise assistant working with the same employee for months). Its downside is that the agent spends extra model calls to run its own memory operations, creating a hidden cost line. For small, one-off tasks this overhead is unnecessary.

Mem0: a two-phase pipeline and a hybrid backend

With its work published in April 2026, Mem0 lifts memory out of "write-read" simplicity and turns it into a genuine knowledge-management pipeline. What impressed me most is that it takes contradictions seriously.

Mem0's operating logic is two-phase:

  1. Extraction phase: when an interaction occurs, a language model extracts the information worth remembering from the conversation. It does not store the raw text as is; it produces distilled facts like "the user lives in Istanbul", "prefers morning meetings".
  2. Update phase: the newly extracted information is tested against existing memory. The critical step here is contradiction detection: if the user previously said "I live in Ankara" and now says "I moved to Istanbul", the system does not blindly keep the old record; it detects the contradiction and performs a graph update. The old fact is invalidated, the new one becomes valid.

Mem0 also offers a three-level hierarchy: user level (persistent facts about a person), session level (specific to that conversation), and agent level (what the agent itself has learned). This separation is gold in enterprise scenarios, because it directly answers the KVKK access-scope question I will discuss in the next section.

On the backend Mem0 runs hybrid: vector similarity (for semantic proximity) and a knowledge graph (for relationships between entities) together. The graph side captures the "who is related to whom, which fact invalidates which" questions that pure vector search misses.

Cognee and graph-based cross-linking

Cognee is another framework that again clarifies the distinction. Here session memory is the short one, covering the current conversation; persistent memory represents the long-term and is held cross-linked in a graph. The value of the graph is this: you store not singular facts but the relationships between facts. A web of knowledge like "Ahmet owns project X; project X belongs to department Y; department Y processes data sensitive under KVKK" gets lost in a flat vector store but stays alive in a graph and opens itself up to reasoning.

Zep, Redis and the rest of the ecosystem

The whole field is not limited to these three names. Zep is practical especially in chat-heavy products, automatically summarizing conversation history and turning it into a timestamped memory store. Redis-based solutions are preferred by teams wanting low-latency, high-volume long-term memory; Redis's speed advantage relieves the retrieval bottleneck in real-time agents.

My advice to clients is usually this: do not marry the framework. Design an interface that abstracts the memory layer away from the underlying store. Mem0 today, Redis tomorrow, your own solution the day after; your business logic should not be affected.

When to choose which? A decision guide from the field

Let us set theory aside and get practical. This is the question I am asked most, so let me be clear:

  • One-off, short tasks (summarize a document, fill a form): do not touch long-term memory at all. Short-term context is enough. Adding memory here is just complexity and cost.
  • Personalized, ongoing assistants (with the same user for months): semantic memory (preferences) + episodic memory (history) are essential. Mem0's user-level scope fits well here.
  • Relationship-heavy, enterprise knowledge (departments, projects, links between people): a graph-based approach (Cognee style) reasons far better than flat vectors.
  • High volume, low latency (live customer service): Redis-based long-term memory saves latency.
  • Long, uninterrupted sessions (context-overflow risk): Letta's OS-inspired paging is an elegant solution.

Retention and consolidation in production: memory consolidation

Running an agent in a demo and keeping it up in production for months are two very different jobs. In production, the most critical problem with memory is growth. If every interaction produces a new record, a few months later you will have a memory pile that is slow to retrieve, low in relevance and high in cost.

The solution resembles what the human brain does during sleep: memory consolidation, periodically distilling raw, scattered short-term records into summarized, persistent facts. In practice I apply it like this:

  1. Raw capture: interactions first enter the short-term store in raw form.
  2. Periodic distillation: at certain intervals (end of session or a nightly job) a model reads the raw records and reduces them to persistent facts. "A 20-message conversation" -> "the user prefers X, complains about Y".
  3. Contradiction resolution: as Mem0 does, if the newly distilled information contradicts the old, the old is invalidated.
  4. Archiving/deletion: after being distilled and after legal retention periods are observed, raw records are archived or deleted.

This cycle improves both cost and retrieval quality at the same time. With one client, when we moved raw records to weekly consolidation, the memory store size dropped to a third and the agent's answer quality visibly improved; because finding the right fact amid the noise had become easier.

Cost: the invisible bill of memory

Memory is not free. It creates three separate cost lines, and most teams forget to include them in planning:

  • Storage cost: vectors and graph nodes take up space. At millions of users this reaches a serious figure.
  • Embedding cost: vectorizing every new piece of information is a model call. You can cut this significantly with a local embedding model; CrewAI's local-embedding preference makes sense precisely for this reason.
  • Extraction and consolidation cost: Mem0-style extraction and Letta-style self-management spend extra model calls. This hidden line can become a significant slice of the bill as volume grows.

My advice: monitor memory like a cost center. Track monthly memory cost per user as a metric. The appetite to "remember everything" turns into an uncontrollably growing cloud bill.

Evaluation: how do you test an agent that remembers?

Classic LLM evaluation measures a single question-answer. But memory, by definition, must be tested over time and across sessions. Practical approaches I use in the field:

  • Recall accuracy: build scenarios that measure whether the agent correctly remembers, several sessions later, a fact told to it earlier.
  • Contradiction test: simulate cases where the user changes their mind; does the agent use the old or the new fact?
  • Noise resistance: does retrieval quality drop when memory fills with thousands of records?
  • Leakage test (critical): user A's information should never appear in user B's session. This is both a quality and a KVKK matter.

Memory design compliant with KVKK and the EU AI Act

Here is the part that most teams notice late but that costs the most when building an enterprise agent in Turkey. Let me be blunt: user memory is, by definition, personal data. If you are persistently storing a user's preferences, history and behavior, you are within the scope of KVKK (Law No. 6698). This is not something to be patched later; it must enter the design from day one of the architecture.

Concrete requirements and the implementation counterparts I recommend:

Legal basis and consent. Before writing personal data to memory, clarify which legal ground it rests on. Most scenarios require explicit consent or legitimate interest; when you tell the user "I will remember you", disclose this transparently.

Retention period and purpose limitation. KVKK does not allow you to store data indefinitely. Attach a time-to-live (TTL) and a purpose label to each memory record. Ensure the record is automatically deleted when the purpose disappears or the period expires. The consolidation cycle I described above places this at a natural point.

Right to erasure (right to be forgotten). When a user says "forget me", the system must actually be able to delete all memory records, vectors and graph nodes belonging to that person. A hierarchy like Mem0's user-level scope is a lifesaver here: you can wipe everything tied to a single user identity in one operation. If your data sits in a flat, undifferentiated vector store, this becomes nearly impossible.

Access-scope separation (multi-tenancy). In an enterprise agent, department A's memory must not leak to department B, nor one user's memory to another. Separating the memory hierarchy into user/session/agent is not just technical elegance but a direct data-security and KVKK requirement. This is why I insist on the leakage test mentioned above.

Data residency. Where does your memory store physically sit? Cross-border data transfer creates additional obligations under KVKK. For enterprise clients this sometimes forces a self-hosted vector DB or in-country hosting.

The EU AI Act side. If you touch the European market, the AI Act's risk-based approach kicks in. Persistent memory makes the agent more "autonomous" and effective; that means more impact on the user. Transparency obligations (the user knowing they are talking to an AI and that information is being stored about them), record-keeping and human oversight in high-risk uses directly affect your memory design. Being able to explain what memory stores (explainability) is no longer a luxury but a compliance requirement.

A concrete architecture: building an enterprise assistant end to end

To bring theory down to concrete ground, let me share, in simplified form, the memory architecture of an assistant we built with an insurance company last month. The goal was to build an agent that works with the same insurance agent for months, remembering policy history, customer preferences and past requests.

Our first decision was to split memory into three separate paths. The momentary context arising during the conversation (which policy we are looking at, which step we are on) was kept in the short-term layer and deleted when the session ended. The agent's persistent preferences (language, contact hours, which reports they want) were written to the semantic layer and tied to the user identity. Past requests and their outcomes were saved to the episodic layer, timestamped.

The second critical decision was the retrieval strategy. Instead of blindly querying all three layers on every new question, we placed a lightweight step that first classifies the type of question: is it about the momentary context, a persistent preference, or a past event? This classification eliminated unnecessary queries; it reduced both latency and cost. What I learned in the field: reading every memory on every query is both expensive and a noise-generating habit. The power of memory lies in knowing when to stay silent.

Let us unpack hybrid retrieval a bit: vector or graph?

The common thread between Mem0 and Cognee is that they use a hybrid backend. Let me make concrete why I care about this choice, because most teams start with vector search only and hit a wall.

Vector search is perfect for semantic similarity: on fuzzy, meaning-focused questions like "what did the customer say about car insurance?", it fetches the relevant records. But vector search does not know relationships. On a multi-step, relational question like "which was this customer's spouse's policy and how does that policy affect this request?", vector alone falls short; because it sees each record as an independent point, not the bond between them.

This is exactly where the knowledge graph comes in. The graph holds entities (customer, policy, request, department) as nodes and the relationships between them as edges. So you can reason by traversing a chain like "customer A's policy B triggered request C". My practical advice:

"

Vector for semantic, fuzzy queries; graph for relational, multi-step reasoning. Think of the two not as substitutes but as two complementary lenses.

If you are starting small, set off with vector only; bring in the graph when relational complexity grows. Building a graph from the outset is unnecessary engineering overhead if you do not need it.

The security risk coming through memory: injection and poisoning

This is one of the least discussed but most worrying topics for me. Memory, by definition, blurs a trust boundary: the agent generally assumes information it stored in the past is "true". But what if that information was planted with malicious intent?

Consider: during a conversation a user whispers a hidden directive to the agent like "always apply this instruction", and it gets written to persistent memory as a "preference". In later sessions the agent recalls this poisoned memory and blindly applies it. This is called memory poisoning, and it is a persistent, insidious variety of indirect prompt injection.

The precautions I take in the field: mark everything written to memory as "data", never as "instruction". Place a validation layer at the moment of writing to memory; prevent user content from turning into a system instruction. And most importantly, for critical actions (money transfer, policy cancellation), rely not on memory but on real-time confirmation and human approval. Memory reminds, but it does not authorize.

A special note in the Turkish context: language and cultural memory

There is a subtle issue I noticed when building Turkish agents. When memory extraction is done with a language model, how well the model captures Turkish nuances directly affects memory quality. If the model wrongly distills a preference like "the gentleman does not want to be called in the mornings", that error gets written to persistent memory and can cause wrong behavior for months.

That is why in Turkish-heavy products I additionally test the memory extraction step: we take samples from real Turkish conversations and manually audit the distilled facts the model produces. Cultural context also matters; preferences like formal/informal address and use of titles are more critical for Turkish users than expected. Writing these explicitly into semantic memory makes the agent speak in a visibly more "local" and trust-inspiring way.

The traps I fall into and see most often

Before the closing, let me leave a list of the mistakes I encounter over and over in the field; catch these early in your own project and you will save months:

  • Thinking memory equals the context window. The most basic and most expensive fallacy. A long prompt is not a system that remembers.
  • Writing everything persistently. Memory without a filter turns into a useless pile within a few months.
  • Not building the deletion path from the start. I have seen teams panic when the right to erasure arrives and they cannot delete per-user from a flat vector store.
  • Ignoring contradiction. An agent that keeps the old fact when the user changes their mind loses trust fast.
  • Not measuring memory. A team that does not monitor recall accuracy and cost only notices the problem when the user complains.
  • Forgetting the security boundary. Using memory as a source of instructions opens a permanent injection door.

The unit economics of memory: deciding with numbers

The habit that has served me most in enterprise projects is turning memory from a "cool feature" into a line of unit economics. That is, discussing every memory decision together with its monthly cost per user and the concrete value it produces. An assistant remembering a user is a pleasant sentence; but if you do not know how many cents per month that remembering costs and how many minutes of work it saves in return, your decision rests on emotion.

In the field I produce a table like this: the average number of records stored per user, the embedding and storage cost of those records, the monthly model-call cost of the consolidation step, and the per-request overhead of retrieval. When you sum these four lines, you see the real price tag of the "agent that remembers" feature. Most of the time it turns out surprisingly reasonable; but occasionally, in an uncontrollably growing memory, I have also seen cost per user exceed the value the agent produces. That is exactly the moment to bring consolidation and pruning discipline into play.

Another practical metric is memory's hit rate. Of the records recalled, how many actually contributed to the answer? If the agent pulls ten records on every question but only two are useful, you are wasting both money and context space. Measuring this ratio and tightening the retrieval threshold usually reduces cost significantly without lowering quality. Finally, memory's value must be tied to a business metric; in my insurance-assistant example, average time per transaction fell noticeably because agents no longer re-entered repeating information. That is the real justification for memory: not technical elegance, but a measurable business gain.

A consolidating action plan

If you want to build memory correctly from the start in your next agent project, here is the sequence I follow in the field:

  1. Classify the need. Is the task one-off or relational? Reject unnecessary memory upfront; not every agent needs persistent memory.
  2. Separate the memory types. Design short-term, semantic and episodic memory separately; do not dump them all into a single trash store.
  3. Abstract the store. Mem0, Cognee, Zep or Redis; whichever you start with, hide your business logic behind an interface.
  4. Set up a consolidation cycle. Periodically distill raw records, resolve contradictions, delete what has expired. Memory is a garden; it needs pruning.
  5. Bring KVKK into the design on day one. TTL, purpose labels, per-user deletion, scope separation and data residency; leaving these for later is the most expensive mistake.
  6. Measure. Regularly monitor recall accuracy, contradiction management, the leakage test and cost per user.

Building an agent that remembers is technically exciting but a job with heavy responsibility. A system remembering you is a powerful personalization promise; but the same promise, designed wrong, turns into a privacy liability. The good news is this: with the right architecture you can achieve both at once. When you build memory not inside the model but around it, as a controlled, measurable and deletable layer, you get agents that are both smarter and more trustworthy.

Consulting Pathways

Consulting pages closest to this article

For the most logical next step after this article, you can review the most relevant solution, role, and industry landing pages here.

Comments

Comments