How Do AI Agents Remember What They’re Doing? Context, Memory, and State Explained

How AI agents keep track of multi-step work: the difference between context, memory, saved state, checkpoints and the model itself, in plain English.

An AI agent keeps track of what it is doing because the software around its language model writes down a running record of the task and hands the relevant parts back to the model at every step. The model itself does not hold on to anything from one call to the next [1], so when people say an agent “remembers,” they are describing that record-keeping.

Ask an agent to check five suppliers, compare their prices and draft a summary, and by step twelve it needs to know which suppliers it has checked, what it found and what is still missing. That running record of a task in progress is agent state: the goal, the plan, the actions taken, the results returned and the work still pending. Four related ideas sit around it. Context is what the model is shown on a single call [2, 3]. Memory, in the agent sense, is information kept on purpose across tasks [4, 5]. A checkpoint is a saved copy of the state, so work can resume after a pause [4]. The underlying model is the trained system that generates each response; what it learned in training changes only through further training, not ordinary use [1].

The researchers behind the CoALA framework note that language models “do not persist information across calls,” while agents built around them can store information for multi-step work [1]. In OpenAI’s Agents SDK, the model sees only the conversation history it is handed on each call [3]. So the software around the model keeps the state and decides what to send back each time. New to agents? Start with what an AI agent is.

The previous guide, how an AI agent can use a computer, showed one version of this problem: a browser’s login state lives apart from the model’s conversation, and much of what a task depends on never appears on screen. This guide covers how agents keep track of work in general. How the context window works inside a model, and what a chatbot carries from one message to the next, belongs to How AI Works: see what AI remembers between messages.

TL;DR

  • Agent state is the working record of one task: goal, plan, completed steps, tool results, pending work and approvals [1, 6, 7].
  • The model does not hold it. Surrounding software stores state and feeds part of it back on each call [1, 3].
  • State is not the model’s training, its context window or its long-term memory [1, 2, 4].
  • Checkpoints save state so work can resume after a pause or a crash, but a saved conversation may not cover files the agent changed [4, 8].
  • It usually lives in several places: a conversation record, a structured object, data the model never sees, and notes or files [9, 3, 10, 11].
  • Most state problems are about selection: too much context weakens recall, and stored records can be lost, overwritten or corrupted [11, 12, 13].

What Does an Agent Keep Track Of?

Agent state covers whatever the agent needs to choose a sensible next step. The CoALA framework calls this working memory: recent inputs, knowledge produced by reasoning or retrieved from storage, and information carried over from the previous step, such as active goals [1]. In practice, that includes:

  • The goal and constraints: what was asked, plus any deadlines, budgets or rules.
  • The plan: the intended steps, covered in depth in how agents break a goal into smaller tasks.
  • Completed actions and their results: a Claude Agent SDK session records every tool call and tool result [8], and LangGraph’s state can also hold retrieved documents, uploaded files and generated artifacts [4].
  • Pending tasks: in Claude’s task tracking, each to-do moves from pending to in_progress to completed [7].
  • Pending approvals: in OpenAI’s Agents SDK, a run paused for a person’s sign-off records what it is waiting on so it can resume afterward [6].
  • Relevant memory: facts retrieved from longer-term storage because they matter to this task [1].

A hypothetical snapshot from the supplier task: three suppliers checked, prices recorded for those three, one page that failed to load, two suppliers and a retry still pending. None of it lives inside the model.

How Are Context, Memory, State and Checkpoints Different From the Model?

All five get called what an AI “knows” or “remembers,” but they differ in what they hold and for how long.

What it holdsHow long it lastsHow it changes
Model weightsKnowledge and skills learned in training [1]Until retrainingThrough fine-tuning, not ordinary use [1]
Context windowThe text the model is given on one call [2, 3]One callRebuilt for every call
Agent stateThe working record of one task [1, 4]One task or thread of work [4]Updated as each step finishes [4]
Long-term memoryFacts, preferences or lessons kept across tasks [4, 5]Across sessions [4, 5]Written and read on purpose [5]
CheckpointA saved copy of a thread’s state [4, 14]Stored so the thread can be resumed [4]Saved as the work progresses [4]

The distinction that matters most for agents is between state and the context window, because state can be bigger than what the model sees. The MemGPT research system separates “main context,” the prompt tokens the model can access during a call, from information held outside that window [2]. The context window is a view of the state, chosen for each call.

Long-term memory differs in reach. LangGraph keeps a task’s state as thread-scoped short-term memory and stores long-term memory, such as user preferences, separately so it can be shared across threads [4, 14]. A task can draw on that memory, but its state belongs to the job at hand.

Where Agent State Lives

State is usually spread across several places.

The conversation record. OpenAI’s Agents SDK sessions retrieve the stored history before each run and save the new items, including tool calls, afterward [10].

A structured state object. LangGraph describes state as a shared snapshot of the application, usually with a defined schema, that each step reads and updates [9].

Data the model never sees. OpenAI’s SDK provides a local context object that tools and code can read and write but that is not sent to the model [3].

