How it works · 33 of 49 Core

How does AI agent memory and state work?

What an agent keeps between steps, tasks and days

Agent memory & state: An agent has three places to keep things, and they last for different times. The context window is what it holds right now: it fills with every step and must be cut or summarised (compacted) when full. Task state (a checkpoint, a to-do list, a NOTES.md file) lives outside the window and lasts until the task ends, so a long task can survive a fresh window. Long-term memory (a store, filed under a user or topic) lasts across tasks and sessions: facts, past events and rules. Each is a design choice: what to write, when, where it is filed, and what must be forgotten, because a stale or private memory that is never removed keeps steering the agent.

Loading the animation…

Say it like this An agent keeps things in three places that last for different times: the context window for this step, task notes or a checkpoint for this task, and a long-term store for across tasks; decide what gets written to each, where it is filed, and what must be forgotten.

Under the hood — for builders
The source, in its words
Rajasekaran, Dixon, Ryan and Hadfield ("Effective context engineering for AI agents", Anthropic, Sep 2025): context is "a finite resource with diminishing marginal returns"; with note-taking "the agent regularly writes notes persisted to memory outside of the context window."
Three stores, three lifetimes
Terms: compaction, summarising a nearly full window to start a fresh one; checkpoint, saved task state that can be resumed; namespace, the shelf a memory is filed under.
The source's example
A Pokémon-playing agent's own note: "for the last 1,234 steps I've been training my Pokémon in Route 1, Pikachu has gained 8 levels toward the target of 10." Claude Code compacts and keeps "the five most recently accessed files".
Run here: a long task
60 steps; 10 facts learned along the way, each needed later. The window holds 20 steps. Compaction keeps each older fact 70% of the time; the agent writes 90% of facts to notes. Rates are ours.
Kinds of long-term memory
LangGraph: semantic ("Facts about a user"), episodic ("Past agent actions"), procedural ("Agent system prompt").
When to write
"In the hot path" (during the task) can "impact agent latency"; "in the background" "eliminates latency" but lags. Subagents hand back "often 1,000-2,000 tokens".
Measure it
Facts recalled when needed · tasks that survive a fresh window · wrong or stale memories used · time to delete a person's memories.
Watch out
LangGraph: a full history can cause "an irrecoverable error"; "remove or forget stale information". File memories by user. Our run is a toy.
Sources
Rajasekaran, Dixon, Ryan and Hadfield, "Effective context engineering for AI agents", Anthropic Engineering, 29 Sep 2025 · LangChain, "Memory", LangGraph concepts, read 19 Nov 2026 · task simulation, Python, 19 Nov 2026.

What happens in the agent memory & state animation, step by step?

  1. An agent works in steps. What it holds right now is its context window: notes on the hand, a small space that fills as it goes.
  2. Long tasks outgrow the window. Before it is wiped, the agent writes what matters to a trail diary outside it, a notes file or a checkpoint, and reads it back next morning.
  3. At the cabin the lessons go into a logbook: long-term memory, kept across tasks and filed under who or what it is about.
  4. Your turn: tap a day above the trail, or the next hiker, to see what each store holds then.
  5. A new task starts with an empty hand and a blank diary. Only the logbook carries over, so the next hiker avoids the broken bridge.
  6. Forgetting is part of the design: stale entries mislead, and a person's notes belong on their own shelf, where they can be deleted. Next: checks on what an agent does.

What everyday example explains agent memory & state?

A trekker: notes inked on the hand wash off each night, the trail diary lasts the trip, and the cabin logbook greets the next hiker.

Why should a team care about agent memory & state?

Most "the agent forgot" bugs are a missing write, not a weak model; most "the agent remembered something it shouldn't" bugs are a missing namespace or delete. Both are architecture.