Delete What It Already Read

A ReAct agent does not pay once for the context it reads, it pays again on every later turn, because the standard loop re-sends the full trajectory. That trajectory goes out unmodified as input tokens on every call. Modeling a 30-turn agent session shows the share of input tokens spent re-billing prior turns grows from 0% at turn 1 to 82% by turn 20, independent of task complexity. A 2026 paper accepted at FSE, AgentDiet, shows this is fixable at inference time by pruning stale and superseded trajectory content: 39.9-59.7% fewer input tokens, 21.1-35.9% lower cost, no measured drop in task performance. This post builds an illustrative cost, latency, and quality model around that finding and compares it to the default fix: swapping to a cheaper model.

Published 2026-08-10 by Dor Amir on the Nadir blog.

Filed under Context & Compression.

Abstract.

A ReAct agent does not pay once for each piece of information it reads. It pays again on every subsequent turn, because the standard agent loop re-sends the full conversation history, unmodified, as input tokens on every API call. This post models that mechanism directly: in an uncompacted 30-turn agent session, the share of input tokens spent re-billing prior turns grows from 0% at turn 1 to 82% by turn 20, even though the task itself has not gotten more complex. We call this the trajectory tax. A 2026 systems paper (AgentDiet, accepted at FSE 2026) shows this is fixable at inference time, without retraining or a smaller model, by pruning stale and superseded context from the trajectory before it is re-sent: 39.9-59.7% fewer input tokens, 21.1-35.9% lower total cost, no measured drop in task performance. This analysis builds an illustrative cost, latency, and quality model around that finding, stacks it against output compaction and prompt caching, and compares it to the default cost-cutting move: swapping to a cheaper model. The practical takeaway is that trajectory-level filtering and model routing solve different problems and are not substitutes for each other.

All charts and the 30-turn session model in this post use illustrative, synthetic data, built from public research and Anthropic's published pricing as of August 2026. They are not derived from proprietary production traces. Reduction rates are anchored to the ranges reported in the cited papers; the specific dollar and latency figures are a modeled scenario, not a benchmark result. Sources cited throughout.

The mechanism nobody names.

Most cost-optimization advice for agentic AI starts with the model: use a cheaper one, route between several, cascade from small to large. That advice is correct as far as it goes, but it treats the input to each call as fixed and only asks which model should read it. It skips a prior question: why is the input that large in the first place.

A ReAct agent (reason, act, observe, repeat) does not process a task once. It reconstructs the entire trajectory on every turn: system prompt, tool schemas, every prior tool call and its raw output, every intermediate plan the agent wrote and later abandoned, and whatever it retrieved along the way. None of that is optional context the agent could choose to skip. It is billed as input tokens on every single call, whether or not the model still needs it.

Xiao, Gao, Peng, and Xiong, "Reducing Cost of LLM Agents with Trajectory Reduction," arXiv:2509.23586, accepted at FSE 2026 name this directly: agent trajectories accumulate "useless, redundant, and expired information," and their method, AgentDiet, removes it at inference time. Across two LLMs and two benchmarks, AgentDiet cuts input tokens 39.9-59.7% and total computational cost 21.1-35.9%, while holding agent task performance at the same level as the uncompacted baseline. That last part is the finding that matters: the tokens being removed were not contributing to the answer.

Research question.

In a multi-turn ReAct agent session, how does the share of input tokens spent re-billing already-read context grow as the session gets longer, and what happens to cost, latency, and quality when that context is pruned rather than left to accumulate?

Modeling a 30-turn session.

To make the mechanism concrete, we modeled a single agent session against a fixed task profile, held constant across every turn, so the only variable is how much prior context each call carries:

Chart 1: Carried history dominates the bill as a session gets longer. In an illustrative uncompacted ReAct session, the share of input tokens spent re-sending prior turns grows from 0% at turn 1 to 82% by turn 20 and 86% by turn 30.
Chart 1: Carried history dominates the bill as a session gets longer. In an illustrative uncompacted ReAct session, the share of input tokens spent re-sending prior turns grows from 0% at turn 1 to 82% by turn 20 and 86% by turn 30.

At turn 1, the entire input is static overhead and the first turn's content: no history to carry yet. By turn 10, carried history is already 65% of the 8,950-token input. By turn 20, it is 82%. By turn 30, 86% of the 21,950-token input is context the model already read on a prior turn. The task did not get harder. The bill got heavier because the loop never stops re-billing its own past.

