Mahal Systems

Overview › 4Memory › b.Resuming › iii.

Keep plan, progress and results in files when work outlives one context window

State Planning

Also fits: 4Memory › a.Externalizing state

When a task spans context resets (compaction, a truncation limit, a new session), have the agent keep what the next window needs in files and read them back at the start of each window: the plan and a progress list, decisions and open items, intermediate results too large to hold in context, and for coding a structured test list and an init script. In measured studies, mostly of deep-research and long-horizon coding agents, state kept outside the history beat a growing or compacted one: Anthropic's memory tool plus context editing gained 39% on agentic search against 29% for context editing alone. The limits: model-written notes were incomplete or never read back, a stale file misled agents more than no file, and a stronger model needed resets less. Within one window this adds nothing a re-injected task list (7.b.iv) doesn't.

Tier 4 because it moves task state outside the context window.

When it applies

  • In the code: A plan or todo file, a progress log, a decisions and open-items file, and for coding a structured test list and an init script, kept outside the context window, plus a start-of-window step that reads them back.
  • In traces: Context resets followed by re-exploration or redone steps; notes written but never read back; user constraints or decisions violated after compaction; work declared done after a reset; state files older than the code they describe.
  • In eval results: Completion rate and redone work on tasks longer than one window, with a reset forced midway.
  • With probes: Tasks longer than one context window.

How

  1. Start from the harness as it is (compaction or truncation only) on tasks that really run past one window, and log what breaks after each reset: work redone, decisions or user constraints lost, work declared done too early.
  2. In the first window, before real work, have the agent create the state files: a structured list of features or tests (JSON, every item failing, with an instruction that items are never removed or rewritten, only marked passing), a free-text progress log, a decisions and open-items file that also holds the user's constraints, and for coding an init script that starts the app and runs a smoke test; commit them to git.
  3. Write large intermediate results (sources, query results, documents, logs) to files and keep only the path and a one-line note in context.
  4. Start every later window with a fixed resume step written into the prompt: read the progress log, the decisions file, the test list and the git log, run the init script and the smoke test, then take one open item. Do not leave reading optional; agents write notes they never read.
  5. Update at fixed points: when an item passes an end-to-end check, mark it, append to the log and commit; before a reset, write the handoff. Rewrite the files in place so they describe the present and delete stale entries, because agents follow a written file over the code.
  6. Keep harness-side safety nets instead of relying on model-written notes alone: keep compaction or the harness's own state capture, re-append the constraint list after every compaction, and choose a fresh window or compaction per model.
  7. Measure with paired runs that force a reset midway, with and without the files and the resume step: completion, steps redone, constraint violations after the reset, tokens and wall time, per model; re-run after a model change.

How to measure it

  • experiment (tier 4): paired runs on tasks longer than one window, forcing a reset (or capping the window) midway: the harness as is against the same harness with state files and a fixed resume step; completion, steps redone after the reset, constraint violations after the reset, tokens and wall time, per model; re-run after a model change
  • monitor: per reset: whether the first actions read the state files, steps redone, items marked done that fail their test, state files older than the code or plan they describe, and the share of tokens spent writing notes

To compare the change against your agent's current version, with the same cases and enough repeats to see past run-to-run noise, use aot-evals.

Expected impact

  • Quality: improves, medium: tasks past one window: memory tool plus context editing +39% against +29% for context editing alone (Anthropic, Sep 2025); a report rewritten into each rebuilt context +12.7 (o3) and +19.2 (DeepSeek-V3.1) points on BrowseComp over ReAct (Chen, Nov 2025); without todo, checklist and log files 52.76 to 48.69 RACE on 10 queries (Zhu, Feb 2026); model-written notes alone degraded Devin (Cognition, Sep 2025); a stale convention file cut better-form decisions from 33% with no file to 0% (Mohammadi, Aug 2026)
  • Cost: mixed, small: file I/O under 0.03% of wall time (Zhu, Feb 2026); resets add token overhead (Rajasekaran, Mar 2026); an agent sometimes spent more tokens writing summaries than solving the problem (Cognition, Sep 2025); no study reports tokens for the files alone
  • Performance: mixed, small: with a state-recovery memory, minutes per DeepSWE task rose from 42.0 to 54.2 under one harness and fell from 103.8 to 75.3 under another (Xu, Oct 2026); resets add latency (Rajasekaran, Mar 2026)
  • Security: none (unmeasured)
  • Governance: improves, small (unmeasured)
  • Brand: none (unmeasured)

Caveats

Most measured gains come from deep-research and long-horizon coding systems built around their authors' own memory design, often on one model and small samples (one ablation used 10 queries, another does not state its run count), and no controlled study isolates a plain progress file under a forced reset. Model-written notes are not free memory: Cognition found them incomplete, Vending-Bench agents wrote notes they never read, and a stale written standard led agents to the worse form on every contested decision, so read-back and upkeep must be enforced. The need depends on the model: Anthropic needed resets with handoff files for Sonnet 4.5 but dropped them for Opus 4.5, so measure per model and again after an upgrade.

Evidence

