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

Production10 min readFirst readAgent Memory: Layers & Types

After this section you can

  • Implement the retrieve, extract and reconcile loop for memory that lasts across sessions
  • Choose a short-term strategy that fits the model, using compaction instead of trimming history on current Claude models
  • Design a memory record and decide what is worth writing to it
17

Memory Implementation & Patterns

How an agent actually remembers: retrieve before the turn, extract and reconcile after it, keep each session inside the window without rewriting history, and design a store you can search, correct and delete from.

Key idea

Long-term memory is a loop wrapped around the agent loop: retrieve what is relevant before the turn, extract candidates after it, and reconcile each one against what is stored. Retrieval gets the attention; reconcile decides whether the store stays true.

Long-term memory is a loop around the agent loop. Reconcile is the step that keeps the store true.
BEFORE AND DURING THE TURN AFTER THE TURN, OFTEN ASYNC Memory store facts · episodes · rules scoped to one owner with source and time 1 · Retrieve filter by owner rank: relevance, recency, importance 2 · Answer model turn with memories in the context window 3 · Extract candidate facts and episodes from this exchange 4 · Reconcile compare with stored ADD · UPDATE DELETE · NOOP 5 · write back: one operation per candidate, never a blind append Retrieval is a search problem you can tune. Skip reconcile and the store fills with contradictions no ranking can fix.

Related

More in LLM & Agentic

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

Unlock Premium