Agent memory hierarchy
session statestoredretrievedwrite-back
- Working memory: in-context, volatile, per session.
- Semantic memory: top-k retrieval (RAG) into context.
- Episodic memory: persistent notes loaded at start.
- Reflection writes back; working memory is flushed.
Notes & references
Use when
State must persist across sessions and context windows.
Avoid
Indiscriminate writes: they reintroduce retrieval noise.
# start of session
context = [
system_prompt,
read("MEMORY.md"), # notebook
*search(library, question, k=3), # library
*recent_messages, # desk
]
# end of session
append("MEMORY.md", lesson_learned)
- Effective context engineering for AI agentsAnthropic
- Memory toolAnthropic
- How Claude remembers your projectClaude Code
- MemGPT: Towards LLMs as Operating SystemsPacker et al.
- Cognitive Architectures for Language AgentsSumers et al.
- Generative AgentsPark et al.