2026 Agent Wrapped is here! Check out yours
All articles

What Is Agent State? Eight Layers, From Context to Audit Logs

Agent state is any information or effect able to change what agents do next. Eight layers, how each one breaks, and one check per crossing.

Arnav Gupta

December 4, 2026 · 8 min read

Line diagram: a stack of eight state layers feeds a model that keeps nothing between calls, the model acts through tools, and tools change state.

While drafting this post, our coding agent opened one of its own saved memories. It said our blog images should look like lavender sticky notes. We wrote it 65 days earlier. But our request came with another reference attached, grey machines on white, so our agent followed this newer one. Later we changed our minds again and asked for line diagrams.

It had to decide which piece of state still counted. Agents make some version of this call all day.

Language models keep no memory between API calls. Whoever builds on them has to store everything else: messages so far, plans, files, keys. All of it together is agent state.

Short answer

Agent state is any information or effect able to change what agents do next. Frameworks often use this term for something narrower, such as one conversation’s saved variables. We count eight layers.

LayerWhat it holdsHow long it lastsHow it breaks
Contextmessages, tool resultsone session, less after compactiondetails drop out
Instructionssystem prompt, rule files, hooksuntil editedtwo rules disagree
Working stateplan, scratch files, subagent reportsone taskplan drifts from reality
Memorynotes kept across sessionsuntil deletedstale or planted entries
Environmentfiles, shell, browser tabsas long as its machinesomeone else changes it
Identitytokens, cookies, scopesuntil expiry or revocationaccess outlives its task
Side effectscommits, emails, paymentsoften permanentretries repeat them
Recordtranscripts, audit logsset by retention policygaps or leaked secrets
eight layers and how they feed each other

1. Context

Context is whatever Claude, GPT or Gemini can read on its current turn. User messages go in, along with model replies and tool results.

Filling it has costs. Anthropic describes context rot: as token count grows, models recall less of what they were given.

Compaction buys room by swapping older turns for one summary. Anthropic says Claude Code keeps architectural decisions and unresolved bugs, drops redundant tool output, then carries on with its summary plus five recently accessed files. Details can still go missing. One line saying "leave this table alone" may look minor to whichever model writes our summary and matter plenty one hour later.

Exact values belong in files, where agents can reopen them.

2. Instructions

System prompts and files like CLAUDE.md or AGENTS.md tell agents how to behave. Hooks and skills add more. We count them as state because teammates edit them mid-project, and behavior changes with each edit.

Two rules can also disagree. We tested this on three coding agents. Claude Code and Codex followed chat over their agent file. Antigravity followed its file over chat in 12 of 12 runs.

Keeping each rule in one place avoids most of this. Code review helps too. For edits made outside review, Prismor’s memory integrity check compares each instruction file with its last trusted version and flags cases where agents changed their own rules.

3. Working state

Working state covers progress on one job: its plan, finished steps and half-edited files.

Long jobs outlast one context window, so agents need notes they can pick up cold. In Anthropic’s long-running agent setup, each session starts by reading git logs, one progress file and one JSON feature list. For their claude.ai clone, this list held over 200 features, all marked failing at first. Coding agents could change only its passes field. Anthropic built this after watching later sessions look around, see progress and declare victory early.

Subagents add another gap. Anthropic says one may spend tens of thousands of tokens exploring, then return 1,000 to 2,000 tokens of summary. Its parent sees only this summary. "Tests pass" and "tests pass, six skipped" lead to different next steps, so we check reports against diffs. Teams can also cap how many subagents one agent launches.

4. Memory

Memory is what survives once sessions end. LangGraph draws this line in its API: checkpointers save state for one thread, while stores hold data shared across threads.

Our own setup is plain. We keep small markdown files with one fact each, plus one index our agent loads at start. We also log each task with three fields: goal, method and what is still missing. Our third field earns its keep, because next week’s session can see which work is unfinished.

