concepts

What agent state is (and what it is not)

Agent state is the durable, writable knowledge an agent carries between runs: facts, decisions, learnings, and work in progress.

Definition

The agent reads state to orient itself at the start of a task. The agent writes state to preserve what it discovers. State survives session restarts. It belongs to the agent, not to the runtime.

Example: an agent finishes a deploy and writes the outcome to modules/deploy/log.md. Next session, the agent reads that log before it acts. The file is the state. The write is what makes it state.

modules/deploy/log.md
## 2026-08-22: deploy to staging
Outcome: success
Duration: 4m 12s
Rollback: git revert abc1234
## 2026-08-21: migrate user table
Outcome: success
Migration: 0042_add_email_verified
Note: took 90s on 2M rows, lock held

What state is not

Not chat history

Chat history is a transcript. State is the distilled result. Replaying full conversations costs tokens and carries noise. State replaces thousands of tokens with a few lines of knowledge.

Not RAG

RAG retrieves from a corpus the agent does not own. State is owned and mutated by the agent itself. RAG answers "what do we know?" State answers "what have I learned?"

Not configuration

Configuration is human-authored input (CLAUDE.md, cursor rules). State accumulates from work. The difference: who writes it. A human writes config. The agent writes state.

Properties good state needs

Durable
Survives session restarts
Writable
The agent creates and updates it
Inspectable
Open and read it in any editor
Portable
Move to another machine or tool
Scoped
Load only what the task needs

Comparison

Chat historyRAG corpusConfigurationAgent state
OwnerRuntimePipelineHumanAgent
Write pathAutomaticPipelineHuman editAgent tool call
LifetimeSessionIndefiniteUntil changedBetween runs
GranularityMessageDocumentFileTopic
CorrectionNot correctableRe-indexEdit fileEdit file or self-correct

State management patterns

Entry-point routing. Each topic gets a folder with an index.md that routes to sub-files. The agent reads the index first.

Append-then-distill. Write raw observations during work. Periodically summarize into a shorter file.

Decision logs. Append-only record of choices and reasons. The agent checks before repeating a decision.

Run scratchpads. Per-task workspace. Promote durable findings when the task finishes.

folder layout
modules/
deploy/
index.md entry point
log.md append-only decisions
runs/
2026-08-22.md scratchpad (promoted)
onboarding/
index.md entry point
learnings.md distilled knowledge

gcontext: state as a folder over MCP

gcontext serves a folder of plain text files as agent state over MCP. Three top-level directories: connections/ for services, modules/ for knowledge, agents/ for installed agents.

The agent reads and writes through MCP tools. Any MCP client works: Claude Code, Cursor, Codex.

install and start
$ uv tool install gcontext-ai
$ gcontext init my-agent
$ gcontext up my-agent

Questions

What is agent state management?

The practice of giving an AI agent durable, writable storage that it reads at the start of each task and writes to as it works. Good state management keeps that storage inspectable, portable, and scoped to what the current task needs.

Is agent memory the same as agent state?

"Memory" emphasizes recall. "State" emphasizes that the agent both reads and writes it. In practice they describe the same thing: persistent knowledge the agent maintains across sessions.

Where should agent state be stored?

Files for most use cases. A database when you need structured queries. Vector storage when you need fuzzy recall over large corpora. Plain files give you the best inspectability and version control with the least infrastructure.

Related

AI agent memory
Four approaches to persistent agent memory compared
Claude Code memory
What persists across sessions in Claude Code
Stateful MCP servers
The pattern behind gcontext
LangGraph memory
Checkpointers, Store, and the file layer
CLAUDE.md limits
Why agent memory should not live in one file
State management for your agent

Install gcontext. A folder of plain files, served over MCP, readable and writable by the agent.

View on GitHubCompare memory approaches