Episodic vs Semantic vs Procedural Memory in Agents
~15 min read
Long-term agent memory, mirroring human memory, splits into three distinct flavors: semantic (facts), episodic (past experiences), and procedural (learned how-to knowledge) — each stored and used differently.
Once you move past in-context and external memory as STORAGE mechanisms, there's a separate, equally important question: what KIND of information is actually being remembered? Long-term memory in agents, mirroring the same distinction from human cognitive science, splits into three flavors, and each one is used differently by an agent.
Semantic memory stores facts and knowledge — the kind of information that's true independent of any specific episode or interaction: 'the user's subscription tier is Pro,' 'the API rate limit is 100 requests/minute,' 'the company's return policy is 30 days.' This is the closest analog to a traditional knowledge base or a set of facts in a database, and it's typically what gets retrieved when an agent needs to answer a factual question or apply a known constraint.
Episodic memory recalls past EXPERIENCES or completed tasks — not general facts, but specific things that happened: 'last Tuesday, I helped this user troubleshoot a login issue, and the root cause turned out to be an expired session token,' or 'the last time I tried this API call with these parameters, it returned a 429 rate-limit error.' This is what lets an agent avoid repeating a mistake it's already made, or pick up a multi-day task exactly where it left off, because it's recalling the specific episode, not just a general fact derived from it.
Procedural memory learns HOW to do things — internalized 'how-to' knowledge, closer to a skill than a fact or a memory of a specific event. In practice, for LLM-based agents, this often takes the form of prompts or instructions that have been refined over time based on what worked — a system prompt that's been iteratively improved to handle a recurring task well is a form of procedural memory, even though it doesn't look like a 'memory' in the conversational sense at all.
This distinction isn't just academic categorization — it directly informs storage architecture. Semantic memory usually lives well in a structured database or knowledge base; episodic memory usually lives well in a vector store, retrieved by similarity to the CURRENT situation ('has something like this happened before?'); and procedural memory often lives as versioned prompt/instruction text that gets updated based on observed outcomes, rather than as retrievable records at all.
💻 Code example
from dataclasses import dataclass, field
from datetime import datetime
@dataclass
class SemanticFact:
key: str
value: str
@dataclass
class EpisodicMemory:
timestamp: datetime
situation: str
outcome: str
class AgentMemory:
def __init__(self):
self.semantic: dict[str, str] = {}
self.episodic: list[EpisodicMemory] = []
self.procedural: dict[str, str] = {} # task_name -> refined instructions
def learn_fact(self, key: str, value: str) -> None:
self.semantic[key] = value # e.g. "subscription_tier" -> "pro"
def record_episode(self, situation: str, outcome: str) -> None:
self.episodic.append(EpisodicMemory(datetime.now(), situation, outcome))
def refine_procedure(self, task_name: str, improved_instructions: str) -> None:
self.procedural[task_name] = improved_instructions # updated "how-to"
memory = AgentMemory()
memory.learn_fact("subscription_tier", "pro")
memory.record_episode(
situation="User's login failed with token error",
outcome="Root cause was an expired session token — resolved by re-auth",
)
memory.refine_procedure(
"troubleshoot_login",
"Always check token expiry FIRST before checking password issues.",
)
💬 Deep Dive with AI
Key points
- •Semantic memory stores facts/knowledge that are true independent of any specific event — typically a structured lookup
- •Episodic memory recalls specific past experiences or completed tasks — typically retrieved by similarity to the current situation
- •Procedural memory is internalized 'how-to' knowledge — for LLM agents, often refined prompts/instructions rather than retrievable records
- •Semantic memory answers 'what do I know'; episodic memory answers 'what have I seen before'; procedural memory answers 'how do I do this well'
- •This distinction directly informs storage architecture — database for semantic, vector store for episodic, versioned instructions for procedural