Skip to content
AI Engineering
Agents

Memory and state

The model remembers nothing between calls. Memory is whatever your system stores and puts back in the window.

Chapter 9: AgentsLesson 7 of 10Level: CoreAbout 12 min
Words on this page (10)
logarithm
: The power you raise a base to in order to get a number. log base 2 of 8 is 3 because 2 to the power 3 is 8.
vector
: An ordered list of numbers. Embeddings and model activations are vectors.
skill
: A folder of instructions and scripts an agent loads only when a task needs it.
agent
: A model run in a loop that chooses its own tools and steps until the task is done.
retrieval
: Finding the most relevant pieces of text for a query.
harness
: Everything around the model that makes it an agent: prompts, tools, rules, sandboxes, hooks, memory and checks.
prompt
: The input text you give a model, including instructions, examples and data.
token
: A piece of text the model reads and writes, usually a word or part of a word. About 4 characters of English on average.
tool
: A function the model can ask your program to run, described by a name, description and argument schema.
repo
: Repository: a project folder tracked by git, usually hosted on GitHub.

Kinds of memory

Working memory is the current context. Session memory is a or summary of what happened so far. Long-term memory is facts and preferences stored outside the window, usually as files, a database or a index, and retrieved when relevant. Procedural memory is instructions and that tell the how to do things.

Practical design

Start with plain files: a progress notes file, a decisions log and the project memory file. They are readable, diffable and easy to edit. Add only when the notes outgrow the window. The hard problems are choosing what to write down, avoiding stale or wrong facts, and forgetting on purpose. Anything the agent writes to memory can be wrong, so treat it as a hypothesis to verify.

A worked example: a notes file

After each session the agent appends to notes.md: "User prefers metric units. Project uses PostgreSQL 15. Decision 3 May: use queue for emails." At the next session it reads the file first. Plain text, readable by you, editable by you. Later, if the file grows, add search over it.

How a note gets back into the window

The model does not read your notes file by itself. At the start of each session your reads the file and pastes it into the , so the text is in the window again.

That has a price. Invented numbers: the file is 2,000 and grows by 200 tokens a session. Every call carries it. After 40 sessions it is 10,000 tokens on every call, even when most lines are irrelevant. That is the point where search over the notes starts to pay for itself.

What goes wrong: stale memory

A note says "The project uses PostgreSQL 15." The team has since moved to 16. The agent reads the note, trusts it, and writes code for the old version. The symptom is an agent acting confidently on a fact that was once true. Confirm it by asking the agent where it got the fact, then checking the date on that note. Fix it by dating every entry and having the agent check anything it can look up, such as a version, before acting on it.

When memory is the wrong tool

Do not copy into notes what the agent can read from the source. A list of files in the goes out of date on the next commit, while the repo itself is always right. Use memory for what cannot be recovered: what the user prefers, which approach was chosen and why, and which attempts already failed.

Common mistake

Building a complicated memory system before trying a notes file.

Check yourself

Where should an agent's notes start out?

Why treat remembered facts as hypotheses?

A user moves to a new database and the notes still say PostgreSQL. What is this problem?

Go deeper

  • Repo
    mem0Repo★ 67k

    Mem0 · A memory layer for agents with extraction and retrieval.

  • Repo
    LettaRepo★ 25k

    Letta · Stateful agents with self-managed memory, from the MemGPT line of work.

  • Article

    Anthropic · Structured note-taking and just-in-time retrieval.

Spotted a mistake or something unclear? Report it on GitHub.

On this page