Agent memory hierarchy

session statestoredretrievedwrite-back
Workingin-contextSemanticvector index / RAGEpisodicMEMORY.md
  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.
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)