Memory

Day 1 - Block 6

Context = Short-Term Memory 1

The session (“chat”) is the agent’s context (i.e. short-term memory).

We can also edit this history (e.g. in LangChain)!

But: Context window is finite and session-bound!

Long-Term Memory

Memory system that

  • persists across sessions
  • can be (much) larger than context window

-> injects relevant info into context

Long-Term Memory (Level 1): MEMORY.md 1

  • Policy in AGENTS.md
  • Facts/logs in MEMORY.md
# AGENTS.md (memory policy)

## Memory policy
- Load `MEMORY.md` at session start.
- Append durable facts to `memory/YYYY-MM-DD.md`.
- If user says "remember this", write it down immediately.
- Promote stable preferences/decisions into `MEMORY.md`.

## Editing rules
- Keep entries short, factual, and timestamped.
- Remove stale items when contradicted by newer evidence.

Long-Term Memory (Level 2): “Clever” MEMORY.md 1

We can post-process MEMORY.md:

  • Summarize (compress)
  • Prune it
  • Introduce hierarchy (INDEX.md file pointing to other MEMORY.md files)

Long-Term Memory (Level 3): 1

Retrieval-Augmented Generation (RAG) (… and fancy systems on top of it)

  • Embed documents into vector space
  • Compare query embedding to document embeddings (cosine similarity)
  • Inject relevant passages into context

Figure from LangChain

Figure from LangChain

References

LangChain. 2026a. “Retrieval in LangChain.” https://docs.langchain.com/oss/python/langchain/retrieval.
———. 2026b. “Short-Term Memory in LangChain.” https://docs.langchain.com/oss/python/langchain/short-term-memory.
Lewis, Patrick, Ethan Perez, Aleksandra Piktus, Fabio Petroni, Vladimir Karpukhin, Naman Goyal, Heinrich Kuttler, et al. 2020. “Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks.” In Advances in Neural Information Processing Systems. https://proceedings.neurips.cc/paper_files/paper/2020/hash/6b493230205f780e1bc26945df7481e5-Abstract.html.
Microsoft Research. 2025. “Effects of LLM Use and Note-Taking on Reading Comprehension and Memory.” https://www.microsoft.com/en-us/research/publication/effects-of-llm-use-and-note-taking-on-reading-comprehension-and-memory-a-randomised-experiment-in-secondary-schools/.
OpenClaw. 2026. “OpenClaw Documentation.” https://docs.openclaw.ai/.
OpenCode. 2026. “OpenCode Documentation.” https://opencode.ai/docs/.
Willison, Simon. 2025. “Agentic Engineering Patterns.” https://simonwillison.net/guides/agentic-engineering-patterns/.