Skip to content
47% off: the complete course for $79 (reg. $149)Order now →
Agent Builder
Module 5Full course14 min read

Adding Memory to Your Agent

Give the course agent memory that lasts between sessions: what to store, where to store it, and how to load only what matters.

Tell your agent "I prefer temperatures in Fahrenheit" and it will happily comply, for exactly one run. Start it again tomorrow and it has no idea who you are. Every session begins from zero, because the only memory your agent has is the messages array, and that array is thrown away when runAgent returns.

In this lesson you'll give the agent memory that lasts between sessions. You'll decide what's worth remembering (far less than you'd think), store it in a small file you can read and edit yourself, and load only the memories that matter for each task, so memory helps the agent instead of filling its context with noise. You'll also see why memory is a security surface, and what to do about it.

Three kinds of memory

Your agent already has two kinds of memory. This lesson adds the third.

KindWhere it livesLifetimeExample
Working memoryThe messages arrayOne runThe file it read three turns ago
WorkspaceFiles in workspace/Until deletedreports/weather.md
Long-term memoryA memory store you manageAcross sessions"User prefers °F"

The workspace already persists, so why not just let the agent write notes to a file there? Two reasons. First, workspace files are the agent's output, and the agent can overwrite or delete them freely with write_file. Memory should change only through deliberate operations you control. Second, the agent would have to remember to go and read its notes, and it won't know they exist unless something tells it.

A real memory system answers three questions, which make up the rest of this lesson: what to store, where to store it, and how to load only what matters. If you want the bigger conceptual picture first, including file-based memory in tools like Claude Code, read Giving Agents Memory.