All articles

AI Agent Memory: Why Context Windows Aren’t Enough

How AI agent memory differs from context windows and RAG, with a token-cost model and proposed tests for reliable project continuity.

Working context is a temporary selection. Durable records and verified state remain independent of the model.

AI Agent Memory: Why Context Windows Aren’t Enough

We don't expect a processor to replace a database. Why should an LLM replace a memory system?

In my work on OSIX, Agent-Diary and CrazySkills, I want an agent to resume a project from durable records. The context window is its working input, not the source of truth.

Drag the figure to separate the blue knowledge records and green operational records from the amber working set. The violet model receives only the selected information.

View on X · Andrej Karpathy on choosing the information a model needs for its next step

01 / Why a million-token context window is not enough

On December 2, 2026, Lydia Hallie announced Claude Code’s earlier default compaction setting. The official documentation describes a 400K setting for current native 1M models, with exceptions. On this setting, compaction begins around 367K tokens. The full window is available with /autocompact 1m.

View on X · Lydia Hallie’s Claude Code auto-compaction announcement, December 2, 2026
Documented capacity and compactionFor Claude Code native 1M models using the 400K auto setting; exceptions apply. Source: Claude Code model configuration.
  • Tokens

Unit · tokens

View chart data
Documented capacity and compaction (tokens)
CategoryTokens
1. Capacity1,000,000
2. Configured window400,000
3. Compaction ≈367,000

I need large context windows to investigate complex bugs. But a summary can discard the constraint I need three days later. Lost in the Middle found that information retrieval performance varied with its position in the tested models’ inputs. I would test that separately on current models.

02 / Working context, RAG, durable memory and state

Working context holds the instructions and evidence for the current model request. Retrieval-augmented generation (RAG) selects material from canonical sources. Durable memory retains decisions and reviewed lessons between sessions. Operational state holds the current task and its acceptance evidence. Explicit approvals govern updates.

Durable recordsGoverned stateSources / decisionsApprovals / evidenceWorking contextModelTools / actionsValidation
The model receives selected context. Only validated transitions update governed state. Proposed architecture.

MemGPT explored hierarchical memory in 2023. My concern is also authority. A similarity score tells me which record might be relevant, not whether it is current or approved. A proposed change stays separate from verified state until the workflow accepts it.

03 / Context growth and inference token costs

Take 20 requests. The first carries 20,000 input tokens (B), each subsequent request adds 5,000 (Δ), and a hypothetical bounded context carries 30,000 (W) each time. Let n be the number of requests. The two formulas give the cumulative input, without compaction in the growing case.

Th(n)=nB+Δn(n−1)2Tb(n)=nW\begin{aligned}T_h(n)&=nB+\frac{\Delta n(n-1)}{2}\\T_b(n)&=nW\end{aligned}\begin{aligned}T_h(n)&=nB+\frac{\Delta n(n-1)}{2}\\T_b(n)&=nW\end{aligned}
Cumulative input for growing history and bounded context.

The cumulative totals meet at request 5. At request 20, growing history has consumed 1.35 million logical input tokens, compared with 600,000 for bounded context. That is a difference of 750,000 tokens (55.6%).

Cumulative logical input tokensIllustrative calculation. At 20 requests: 600K versus 1.35M. Neither an OSIX benchmark nor a billing estimate.
  • Bounded context
  • Growing history

Unit · tokens

View chart data
Cumulative logical input tokens (tokens)
CategoryBounded contextGrowing history
1. 000
2. 260,00045,000
3. 4120,000110,000
4. 6180,000195,000
5. 8240,000300,000
6. 10300,000425,000
7. 12360,000570,000
8. 14420,000735,000
9. 16480,000920,000
10. 18540,0001,125,000
11. 20600,0001,350,000
1−600 0001 350 000≈55.6%1-\frac{600\,000}{1\,350\,000}\approx 55.6\%1-\frac{600\,000}{1\,350\,000}\approx 55.6\%
Illustrative input reduction over 20 requests.

This is arithmetic, not an OSIX benchmark. Caching changes actual billing. Retrieval and summarization add overhead. The smaller input must still support the same task quality before I can call it a useful optimization.

04 / Cost per verified task

Input tokens alone tell me little about the cost of finishing a project. I want to count the work that passes acceptance, including failed attempts.