Memories go stale. Servers move and preferences change, as ours did with sticky notes. Dates and reasons help agents judge whether old entries still apply.

Attackers can write memories too. Researchers behind MINJA planted bad records in shared agent memory through ordinary queries, with no direct access to its database. They report 98.2% average success at injecting records and 76.8% at causing their intended harm. Those are lab numbers. One January 2026 follow-up on medical-record agents found these attacks far less effective once memory held legitimate entries. OWASP lists memory and context poisoning as ASI06 in its agentic top 10. It recommends scanning new writes and expiring unverified ones. We walk through these attacks and their controls in our post on agent memory security.

5. Environment

Agents act on git branches, running processes and database rows they don’t control. Another session may switch branches while one agent is still thinking. Someone may force-push overnight.

Resumed agents hold yesterday’s picture of all this. Running git status before each commit costs almost nothing, and it catches plenty.

6. Identity and credentials

API keys, OAuth grants and signed-in browsers set what agents can reach. Many setups keep them in environment variables or config files.

Access often outlasts its reason. Say someone issues one database token for Tuesday’s migration. Unless it expires, any process able to read it can still use it on Friday.

We prefer short-lived credentials with narrow scopes. Delegation between agents adds its own gaps, which we cover in why agent identity needs more than OAuth. We also keep real values out of context. Our agents write placeholders such as @@SECRET:name@@, and one hook swaps in each real value as its command runs, then scrubs it from captured output. We call this hook Cloak, and it is open source.

7. Side effects

Sent emails and charged cards sit outside any agent’s undo button. Even local undo has limits. Claude Code can rewind its own file edits, but its docs say files changed only by Bash commands aren’t tracked.

Crashes make this worse. Temporal’s docs describe one such case: some worker finishes its job, then dies before reporting back. Temporal sees no completion and retries. If this job was one payment, its customer may pay twice.

LangGraph has its own version. Paused nodes restart from their first line on resume, so any email sent before pausing can go out again.

Idempotency keys fix this where services support them. Stripe, for example, returns its saved result when requests repeat with identical keys. Its v1 API may prune keys after 24 hours, so agents resuming two days later need another check. Elsewhere, agents can look for existing results before writing. For actions with no undo, human approval can hold one call until someone decides.

8. Record

Transcripts and audit logs show who asked for what, and what happened next. Incident reviewers depend on them. So does any agent resuming old work. Prismor keeps one hash-chained audit trail of tool calls, so later edits to it show up.

Logs carry risk of their own. One printed secret can sit in some transcript for months, and later sessions may read it back in. We redact at each tool call for this reason.

Saving, resuming and letting go

one task saved, resumed after one crash, forked, handed off and expired

Teams need answers for each of these moments:

  • Save: write progress after each step, since crashes skip end-of-session cleanup
  • Resume: reload notes, then recheck branch, files and permissions
  • Fork: give each copy its own worktree when both will edit code
  • Hand off: pass along goal, finished work, open work and evidence
  • Expire: delete stale memories and revoke old tokens

Expiry is easy to put off. Old tokens cause no visible trouble until someone misuses one.

Reading this as attackers would

attack path from web page to email, with one check at each crossing

Picture one poisoned web page. Our agent reads it, so its text enters context. If our agent saves it as one of its notes, it returns tomorrow looking like something we wrote. From there it can steer whatever credentials our agent holds, and send email or push code.

Each step crosses from one layer into another, and each crossing is somewhere to put one check:

  • Treat web pages and tool results as data, with no authority to give orders
  • Review writes to memory and rule files as carefully as code
  • Keep secret values out of context
  • Check risky tool calls in code before they run

We build Prismor for these checks, and it sits in each tool call’s path. Models weigh written rules against each other, as our conflict tests showed. Code can refuse calls outright.

Try it on one agent

Pick one agent in production and copy our table. For each layer, write down where it is stored, who can write to it and when it gets deleted. I’d start with memory and identity, since those two carry most risk from one session into another.

Written by Arnav Gupta

Keep reading