Checkpoints. LangGraph saves a thread’s state to a database with a checkpointer so the thread can be picked up later, and keeps those checkpoints separate from long-term stores shared across threads [4, 14].

Notes and files. Anthropic describes structured note-taking, in which an agent writes notes outside its context window and reads them back later, such as a to-do list or a NOTES.md file [11]. Its memory tool works the same way across sessions: Claude requests file operations, and the developer’s application performs them on storage it controls [5].

Each place holds only part of the picture. Claude Agent SDK sessions save the conversation but not the changes the agent made to files, which need separate checkpointing [8]. Wherever the record lives, the people who deploy an agent decide what it stores and keeps, and they remain responsible for checking it.

How State Changes With Each Step

Each pass through the agent loop reads state, acts and writes the result back. In LangGraph, state is read at the start of each step and updated when the step completes [4]. The model then receives a selected view of that state.

Choosing that view is much of the engineering. Anthropic advises treating context as a finite resource with diminishing marginal returns [11]. Three common approaches:

  • Load on demand. Agents can hold lightweight references, such as file paths or web links, and pull the data into context only when needed [11]. MemGPT uses function calls to move information between the context window and external storage [2].
  • Summarize. Compaction condenses a conversation nearing the limit, but cutting too aggressively can lose details whose importance only becomes clear later [11].
  • Write it down. In one Anthropic coding experiment, a progress file and the project’s git history let each new session see where the work stood [12].

Written records matter more as work stretches out, because Anthropic describes each new session of a long run as starting with no memory of the last [12]. The next guide, how an AI agent can work on a task for hours or days, builds on these records with checkpoints, retries, budgets and stop conditions.

What Goes Wrong When State Breaks

State problems usually come down to the model being shown too much, too little or the wrong thing.

Too much. Anthropic reports that recall from the context window weakens as more tokens are added, a pattern it calls context rot [11]. LangChain’s documentation adds that a full history may not fit at all [4].

Early mistakes carried forward. A 2025 preprint by Philippe Laban and colleagues ran more than 200,000 simulated conversations with 15 models and found performance fell 39% on average when task details arrived over several turns rather than all at once [15]. Models that took a wrong turn tended not to recover, and restating everything gathered so far helped without closing the gap [15]. The study tested chat-style tasks, not tool-using agents.

Records overwritten. Anthropic found its model less likely to inappropriately change or overwrite a feature list stored as JSON, a structured data format, than one written in Markdown [12].

Corrupted memory. OWASP’s list of security risks for agentic applications, released in December 2025, includes memory and context poisoning, in which tampered memory shapes behavior long after the original interaction [13]. See prompt injection for how outside content manipulates agents.

How much written state agents need is still shifting. Anthropic’s engineering guidance recommends notes and to-do lists [11], yet its Agent SDK documentation, as of November 2026, says newer Claude models track multi-step work without a written to-do list [7]. No independent data was found on how often deployed agents fail because of state problems; for failures more broadly, see how AI agents can fail when they act.

Practical Takeaways

  • Ask where the record lives: a conversation history, a database, files or all three.
  • Check what a save covers. Restoring a conversation may not restore the files or systems the agent changed [8].
  • Prefer state you can inspect, such as to-do lists, progress notes and logs.
  • Restate key constraints on long tasks, since summaries and long histories can bury them [11, 15].
  • Review what an agent keeps across tasks. Stored memory can be wrong or tampered with [13].
  • Look at the record before blaming the model. Weights do not change in ordinary use, so losing track mid-task points to what was stored or trimmed [1].

Sources

  1. Cognitive Architectures for Language Agents. arXiv, 2024-03-15, accessed 2026-11-09.
  2. MemGPT: Towards LLMs as Operating Systems. arXiv, 2024-02-12, accessed 2026-11-09.
  3. Context management – OpenAI Agents SDK. OpenAI, accessed 2026-11-09.
  4. Memory overview – Docs by LangChain. LangChain, accessed 2026-11-09.
  5. Memory tool – Claude Platform Docs. Anthropic, accessed 2026-11-09.
  6. Human-in-the-loop – OpenAI Agents SDK. OpenAI, accessed 2026-11-09.
  7. Track todos – Claude Code Docs. Anthropic, accessed 2026-11-09.
  8. Work with sessions – Claude Code Docs. Anthropic, accessed 2026-11-09.
  9. Graph API overview – Docs by LangChain. LangChain, accessed 2026-11-09.
  10. Overview – OpenAI Agents SDK. OpenAI, accessed 2026-11-09.
  11. Effective context engineering for AI agents. Anthropic, 2025-09-29, accessed 2026-11-09.
  12. Effective harnesses for long-running agents. Anthropic, 2025-11-26, accessed 2026-11-09.
  13. OWASP Top 10 for Agentic Applications – The Benchmark for Agentic Security in the Age of Autonomous AI. OWASP Gen AI Security Project, 2025-12-09, accessed 2026-11-09.
  14. Persistence – Docs by LangChain. LangChain, accessed 2026-11-09.
  15. LLMs Get Lost In Multi-Turn Conversation. arXiv, 2025-05-09, accessed 2026-11-09.