1:1 mentoring with Big Tech AI engineers
LLM & Agentic

Memory Implementation & Patterns

Production-ready memory code, episodic vs semantic vs procedural memory, and system design patterns.

Last updated

Production8 min readFirst readThe Four Types of Agent Memory

After this section you can

  • Implement the write, retrieve, and update loop for an agent that remembers across sessions
  • Choose a short-term strategy that survives a finite context window
  • Decide what is actually worth remembering rather than persisting everything
02

Memory Implementation & Patterns

The cognitive types — episodic, semantic, procedural — and how to actually build them: short-term compaction strategies, a write–retrieve–update loop, and the production memory-system design that ties it together.

THE CENTRAL IDEA

The previous section sorted memory by where it lives. This one sorts it by what it stores — the cognitive-science taxonomy that every serious framework (LangMem, Letta, Mem0, Zep) has converged on. Three types: episodic (“what happened”), semantic (“what’s true”), procedural (“how to act”). Getting an agent to remember isn’t one feature — it’s three different pipelines with different write triggers, retrieval methods, and update rules. Conflate them and you get the classic failure: a vector store full of raw transcripts that retrieves nothing useful.

The three cognitive types — different write triggers, different retrieval, different decay
EPISODIC “what happened” Stores: events, past turns, outcomes — with timestamps write: after each interaction read: similarity + recency decay: yes — ages out e.g. “On Mar 3 the user asked for a refund on invoice #4821” SEMANTIC “what’s true” Stores: facts, preferences, relationships — distilled write: when a fact is learned read: semantic similarity update: in place (overwrite) e.g. “User prefers metric units; their manager is Sarah” PROCEDURAL “how to act” Stores: rules, skills, learned routines — the how-to write: when a strategy proves out read: always (in system prompt) update: rarely, deliberately e.g. “For refunds over $500, always check the tier first”

Related

More in LLM & Agentic

Get full access to all 74+ sections with code examples, diagrams, and interactive animations.

Unlock Premium