Lesson 04.10 · Phase 04 · Memory & Context Engineering

Files as long-term memory

The simplest memory that works across sessions is a folder of Markdown files the agent can read and edit. Make the tools safe, keep an index in every prompt, and the next session picks up where this one stopped.

Learning objectives

  • Implement memory file tools (view, create, strreplace, insert, delete) scoped to one directory.
  • Defend them: reject paths that escape the directory (including through symlinks), limit file types, cap file and directory size, and require edits to match exactly once.
  • Load a short index file into every system prompt, so a new session knows what memory exists.
  • Show two sessions with no shared context continuing the same task through files.

Lessons 5 to 8 built memory out of databases: vectors, facts, episodes. They work, and they are invisible. You can't open them in an editor, review them in a pull request, or fix a wrong fact by hand without writing code.

Loading the full lesson…