This is a different failure mode than the one usually described in "agents are expensive" posts. It is not about over-retrieval or verbose tool schemas in isolation (both real, both covered below); it is about the trajectory itself compounding, turn over turn, independent of task complexity.

Cost: trajectory reduction and output compaction stack.

Trajectory reduction targets the carried-history component specifically. It is not the only lever available. Two others are worth stacking on top of it: rewriting verbose raw tool output before it enters the trajectory at all, and caching the static prefix that gets resent unchanged every turn.

Chart 2: Trajectory reduction and output compaction are additive. Across four configurations of the same 30-turn session, combining trajectory reduction, output compaction, and prompt caching brings cost from $2.141 to $0.952 per session, a 56% reduction.
Chart 2: Trajectory reduction and output compaction are additive. Across four configurations of the same 30-turn session, combining trajectory reduction, output compaction, and prompt caching brings cost from $2.141 to $0.952 per session, a 56% reduction.
ConfigurationCost / 30-turn sessionvs. baseline
Baseline: full trajectory, no reduction$2.141—
Output compaction only (rewrite verbose tool output)$1.971-8%
Trajectory reduction only (prune stale/superseded context, ~50% cut to carried history)$1.436-33%
Combined: trajectory reduction + output compaction + prompt caching$0.952-56%

Output compaction alone is the smallest lever here because it only touches output tokens, which are a minority of the bill in a read-heavy agent loop. Some open-source tools built to rewrite verbose tool-call output into terse summaries report output-token reductions in the 60-70% range on coding-agent traces; we used 65% as the illustrative rate here. Trajectory reduction, applied to the carried-history component at roughly the midpoint of AgentDiet's reported 39.9-59.7% range, does more on its own because it targets the component that is actually growing. Layering prompt caching on the now-smaller static prefix adds a further discount at effectively zero engineering cost once the other two are in place.

Latency does not wait for the invoice.

The same mechanism that inflates cost also inflates time-to-first-token, because prefill cost scales with the number of input tokens a call carries, independent of what the model does with them.

Chart 3: Uncompacted context slows every turn, not just cost. Modeled P50 latency per turn grows from 1.1s at turn 1 to 2.1s at turn 30 without trajectory reduction, versus 1.6s at turn 30 with it applied each turn.
Chart 3: Uncompacted context slows every turn, not just cost. Modeled P50 latency per turn grows from 1.1s at turn 1 to 2.1s at turn 30 without trajectory reduction, versus 1.6s at turn 30 with it applied each turn.

By turn 30 in this model, the uncompacted session's per-turn latency has roughly doubled from where it started, purely from carried-history growth. Applying trajectory reduction each turn keeps that curve substantially flatter. This is a directional relationship (real prefill latency depends on batching, hardware, and provider-specific serving behavior we do not model here), but the direction is not in question: a call that carries 22,000 tokens of mostly-already-read context is slower to start generating than one that carries 4,000. Teams that treat cost and latency optimization as separate projects are often solving the same root cause twice.

Where the wasted tokens actually come from.

"Trajectory tax" is not one thing. Breaking down the overhead in the modeled session shows five distinct categories, each with a different fix:

Chart 4: Overhead tokens are not one problem, they are five. Illustrative breakdown of carried-history and retrieved-context overhead: verbose raw tool output 26%, stale tool schemas 22%, duplicate retrieved content 20%, superseded reasoning steps 18%, irrelevant retrieved chunks 14%.
Chart 4: Overhead tokens are not one problem, they are five. Illustrative breakdown of carried-history and retrieved-context overhead: verbose raw tool output 26%, stale tool schemas 22%, duplicate retrieved content 20%, superseded reasoning steps 18%, irrelevant retrieved chunks 14%.

Two of these five categories, stale schemas and duplicate retrieval, are close cousins of problems covered elsewhere: see MCP tool-schema overhead and over-retrieval in RAG pipelines. The other three, verbose output, superseded reasoning, and general context accumulation, are specific to the trajectory itself and do not show up in a chunk-count or schema-size audit.

Cost vs. quality: pruning is not the same move as downgrading.

The instinctive response to a high agent bill is to swap in a cheaper model. The data here argues that trajectory reduction and model downgrading are not interchangeable, because they remove different things.

