← AI Security & GovernanceAI Security & Governance

AI Agent Memory

Everything an agent keeps between turns and between sessions — sliced two ways, because each type is also its own attack surface.

A model answering a single prompt has no memory — the context window is all it knows. An agent is different: it carries state forward, so it can pick up a task where it left off, remember what you prefer, and reuse an approach that worked last week. That state splits cleanly intoshort-term memory — the live context for the task in hand, usually a rolling summary of the conversation — andlong-term memory, which survives the session and is retrieved on demand.

Long-term memory is where the interesting design choices — and the interesting security problems — live. It gets categorized two different ways: by what kind of thing is being remembered (its function), and by how it's stored and retrieved (its structure). They're not alternatives; a single system has a function and a structure, and most real agents run several combinations at once.

The Two Ways to Slice Agent Memory

The top band is the cognitive taxonomy — borrowed loosely from how human memory is described. The middle band is the engineering taxonomy — the actual data structure behind the store. The legend is what production frameworks (LangChain, LlamaIndex, LangGraph, MemGPT / Letta) tend to assemble in practice.

Agent memory categorized by function and by structure, and how the two combine in practice🧩 MEMORY BY FUNCTION — what kind of thing is rememberedEPISODIC• Specific past events• "You asked me to fix bug X"• Continuity & personalization• Timestamped entries, a logSEMANTIC• General facts, not events• "User prefers Python"• "Rate limit is 100/min"• A knowledge base, not a logPROCEDURAL• "How to do things"• Learned workflows, tool use• Strategies that worked before• Playbooks/scripts or fine-tuneREFLECTIVE / META• The agent's notes on itself• "That failed — next time X"• Periodic self-review, distilled• Distinct from raw episodesthe same memories — organized a second way🗄️ MEMORY BY STRUCTURE — how it's stored & retrievedVECTOR / EMBEDDING• Similarity search over text chunks• Most common — RAG-style recallKEY-VALUE• Explicit fact records• Like a user profile• Interpretable, editable, deletableGRAPH• Entities + relationships• Reason over connectionsBUFFER / SUMMARY• Rolling summary of the conversation• Keeps context compact — but lossyEXTERNAL DB / TOOL• Query a real DB or filesystem• No internal store to secure or syncIN PRACTICE — most production agents run several of these at once⚡SHORT-TERM BUFFERthe live task context🔎VECTOR STOREepisodic + semantic recall🗂️STRUCTURED PROFILEstable, editable facts

By function — what kind of thing is remembered

TypeWhat It HoldsWhat It's ForHow It's Stored
EpisodicRecords of specific past events and interactions — "the user asked me to fix bug X on Tuesday, and here is what I did."Continuity and personalization across sessions; being able to say what happened and when.Timestamped entries — a log, often embedded so past episodes can be recalled by similarity.
SemanticGeneral facts and knowledge not tied to any one event — "the user prefers Python over JS," "the API rate limit is 100/min."A stable knowledge base the agent can rely on without re-deriving it every time.Structured records or embedded notes; closer to a profile or a wiki than a log.
Procedural"How to do things" — learned skills, workflows, tool-use patterns, strategies that worked before.Reusing a known-good approach instead of re-planning from scratch.Reusable playbooks, scripts, or prompt templates — sometimes baked into fine-tuning rather than kept as text.
Reflective / metaThe agent's own summary and evaluation of its past actions — "that approach failed, next time try X."Self-correction over time; distinct from just replaying raw episodes, because the lesson is already distilled.Periodically generated reflection notes, written back to long-term memory as their own records.

By structure — how it's stored and retrieved

