03. Core Components
Agent Memory Types (Short-Term, Long-Term, Episodic, Semantic)
Agent memory is how systems keep state beyond one model call. Short-term holds the working context; long-term persists across sessions; episodic stores events; semantic stores lasting facts.
What you will learn
- Define the four common agent memory types
- Map each type to product storage patterns
- Explain read/write flow inside the agent loop
- Choose what to persist vs keep ephemeral
- Answer interview questions with short, solid answers
Definition
Memory lets an agent use information that is not in the current raw user message alone. Without memory, every turn is amnesia with a bigger prompt dump.
In Agentic AI, memory is engineered: buffers, databases, vector stores, and curated profiles — not mystical model weights. Training data is not the same as runtime memory you can update per user.
Introduction
This lesson (#4 in Core Components) follows Reasoning and Planning. Plans need state; state lives in memory. Next lessons cover tools and APIs that produce new observations to store.
Cognitive-science labels are useful metaphors — implement them as clear data models.
Why memory matters
- Survives context-window limits via retrieve-and-pack
- Personalizes agents without retraining
- Enables multi-step goals across sessions
- Supports learning from past successes and failures
Short-term memory (working memory)
Short-term memory (STM) is the active scratchpad for the current task or session: recent messages, the open plan, intermediate tool results, and slot-filled state.
- Lifetime - minutes to one session / one job run
- Store - in-process state, Redis, conversation buffer
- Examples - current ticket fields; failing test name; plan checklist
- Ops - summarize or drop when the token budget tightens
Long-term memory
Long-term memory (LTM) persists beyond a single session so the agent can recall later. Episodic and semantic memories are usually kinds of long-term content.
- Lifetime - days to indefinite (with retention policy)
- Store - SQL/NoSQL, object storage, vector DB, graph DB
- Examples - user preferences; project conventions; prior incident writeups
- Ops - access control, TTL, GDPR/deletion, quality filters on write
Episodic vs semantic memory
Episodic memory records events in time — “what happened.” Semantic memory stores generalized knowledge — “what is true / preferred.” Both may be long-term.
- Episodic - traces, run summaries, “last time we fixed X by Y”
- Semantic - profiles, FAQs, policies, entity attributes
- Episodic retrieval - by time, task similarity, embedding of the story
- Semantic retrieval - by key, entity id, or meaning search
- Promotion - repeated episodes may be distilled into semantic facts
Memory in the agent loop
Treat memory as explicit read and write stages, not accidental chat history growth.
- Retrieve - pull STM + relevant LTM into the context pack
- Decide / act - use tools; update STM with observations
- Persist - gated write of episode summaries or new semantic facts
- Forget - TTL, user delete, and decay for stale or wrong memories
Implementation patterns
- Buffer memory - rolling chat window (STM)
- Summary memory - compressed STM when history grows
- Vector memory - embed episodes/docs for similarity recall
- Entity / profile store - semantic attributes keyed by user/project
- Checkpointer - resume long workflows (STM snapshot)
Program / implementation notes
Separate stores by purpose. Write policies matter as much as retrieval — garbage in memory becomes confident wrong context later.
- Schema every memory record (type, owner, timestamp, source, confidence)
- Never auto-write secrets or raw PII without policy
- Cite memory sources in logs when used for a decision
- Eval retrieval: did the right memory enter the pack?
- Next: Tool Calling, Function Calling and Action Execution
Advantages and limitations
- Advantage: continuity across turns and sessions
- Advantage: personalization and fewer repeated questions
- Advantage: learning from episodes without fine-tuning
- Limitation: stale or wrong memories poison decisions
- Limitation: privacy and retention obligations
- Limitation: retrieval noise if everything is embedded indiscriminately
Key points
- STM = working context for the current task/session.
- LTM = persisted knowledge across sessions.
- Episodic = timed events; semantic = durable facts/preferences.
- Read memory into context; write with gates and schemas.
- Model weights ≠ updatable runtime memory.
- Forgetting and access control are part of the design.
FAQs
Is the context window short-term memory?
It is the hard limit for what the model sees now. STM is the broader working state you manage — often summarized into that window.
Is RAG the same as long-term memory?
RAG is a retrieval pattern often used to implement LTM (especially document/semantic knowledge). Memory also includes profiles, episodes, and structured state.
Should every tool result go to long-term memory?
No. Keep most results in STM; persist summaries or facts only when they will help future tasks and pass privacy checks.
Can fine-tuning replace memory?
No. Fine-tuning changes general behavior; runtime memory stores user- and task-specific state you can update and delete.
Interview questions
- What are the main types of agent memory?
Answer Short-term (working), long-term (persistent), episodic (events/traces), and semantic (facts/knowledge) — often combined in one system.
- Short-term vs long-term memory?
Answer Short-term holds active session/task state. Long-term persists across sessions for later retrieval.
- Episodic vs semantic memory?
Answer Episodic stores what happened at a time; semantic stores durable facts or preferences that remain true beyond one event.
- How does memory fit the observe–think–act loop?
Answer Retrieve relevant memory into context before deciding; update short-term after observations; optionally persist long-term after valuable outcomes.
- How would you implement long-term memory?
Answer Use a durable store (DB/vector/profile service) with schemas, authz, retention, and a retrieval step in the context builder.
- What goes wrong with agent memory?
Answer Stale facts, prompt injection via stored text, privacy leaks, and noisy retrieval that crowds out useful context.
- Is chat history enough memory for agents?
Answer It is a basic STM form, but serious agents also need structured state, selective persistence, and typed episodic/semantic stores.
Related topics
Practice task
Complete each numbered practice step in a notebook or doc before opening the next lesson.
- Write one-sentence definitions for STM, LTM, episodic, and semantic memory.
- For a support agent, list two examples of each type.
- Design a memory record schema: fields you would always store.
- Sketch retrieve -> decide -> act -> persist and mark write gates.
- Answer interview questions 1, 3, and 6 in two sentences each.