Evidence comes from: Web research, Code generation, Document extraction, Tool use, Conversation, Planning.

  1. Write plan to file and re-read it periodicallyNot measured

    "Some agents write a plan to a file and read it back into context periodically to reinforce objectives and / or verify its work."

    Lance Martin, "Agent Design Patterns" · Jan 2026 · Offload Context

  2. Save the plan to external memory before truncationNot measured

    "saving its plan to Memory to persist the context, since if the context window exceeds 200,000 tokens it will be truncated and it is important to retain the plan."

    Jeremy Hadfield, Barry Zhang, Kenneth Lien, Florian Scholz, Jeremy Fox, Daniel Ford (Anthropic), "How we built our multi-agent research system" · Jun 2025Older evidence · Architecture overview (process diagram caption); Appendix: Long-horizon conversation management

  3. Lists this practice in its agent-optimization pattern library (Long-Horizon group)Not measured

    Names the practice as a known agent optimization; reports no measured effect for it.

    Scale AI, "VeRO: A Harness for Agents to Optimize Agents" (ICML 2026) · Feb 2026 · paper Table 6; pattern library file master-agent-optimization-cookbook.md

  4. Keep a progress file and git history so a fresh context window can pick up the workNot measured

    "The key insight here was finding a way for agents to quickly understand the state of work when starting with a fresh context window, which is accomplished with the claude-progress.txt file alongside the git history."

    Justin Young (Anthropic), "Effective harnesses for long-running agents" · Nov 2025 · The long-running agent problem

  5. Give the agent a file-based memory tool (create, read, update and delete files in a memory directory) alongside context editing that clears stale tool results

    "combining the memory tool with context editing improved performance by 39% over baseline. Context editing alone delivered a 29% improvement." The 84% token reduction in the same post is for context editing alone, on a 100-turn web search evaluation.

    Anthropic, "Managing context on the Claude Developer Platform" · Sep 2025Older evidence · Performance improvements with context management

  6. Each round, rebuild the context from the question, an evolving report the agent rewrites as its memory, and only the last action and its result, instead of one growing history

    As a prompting strategy with no training, it beat ReAct on BrowseComp by 12.7 points with o3 and 19.2 with DeepSeek-V3.1. With identical training data, the iterative agent averaged 49.1 against 36.5 for a single-context agent across six benchmarks (+12.6), although the single-context agent had a 64K window against 40K.

    Guoxin Chen, Zile Qiao, Xuanzhong Chen, Donglei Yu, Haotian Xu, Wayne Xin Zhao, Ruihua Song, Wenbiao Yin, et al., "IterResearch: Rethinking Long-Horizon Agents with Interaction Scaling" · Nov 2025 · Abstract; §4.3 Table 2; §4.5 Figure 4

  7. Keep task state in files and rebuild each step's context from a workspace snapshot plus a fixed window of recent actions; ablate by replacing the file state with compressed long-context prompts

    Average coverage on an 80-paper literature review: 67.1 (GPT-OSS-20B), 80.0 (Gemini-3-Flash) and 80.0 (Claude-4.5-Sonnet) with file-centric state; 3.2, 21.1 and 27.7 with "No File State (Compressed Context)". Claude Code with Claude-4.5-Sonnet averaged 29.1. The authors note latency overhead, and that wrong information a sub-agent writes to the files can propagate.

    Chenglin Yu, Yuchen Wang, Songmiao Wang, Hongxia Yang, Ming Li, "InfiAgent: An Infinite-Horizon Framework for General-Purpose Autonomous Agents" · Jan 2026 · §5.2 Table 1 and Ablation analysis; §7 Limitations

  8. Deep research over several sessions on a file workspace: a todo file with a status per item, a fixed checklist and a log read at each session start, plus a knowledge base of notes and archived sources; ablate by removing the control files and replacing the structured workspace with a flat note

    Removing the persistent workspace dropped RACE from 52.76 to 48.69, with Insight -7.95 and Comprehensiveness -3.58. File I/O took under 0.03% of wall-clock time.

    Chiwei Zhu, Benfeng Xu, Mingxuan Du, Shaohan Wang, Xiaorui Wang, Zhendong Mao, Yongdong Zhang, "FS-Researcher: Test-Time Scaling for Long-Horizon Research Tasks with File-System-Based Agents" · Feb 2026 · §3 (control files); §4.2 Table 5; Appendix M Table 15

  9. Store execution history outside the window as traces anchored to files, symbols and tests; after a context refresh, rebuild what is done and what remains from them and check stored evidence against the current repository before reuse

    Against each harness's native context management: under Codex CLI, DeepSWE pass@1 35.4 to 56.6, SWE-EVO resolved 47.8 to 69.6, SWE-Milestone score 28.6 to 46.4; under mini-swe-agent, DeepSWE 48.7 to 66.4. A flat trace store without the structure scored 32.1 on DeepSWE, below native. 57.0% of 9,226 file-bound traces saw a later change to a bound file. Mean minutes per DeepSWE task: 42.02 to 54.17 under Codex CLI, 103.77 to 75.30 under mini-swe-agent.

    Hongming Xu, Le Zhou, ZhongHe Jin, Xiang Zhang, Bo Tang, Zhiyu Li, Xuanhe Zhou, Juncheng Zhang, "MemTrace: State-Consistent Memory for Long-Horizon Coding Agents" · Oct 2026 · Abstract; Table 2; Table 3; §4.3 State–memory alignment; Appendix A.2 Table 6

  10. Keep user-issued constraints in a registry outside the summary and append it after every compaction, against compaction alone

    Compactors retained 17% of injected constraints on average; in an inbox test the agent deleted emails without approval in 30/100 sessions after compaction, against none before. The registry kept 90.3%, 93.7% and 95.1% of constraints (WildChat, Hermes Agent, OpenResearcher), and appending it raised compliance by 39.5-42.6 percentage points.

    Zhiqi Wang, Yichi Zhang, Dongwon Lee, Nathalie Baracaldo, Yuchen Yang, "Lost in Context Compaction: When LLM Systems Drop Side Constraints" · Jul 2026 · Abstract; §2; §5.1; §5.4 Table 4

  11. The agent keeps its task state in an external knowledge graph that its tool calls (web, Python, file readers) keep extending and that it queries (Cypher, SPARQL or Python) to answer, instead of holding that state in contextMixed

    GAIA validation, GPT-4o mini, tasks solved of 165: single knowledge-graph variants 36 to 44, "between 42% to 62% lower costs", against 30 and 33 for the same pipeline without the graph ("No KG") and 35 for Hugging Face Agents. A fusion of all graph variants solved 71, against 40 for the no-graph fusion. Open models (Neo4j + Cypher variant): DeepSeek-R1-7B solved 13 zero-shot but 6 with the graph, R1-32B 14 against 21, R1-70B 20 against 22.

    Maciej Besta et al., "Affordable AI Assistants with Knowledge Graph of Thoughts" · Apr 2025Older evidence · §5.1; §5.3; §5.6; Appendix Table 2 (GAIA, per model)

  12. Long-running agent with only the last 30,000 tokens in context plus a scratchpad, key-value store and vector database it can read and writeMixed

    All models had runs that derailed. Claude 3.5 Sonnet wrote a long daily summary to the scratchpad "but never retrieves the information." Memory-tool use did not differ significantly between 10k, 30k and 60k token windows, and the larger windows did worse. The Pearson correlation between days until sales stop and days until memory is full was 0.167; "the breakdowns are not directly related to the context of the LLMs being filled".

    Axel Backlund, Lukas Petersson, "Vending-Bench: A Benchmark for Long-Term Coherence of Autonomous Agents" · Feb 2025Older evidence · §2.1; §3.2.2; §3.5.2 Figures 12-13; §3.6 Table 9

  13. Give a coding agent a written standard file that agrees with the code, no standard, or a stale standard that demands the worse formMixed

    Share of contested decisions written the better way: 100% with a correct standard, 33% with no standard, 0% with a stale one; "Deleting an out-of-date convention file beats leaving it in place." Where a written standard and working code disagreed, agents followed the standard in every one of 39 trials.

    Bardia Mohammadi, Lars Klein, Aman Chadha, Akhil Arora, Laurent Bindschaedler, "The Working Set of a Coding Agent: Coherence Debt in Repository-Scale Tasks" · Aug 2026 · §4.8; §4.9; Appendix N

  14. Let the model's own notes (CHANGELOG.md, SUMMARY.md) replace the harness's compaction and summarizationMixedNot measured

    "we found the summaries weren't comprehensive enough. For example, it would sometimes paraphrase the task, leaving out important details. When we relied on the model's own notes without our compacting and summarization systems, we saw performance degradation and gaps in specific knowledge". Also "we've seen the agent spend more tokens writing summaries than actually solving the problem." The behavior was "useful in certain cases, but less effective than our existing memory systems".

    The Cognition Team, "Rebuilding Devin for Claude Sonnet 4.5: Lessons and Challenges" · Sep 2025Older evidence · The model takes a lot of notes

  15. Context resets with a structured handoff between sessions, against one continuous session with automatic compactionMixedNot measured

    With Claude Sonnet 4.5, "compaction alone wasn't sufficient to enable strong long task performance, so context resets became essential", at the cost of "orchestration complexity, token overhead, and latency". "Opus 4.5 largely removed that behavior on its own, so I was able to drop context resets from this harness entirely"; it ran one session with automatic compaction, and its agents still handed work to each other through files.

    Prithvi Rajasekaran (Anthropic), "Harness design for long-running application development" · Mar 2026 · Why naive implementations fall short; The architecture

Also known as

  • Structured note-taking
  • File system as external memory
  • Proactive state externalization

Related

In Claude Code

This optimization is a skill in aot-kit, our open-source Claude Code plugin: /aot-kit:multi-window-task-state. Its library entry holds every source. Have new evidence, or a correction? Suggest a change.

Before you go...

Build better agents, weekly

Our latest research, performance benchmarks, optimization strategies, and updates around AOT development.

One email a week, nothing else. Unsubscribe anytime.