TypeHow It WorksGood AtWatch For
Vector / embeddingText chunks stored with embeddings; retrieval is a semantic-similarity search.Fuzzy recall over lots of unstructured history — the default for RAG-style agent memory.Opaque (you can't easily read what it "knows"); needs strict per-user partitioning.
Key-value / structuredExplicit facts as structured records, like a user-profile document.Interpretable and editable — you can see, correct, or delete a specific fact.Someone has to decide what gets promoted to a durable fact, and keep it current.
GraphEntities and the relationships between them, stored as a knowledge graph.Reasoning over connections — "who reports to whom," "which service depends on which."Heavier to build and maintain; extraction errors compound across edges.
Buffer / summaryA rolling summary of the conversation so far, regenerated as it grows.Keeps the active context compact and cheap without dropping the thread.Summarization is lossy — detail the agent will later need can quietly disappear.
External tool / databaseNo internal memory store at all — the agent queries a real database, ticketing system, or filesystem.One source of truth, existing access controls, nothing new to secure or keep in sync.Latency and availability of that system become the agent's; query injection is a risk.

The design choice comes down to trade-offs between retrieval accuracy, latency, cost, and how much you want the memory to be interpretable and editable versus purely embedding-based. A structured profile you can read and correct is safer to operate; a vector store scales to far more history with far less curation. Most teams use both.

The Read Path, the Write Path, and Where It Breaks

Memory has two directions, and the security problems are almost all on the way in. On the read path, the agent assembles context for a turn from the short-term buffer, a similarity search over long-term memory, and any structured profile facts. On thewrite path, after the turn, some distillation of what happened — an episode, a new fact, a reflection — gets written back to long-term memory, where it will be retrieved automatically on every future turn. Anything that lands in that store is trusted by default forever, which is exactly why the write path needs a gate.

An agent turn is a loop around one shared long-term memory store, and the four ways that store fails① READ PATH — assemble the turn's context, including a similarity search over long-term memoryShort-term bufferrolling summary of the chatStructured profilestable, editable factsContextassemblyModelResponseLONG-TERM MEMORYepisodic · semantic · procedural · reflectivevector · key-value · graph — per user, TTLread — top-K by similarity② WRITE PATH — persist what happened, but only through a gateResponse + turnepisode / fact / reflectionWrite gatePII scrub · injection filtertenant scope · attributionwrite — only what passes the gateafter the turnMEMORY POISONINGfalse fact persisted,replayed every sessionPERSISTED INJECTIONmalicious text savedonce, runs foreverCROSS-TENANT LEAKstore not partitionedper userDATA RETENTIONPII / secrets linger;erasure ignored

Memory Is an Attack Surface

Every memory type on this page is useful and dangerous for the same reason: it lets something from the past influence a future decision without a human in the loop. That's the whole value, and it's the whole risk. The table maps each failure mode to the control that actually addresses it — and note that several of these map straight onto the broader AI risk taxonomies: memory poisoning is the top-ranked threat in OWASP's Agentic Security Initiative work, persisted injection isprompt injectionwith a longer fuse, and data retention is adata-protectionobligation the moment personal data is involved.

RiskWhat HappensPrimary Control
Memory poisoningA false or attacker-planted "fact" gets written to long-term memory and is then trusted on every future turn. OWASP's Agentic Security work ranks this as the top agentic-AI threat.Gate writes: validate and attribute what gets persisted, prefer editable structured facts over silent embedding, and let a human review or roll back memory.
Persisted prompt injectionAn injection the agent reads once — in a document or tool result — gets saved into memory, so it replays automatically in sessions long after the original content is gone.Treat retrieved memory as untrusted data, not instructions: delimit it, and separate "content that can inform an answer" from "content that can trigger an action."
Cross-session / cross-tenant leakageA vector store or profile table that isn't partitioned per user returns one person's history — or one customer's data — to another.Namespace every memory by a verified identity; make the user/tenant key a mandatory filter on every read, enforced server-side, not a convention.
Sensitive-data retentionSecrets, credentials, or personal data land in a durable store that outlives the conversation and was never in scope for that kind of data — including under a right-to-erasure request.Scrub or classify before persisting, set a TTL / decay on episodic memory, and keep memory addressable so a specific record can be found and deleted.
Integrity & auditabilityNo record of what the agent knew, when it learned it, or who could change it — so a bad outcome can't be traced to the memory that caused it.Log memory writes and reads like any other privileged operation; version the store; restrict who (and which agent) can write.

How I'd Design Agent Memory

Short-term memory is a context-window optimization. Long-term memory is a database the agent writes to itself and trusts unconditionally — so it needs the same things any other trusted datastore needs: an owner, access control scoped to one identity, a retention limit, an audit trail, and a gate on what's allowed in.

See Securing Agentic AI Systemsfor how a poisoned memory becomes a cascading failure across an agent chain,AI Identity & Criticality Tiersfor the verified identity that memory reads should be scoped to, andDefense in Depth for Bedrock AI Chatfor how this site's own chatbot delimits retrieved context as inert reference.