Chart 5: Pruning tokens the model never needed preserves quality; downgrading models does not. Illustrative comparison across four strategies: always-Opus baseline at 97% quality and $2.141, always-Haiku at 74% quality and $0.343, trajectory reduction alone at 96% quality and $0.952, trajectory reduction plus routing at 93% quality and $0.685.
Chart 5: Pruning tokens the model never needed preserves quality; downgrading models does not. Illustrative comparison across four strategies: always-Opus baseline at 97% quality and $2.141, always-Haiku at 74% quality and $0.343, trajectory reduction alone at 96% quality and $0.952, trajectory reduction plus routing at 93% quality and $0.685.
StrategyCost / sessionQuality vs. baseline
Baseline: always Opus, no reduction$2.14197%
Blind downgrade: always Haiku, no reduction$0.34374%
Trajectory reduction only (same model, pruned context)$0.95296%
Trajectory reduction + routing (filter/summarize steps sent to a small model)$0.68593%

A blind model downgrade cuts cost 84% and quality drops 23 points, because a weaker model is now doing the actual reasoning on the actual task. Trajectory reduction alone cuts cost 56% for a 1-point quality change, because it removes tokens the strong model was never using to produce the answer in the first place, which AgentDiet's own held-performance result across two benchmarks supports. Adding routing on top, sending only the mechanical filter-and-summarize steps (not the task reasoning) to a small model, adds more savings back at a real but much smaller quality cost than blanket downgrading. The order of operations matters: prune first, downgrade selectively second, not the reverse.

Implementation framework.

Step 1: Instrument token usage by stage. Log input tokens before and after each component is appended: system prompt, tool schemas, retrieved context, history. Most teams have never measured their own turn-10-versus-turn-1 growth curve.

import anthropic
client = anthropic.Anthropic()

def stage_tokens(system: str, history: list, tools: list, model: str) -> dict:
    base = client.messages.count_tokens(model=model, system=system, messages=[]).input_tokens
    with_tools = client.messages.count_tokens(
        model=model, system=system, messages=[], tools=tools
    ).input_tokens
    full = client.messages.count_tokens(
        model=model, system=system, messages=history, tools=tools
    ).input_tokens
    return {
        "static_overhead": with_tools,
        "carried_history": full - with_tools,
        "total_input": full,
    }

Step 2: Separate reasoning tokens from context tokens. The split that matters is what the model needs to decide the next action versus what is along for the ride. History and retrieved content are the second category, and it is where most of the overhead in this analysis lives.

Step 3: Detect over-reading and duplicate retrieval. If a chunk or tool result already appeared, summarized, in an earlier turn, re-including it in full is a duplicate-context bug, not a retrieval quality issue.

Step 4: Route simple steps to cheaper models. Chunk relevance scoring, tool-output summarization, and query generation are classification-grade tasks. They do not need the model doing the task's actual reasoning.

Step 5: Compress only after retrieval, not blindly before. Summarizing a document before you know which parts the task needs risks deleting the answer. Compress what was retrieved, after it is scoped to the current turn.

Step 6: Add confidence thresholds and fallback logic. A pruning or routing decision that is wrong on 5% of turns and silently degrades output is worse than a slower path that is consistently correct. Gate aggressive pruning behind a cheap confidence check, and fall back to the fuller context when it fails.

Step 7: Monitor cost, latency, and quality together. A cheaper model or a smaller context that causes retries can cost more than the unoptimized version. Track all three as a triad, not cost in isolation.

What this means for engineering teams.

The 82%-by-turn-20 finding is a property of how the ReAct loop is built, not a property of the task. An agent that re-sends its own trajectory unmodified is going to compound overhead regardless of which model reads it, and no model swap fixes that on its own: it just makes each unit of overhead cheaper, not smaller.

This is the layer model routing needs to sit on top of, not the layer it replaces. Blind routing without context discipline still pays to re-send stale history on every call, just at a lower per-token rate. Trajectory reduction without routing still uses a frontier model for filter-and-summarize work that a cheaper model handles correctly. Neither alone gets you the full picture in the cost-vs-quality chart above; the combination does. Nadir is built for the second half of that combination: classifying the complexity of each step, routing filter and summarization work to the minimum-cost model that preserves quality, and surfacing the savings against an always-premium baseline on a per-request basis, without requiring the trajectory-level engineering work to happen first.

