AI Agent Memory: Short-Term, Long-Term, Episodic, and Vector
AI Agent Memory is for builders who need the term to survive contact with real products, tools, and failure modes. The goal is a practical mental model you can use in design review, not a glossary definition.
We will follow one concrete workflow, separate mechanism from product language, and end with a checkable practice. For nearby background, connect this with Context Engineering and RAG Chunking Strategies.
Memory Is State With a Retrieval Policy
Agent memory is often presented as if the model simply remembers. In production, memory is state stored outside the model: recent messages in context, durable user preferences in a database, episodic task traces, and vector-indexed notes retrieved by similarity.
The running example is a coding assistant remembering that project Atlas uses Postgres and strict TypeScript. The product question is which facts should persist, who can edit them, when they expire, and how they re-enter the prompt.
Quick reference
- Short-term memory lives in the active context window.
- Long-term memory persists beyond one conversation.
- Episodic memory stores task events and outcomes.
- Vector memory retrieves by similarity, not exact truth.
Remember this
Memory is not magic recall; it is external state plus rules for writing, retrieving, and forgetting.
Different Memories Fail in Different Ways
Short-term context fails when the window fills or becomes polluted. Long-term profiles fail when stale preferences are treated as current facts. Episodic traces fail when a past task looks similar but had different constraints. Vector memory fails when similarity returns a nearby but wrong note.
For Atlas, uses Postgres may be durable, but currently migrating billing may expire next week. The memory schema should distinguish stable preference, project fact, temporary plan, and sensitive secret.
Quick reference
- Store memory type, source, timestamp, confidence, and owner.
- Never store secrets as memories.
- Prefer user-visible memory controls for personal facts.
- Retrieve fewer memories with stronger filters.
Remember this
A memory system needs type and lifecycle metadata because stale helpful facts become hidden bugs.
Failure Story: Old Memory Overrides the Repository
Trigger: the assistant remembered that Atlas used Prisma, but the repo migrated to Drizzle. Symptom: generated code imports the wrong ORM. Root mechanism: durable memory entered the prompt without checking the current source tree.
Recovery is to prioritize live evidence over memory and mark the old fact obsolete. Prevention is a precedence order: user instruction, current files/tool evidence, recent task state, then long-term memory. Memory should propose context, not overrule reality.
Quick reference
- Rank live tool evidence above stored memory.
- Attach source links or file paths to durable project facts.
- Expire implementation memories after migrations.
- Let users delete or correct wrong memories.
Remember this
Memory should be advisory context; current evidence owns the final decision.
Practice: Design a Memory Table
Create a table with columns for subject, fact, type, source, createdAt, expiresAt, confidence, and visibility. Add five memories for Atlas, then write retrieval rules for a code-generation task.
Pass when a stale ORM memory is excluded, a stable database preference remains, and a secret-like value is rejected. This gives you a memory design you can review before wiring any vector database.
Quick reference
- Starter: use a local JSON file or SQLite table.
- Expected success: only relevant, non-expired facts enter the prompt.
- Intentional break: add
API_KEY=...as a memory. - Recovery: block storage and log a policy event.
Remember this
A usable agent memory design proves what gets written, recalled, corrected, and forgotten.
Key takeaway
Use the concept when it gives you a clearer boundary, measurement, or operating rule. Skip the label when it only makes the system sound more advanced.
Practice should leave behind an artifact: a table, eval set, trace, or checklist that another engineer can inspect. Pass when the artifact catches the intentional failure described above and gives a concrete recovery path.
Related Articles
Explore this topic