# 4.1 Agent memory hierarchy

Working, semantic and episodic memory tiers with explicit read/write paths.

1. Working memory: in-context, volatile, per session.
2. Semantic memory: top-k retrieval (RAG) into context.
3. Episodic memory: persistent notes loaded at start.
4. Reflection writes back; working memory is flushed.

- **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)
```

## References

- [Effective context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) (Anthropic)
- [Memory tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/memory-tool) (Anthropic)
- [How Claude remembers your project](https://code.claude.com/docs/en/memory) (Claude Code)
- [MemGPT: Towards LLMs as Operating Systems](https://arxiv.org/abs/2310.08560) (Packer et al.)
- [Cognitive Architectures for Language Agents](https://arxiv.org/abs/2309.02427) (Sumers et al.)
- [Generative Agents](https://arxiv.org/abs/2304.03442) (Park et al.)