Conclusion.

The future of agentic AI cost optimization is not a single lever. It is instrumenting where tokens actually go by stage, pruning the ones the model has already read and does not need again, compressing what is left after retrieval rather than before it, and routing the mechanical steps to a cheaper model while keeping the reasoning steps on the model that can do them. Trajectory reduction and model routing solve adjacent, not overlapping, problems: one shrinks what gets sent, the other decides who reads it. Teams that only do the second one are still paying the trajectory tax; they are just paying a discounted rate on it.


Data in charts is illustrative, modeled from public research and Anthropic pricing as of August 2026. Not derived from proprietary production traces. Sources: [Xiao, Gao, Peng, and Xiong, "Reducing Cost of LLM Agents with Trajectory Reduction" (AgentDiet), arXiv:2509.23586, FSE 2026](https://arxiv.org/abs/2509.23586). [Kim, "Entropic Context Shaping: Information-Theoretic Filtering for Context-Aware LLM Agents," arXiv:2601.11585](https://arxiv.org/pdf/2601.11585). [Liu et al., "Lost in the Middle: How Language Models Use Long Contexts," arXiv:2307.03172](https://arxiv.org/abs/2307.03172). [Pinggy, "8 Open Source Tools to Slash AI Coding Agent Token Usage," 2026](https://pinggy.io/blog/tools_to_reduce_ai_coding_agent_token_usage/). [Anthropic Claude Pricing, August 2026](https://www.anthropic.com/pricing). [Anthropic Token Counting API](https://docs.anthropic.com/en/docs/build-with-claude/token-counting).

What Nadir is

Nadir is an LLM router. Nadir sizes every prompt and routes it to the cheapest model that still clears your quality bar. A trained pre-classifier scores each prompt in under 10 ms, with no LLM call in the routing step.

Nadir runs two ways. The decision API returns a model, reasoning-effort, cache, context, and policy recommendation without calling a model provider, beside the gateway you already run. That is how a shadow-mode evaluation works, and its projected savings stay advisory. The OpenAI compatible managed proxy executes the route, and migration is a two-line change: point the base URL at api.getnadir.com and set model to auto. On that path an optional verifier can score a complete non-streaming answer and escalate to a stronger model when it misses the configured bar. Streaming bypasses post-generation verification. BYOK is supported on every tier.

What the numbers are, and what they are not

Nadir publishes each evaluation with its scope. On checkable code, run-check-escalate solved 392 of 395 common HumanEval and MBPP problems (99.2%), graded by running the canonical tests; that applies only to tasks with runnable deterministic tests. Nadir-Tumbler posts an arena_score of 72.3 on RouterArena's public scorer, 5th of 23 routers, which measures the routing decision on RouterArena's own model pool. A reference-assisted RouterBench evaluation over 11,420 held-out triples produced a 60% lower projected cost than always-Opus with about 98% retained quality and a 1.7% catastrophic-route rate. That experiment gave the verifier the expensive-model reference answer, which production does not have, so it is a research ceiling and not the deployed path.

None of these is a production guarantee, a universal savings rate, or a forecast for any particular workload. Customer savings are reported from measured execution against a declared baseline, and customer quality only from outcome-labelled traffic. Projected savings and realized savings are separate artifacts and are never blended.

Design-partner program

Three rungs, picked by risk appetite. Rung 0 Shadow runs advisory decision calls alongside live traffic and returns a projected receipt, with nothing in the request path changed. Rung 1 Hosted is the two-line swap on a production slice and returns a realized receipt. Rung 2 On-prem is a supervised six-week proof of concept inside the partner's VPC, where no prompt, response, or usage reaches Nadir. The commitments are the same at every rung. Apply for a rung directly: Rung 0 Shadow, Rung 1 Hosted, or Rung 2 On-prem. Not sure which fits? Start at getnadir.com/contact/?reason=design-partner.

Licensing

NadirClaw is the self-hosted core, source-available under the PolyForm Noncommercial License. Source-available is the correct label; NadirClaw is not open source. Nadir Route's hosted plan has no base fee and charges a variable fee only on measured savings from requests Nadir executed.

Pages on this site

Machine-readable summaries of this site: llms.txt and llms-full.txt.