Ctotal=Cinference+Cretrieval+Cmemory+CreviewC_{\mathrm{total}}=C_{\mathrm{inference}}+C_{\mathrm{retrieval}}+C_{\mathrm{memory}}+C_{\mathrm{review}}C_{\mathrm{total}}=C_{\mathrm{inference}}+C_{\mathrm{retrieval}}+C_{\mathrm{memory}}+C_{\mathrm{review}}
Include all four costs in the comparison.
Caccepted=CtotalNacceptedC_{\mathrm{accepted}}=\frac{C_{\mathrm{total}}}{N_{\mathrm{accepted}}}C_{\mathrm{accepted}}=\frac{C_{\mathrm{total}}}{N_{\mathrm{accepted}}}
Cost per accepted task, not just per prompt.

Use the same acceptance tests in both configurations. Record cache usage and human review time. If converting time to money, declare the rate. If nothing passes, report failure instead of dividing by zero.

If a memory layer costs more than the rediscovery it prevents, it is not an optimization.

05 / AI agent learning across sessions

I started Agent-Diary as an experiment for OSIX. I have seen the diary persist across sessions. It records introspection and changes over time.

Suppose an agent mistakes a preview for a deployment. On the next task, it should look for deployment evidence before claiming success. Retrieving the lesson is only the first step; the acceptance test is whether its next relevant action changes.

Observed failureVerifiable observationReviewed lessonScope and provenanceDurable memoryRetrieved at resumptionChanged actionBehavioral test
A useful lesson changes what the agent does next. Proposed test sequence.

Applying lessons at initialization and during work remains an experiment I want to test. I am not claiming autonomous coordination already works. Lessons must remain correctable.

06 / Why a green preview is not a verified release

In my CrazySkills PostgreSQL release work, a successful preview or SQL readback is not proof of public activation. The desired path starts with a fresh installation and approved population, then guarded activation, real write/read and verification after restart.

Fresh installationApproved populationGuarded activationApproval and evidenceWrite / readVerify the resultRestartRepeat the checks
Proposed acceptance path, not a report of a completed release.

Spec Kit gives development a structure. Anthropic’s long-running agent harness research uses artifacts to carry work across sessions. CrazySkills is where I want to make the transition rules explicit.

I have not established that this entire release sequence has passed.

07 / Local-first AI memory and data ownership

OSIX is under development. The direction is local-first retrieval and memory, portable knowledge, user-selected models and predictable inference costs. Local storage does not guarantee local inference. Sending data to a cloud model must be explicit.

Agent-Diary explores continuity and learning. CrazySkills addresses delivery verification. The planned Code OSIX workspace addresses coding-agent jobs across the user's own machines. Full integration is planned.

Anthropic’s context-engineering article asks what should go into a request. I also want to decide what survives that request and who can change it.

08 / Measuring agent memory and task resumption

Interrupt a task. Start a fresh session with another supported model and ask it to resume from the last verified result without replaying the conversation. Compare a conversation-only baseline against retrieval plus durable memory on identical tasks. Count a resumption as correct only when the agent recovers the applicable decision and outstanding work.

R=NcorrectNattemptedR=\frac{N_{\mathrm{correct}}}{N_{\mathrm{attempted}}}R=\frac{N_{\mathrm{correct}}}{N_{\mathrm{attempted}}}
Resumption accuracy.

Introduce a contradictory decision and attempt an unauthorized approval. Inspect the sources and revision selected by the agent. Record missed constraints and human interventions. Calculate repeated errors against relevant opportunities rather than all messages. These are proposed measures, not results.

E=Nrepeated errorsNopportunitiesE=\frac{N_{\mathrm{repeated\ errors}}}{N_{\mathrm{opportunities}}}E=\frac{N_{\mathrm{repeated\ errors}}}{N_{\mathrm{opportunities}}}
Repeated-error rate.

References and reading

09 / Context window ≠ memory

I still want bigger context windows. I just don't want the continuity of my work to depend on them.

Context ≠ memoryDurable memorySources / decisionsVerified stateApprovals / evidenceWorking contextModelActions then validationCost per accepted taskContext is reconstructed.Records remain independent.
Rebuild context from independent records. Verify state transitions and measure the cost of accepted work. Conceptual architecture.

Share this article