Manuscript Offprint
arXiv:2610.35496The Hidden Costs of Forgetting: A Study of Trajectory Deletion in Software Engineering Agents
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Fernando Vallecillos-Ruiz*, Islem Bouzenia†, Michael Pradel†, Leon Moonen*
- Simula Research Laboratory, Norway
fernando@simula.no, leon.moonen@computer.org
† CISPA Helmholtz Center for Information Security, Germany
bouzenia.islem@pm.me, michael@binaervarianz.de
Abstract—Software engineering agents resend their entire trajectory to an LLM at every turn, which motivates work on online trajectory reduction. Prior work shows that even randomly deleting 75% of the tokens in old turns may preserve the agent's effectiveness, but it remains unclear why this is the case, what the agent does to compensate for missing content, and whether trajectory reduction actually reduces costs. This paper presents an empirical study of 42 trajectory-reduction configurations, focusing on their effects on effectiveness, agent behavior, and cost. Our study systematically explores the effects of deleting content from old turns by varying the scope, granularity, amount, and timing of deletion across 9,400 runs with two state-of-the-art agents on the SWE-bench Verified dataset. We find that deleting large amounts of trajectory content (e.g., up to 100% of reasoning text) can preserve overall effectiveness. Importantly, such deletion needs to be applied with a delay, as deleting content immediately after it is generated tends to significantly degrade effectiveness. Agents often compensate for deleted content by re-fetching it, which can increase both the number of turns an agent takes to solve a task and the number of input and output tokens. Whether trajectory reduction reduces LLM costs depends on the pricing model: Under a flat pricing model, where all input tokens are billed equally, estimated costs fall in 26 of 42 evaluations across both agents. Surprisingly, under a caching-aware pricing model, none of these 42 evaluations yields lower estimated costs, since reducing the trajectory breaks the cached prefix, whose tokens are billed at a lower rate. Our findings have several important implications: First, token counts alone are misleading; trajectory reduction techniques must instead consider overall costs under a realistic pricing model. Second, studies of trajectories are important for understanding agent behavior, as focusing only on end-to-end effectiveness can hide important behavioral differences, such as excessive re-fetching of deleted content. Finally, these results highlight the need for future work on memory management, that is, deciding which trajectory content to keep or delete and when to delete it, to reduce costs without sacrificing effectiveness.
Index Terms—LLM agents, software engineering agents, trajectory reduction, inference cost
I. INTRODUCTION
Software engineering agents based on large language models (LLMs) increasingly automate software engineering tasks by inspecting repositories, modifying code, and validating patches [1]. Such agents retain prior reasoning, tool calls, and tool outputs in a trajectory that grows as they work. This growth increases the context processed by the model and can eventually exceed its context window [2, 3], making trajectory management an important challenge.
Prior approaches reduce retained trajectories by discarding messages or tool outputs, selecting content to remove, or summarizing earlier interactions [2–4]. For example, AgentDiet reports that randomly deleting up to 75% of eligible trajectory tokens can preserve much of an agent's effectiveness [2]. These studies demonstrate that agents can tolerate substantial trajectory reduction.
However, existing results do not show how the individual design choices in trajectory deletion affect agents. A deletion policy must decide what to remove, how much to remove, whether to remove whole turns or individual tokens, and whether to protect recent turns. Because trajectories contain diverse information, from intermediate reasoning to tool observations, these choices may affect agents differently. A systematic study that isolates deletion scope, granularity, amount, and timing can clarify how each choice affects task solving.
Trajectory reduction requires broader evaluation than final task success or token counts alone. An agent may complete a task by revisiting files, repeating commands, or retrieving deleted information, adding work even when the outcome is unchanged [5, 6]. Token counts also do not establish cost savings: prompt caching discounts reusable input prefixes, and rewriting a trajectory can invalidate part of that prefix [6–9]. Evaluations thus need to measure task effectiveness, subsequent agent behavior, and execution cost together.
This paper presents a systematic empirical study of trajectory deletion in software engineering agents. We vary scope, granularity, amount, and timing across 42 deletion configurations, evaluating each on two popular agents (Mini-SWE-agent [10] and Trae agent [11]). Half of the configurations delete with a two-turn delay and half without it, which gives 42 evaluations per timing across both agents combined. The study covers 100 SWE-bench Verified [1] tasks and 9,400 runs. We measure effectiveness as tasks solved, analyze how agents behave after content is deleted, and estimate execution costs under both flat and caching-aware pricing. More specifically, we address three research questions.
RQ1: How do deletion scope, granularity, amount, and timing affect effectiveness and execution length? We find that the timing of trajectory reduction is critical. With a two-turn delay, 37 of 42 evaluations do not statistically significantly reduce the number of tasks solved. In contrast, immediate deletion significantly reduces the number of tasks solved in 19 of 42 evaluations. The kind of deleted content also matters: Removing reasoning usually does not affect effectiveness, but deleting tool output is more harmful. Finally, we observe that trajectory reduction tends to increase the number of turns an agent needs (in 21 of 42 and 34 of 42 evaluations with delayed and immediate deletion, respectively).
RQ2: How does trajectory deletion affect agents' subsequent behavior, particularly the repeated retrieval of previously observed information? Agents often compensate for deleted content by re-fetching it. For example, deleting tool outputs raises the re-fetch rate to as much as 7.5 times (with delayed deletion) and 10.6 times (with immediate deletion) compared to the baseline.
RQ3: How does trajectory deletion affect estimated execution cost under flat and caching-aware pricing? The answer heavily depends on the pricing model. Assuming a flat pricing model, where all input tokens are billed equally, 26 of 42 evaluations with the delay reduce estimated costs across both agents. However, the results change under a caching-aware pricing model, where cached input prefixes are billed at a lower rate. In this case, none of these 42 evaluations reduce estimated costs, and 26 evaluations are significantly more expensive than the uncompressed baseline.
Our findings have several important implications for future work. First, trajectory reduction should be evaluated not only in terms of task success and token counts. Instead, evaluations should also consider execution length, retrieval behavior, and estimated costs under realistic pricing models. Second, it is important to study the behavior of agents after trajectory reduction, as they may compensate for deleted content by re-fetching it, which can increase execution length and costs. Finally, we expect the detailed results across our 42 deletion configurations to inform future research on trajectory reduction techniques, including memory management strategies that decide what to keep or delete and when to delete it.
In summary, this work makes three contributions:
-
A systematic study of trajectory deletion in agents, quantifying how deletion scope, granularity, amount, and timing affect effectiveness, agent behavior, and execution costs.
-
A detailed analysis of trajectories resulting from trajectory deletion, showing that agents selectively re-fetch deleted tool outputs, preserved effectiveness can conceal longer executions, and fewer tokens can yield higher estimated costs under caching-aware pricing.
-
A dataset and replication package [12] containing 9,400 trajectories produced by two agents on 100 SWE-bench Verified tasks using 42 trajectory reduction configurations, including the original content of deleted turns and analysis code for studying retrieval behavior and execution cost.
A. Agents and Their Trajectories
An LLM-based agent solves tasks, such as GitHub issues, through repeated model calls and repository interactions [10,

Fig. 1. The longest prefix identical to the previous prompt is billed at the cached price. Reducing T2 at Call 4 rewrites it to T2', i.e., T2' and every later turn are re-billed. At Call 5, the prefix matches again and only T5 is new.
11, 13]. At each turn, the model produces reasoning text and tool calls, such as commands to inspect files, modify code, or run tests. The agent executes these calls and records their outputs. A turn comprises one model call, its reasoning, tool calls, and resulting outputs. The sequence of turns forms the agent's trajectory [14]. An agent retaining its complete trajectory includes previous interactions and newly acquired information in each request, so the prompt grows during execution. Tool outputs, including file contents, search results, and test logs, contribute to this growth. Since input-token processing is a major part of coding-agent costs [15], reducing the retained trajectory offers a way to limit context consumption.
B. Trajectory Reduction
Trajectory-reduction approaches rewrite old turns before re-sending them and differ in what they remove and retain. Masking replaces old tool outputs with a placeholder [10, 16]. Selection uses a model to identify and remove irrelevant content [2, 17]. Summarization (compaction) replaces a span of turns with an LLM summary [18, 19]. Recently, agents have been trained to decide when and what to compact [3, 4]. Our study builds on AgentDiet [2], in which a reflection model removes content classified as useless, redundant, or expired from every turn longer than 500 tokens once it is two turns old. AgentDiet's random baseline deletes 75% of eligible tokens and solves almost as many tasks as its model-based reduction approach. These results motivate studying agents' compensation for deletion and the resulting additional execution costs.
C. Prefix Caching and Its Pricing
A model computes key and value vectors for prompt tokens and stores them in a key-value (KV) cache. When a prompt repeats the previous prompt and appends a turn, inference engines reuse cached states for the matching token prefix [20, 21]. Prefix reuse ends at the first token that differs because each cached state depends on the preceding tokens. OpenAI, Anthropic, Google, and DeepSeek discount input tokens served from matching cached prefixes. When the cache is available, an agent appending turns without rewriting history pays the cached price for the repeated prefix. Rewriting an old turn changes the prefix and prevents reuse of the cached states from the first change onward (Figure 1). Under the caching-aware pricing model used in this study, these tokens incur the full input price. SWE-agent's documentation warns that eliding old observations breaks prompt caching [22], and
Anthropic’s documentation states that clearing tool results or reasoning invalidates the cached prefix [19]. Section VI evaluates whether token savings offset the cost of processing tokens beyond the matching prefix.
III. STUDY DESIGN
A. Agents and Tasks
We evaluate two agents with different tool interfaces. The first is Trae agent [11], the agent used by AgentDiet [2], which we include to support comparison with AgentDiet. Trae agent features a structured file viewer, an editor, and a shell environment. The second is Mini-SWE-agent [10], a setup restricted to a single shell tool, which provides a contrast to the specialized tools of Trae agent. Both agents use the same model, DeepSeek-V4-Flash [23]. We choose this open-weight model to support self-hosted inference, complete call logging, and execution of 9,400 runs (Section III-E).
The tasks are the fixed 100-instance subset of SWE-bench Verified [1] used by AgentDiet [2]. Each task corresponds to a real GitHub issue and has a hidden, human-validated test suite. Using AgentDiet's subset [2] supports direct comparison and limits the experiment to 4,700 runs per agent.
B. Deletion Configurations
A turn yields three pieces of information: (i) reasoning text produced by the model, (ii) one or more tool calls suggested by the model, and (iii) the outputs of those tool calls. The trajectory contains information from all completed turns and forms part of each subsequent model request. We vary four dimensions of deletion: scope, granularity, amount, and timing. Each configuration assigns values to each dimension, and is evaluated on both agents. Deletion rewrites eligible turns before a model call, conforming to the configuration.
Scope. The scope is the part of a turn eligible for deletion. We evaluate three scopes: (i) reasoning text, (ii) tool output, or (iii) both, including the tool call. The third scope therefore covers the entire turn. We do not consider the tool call itself as a scope because it is usually short. Reasoning includes observations, plans for subsequent actions, and hypotheses about the cause of a bug. Tool outputs include file contents, search results, and test logs.
Deletion occurs after a turn’s tool calls execute, so the deletion configuration leaves commands unchanged before execution.
Granularity. Turn-level deletion (Turn in the tables and figures) drops the scoped content of a turn entirely, with probability p, and replaces it with a one-line note indicating deleted content. Token-level deletion (Token in the tables and figures) removes 100p% of the scoped tokens of a turn, chosen at random, and keeps a note together with the surviving tokens. At the same p, both granularities delete approximately the same expected percentage of scoped tokens. Token-level deletion retains some tokens in each eligible turn, whereas turn-level deletion either removes or retains all scoped content.
After each turn, the procedure processes the newly eligible turn. Turn-level deletion draws uniformly from and
R Reasoning
C Tool Call
O Tool Output
T1 R Let me understand the issue...
C view /testbed
O /testbed/AUTHORS... (289 lines)
T2 R Let me find the relevant file...
C find ... | grep ModelBackend
O .../auth/backends.py ... (5 files)
T3 R Let me look at the backends...
C view .../auth/backends.py
O import inspect ... (211 lines)
Turn-level
Both
Immediate
Token-level
Tool output
Delayed

Fig. 2. The first three turns (T1–T3, left) of a Trae agent trajectory and the prompts at the next call under two configurations (right). The first configuration deletes T1 and T3, while T2 remains intact. The second configuration modifies parts of T1.
removes the scoped content if the draw is below p. For token-level deletion, the procedure tokenizes the scoped content with a fixed tokenizer and removes of its n tokens, sampled uniformly without replacement.
Amount. We express the amount as a percentage of scoped tokens deleted, so corresponds to 25% deletion. We use 25%, 50%, 75%, and 100% for turn-level deletion, to cover the range from light to total deletion, and 25%, 50%, and 75% for token-level deletion since at 100% the two granularities coincide. This gives combinations of scope, granularity, and amount.
Timing. A turn becomes eligible for rewriting after a fixed delay. With delayed timing, the delay is two turns, so the last two turns are always intact. The two-turn delay follows AgentDiet [2]. With immediate timing, the delay is zero. This configuration tests the effect of removing the retention delay. Immediate deletion rewrites a turn before the next model call, so the agent never observes the original content of a deleted output. The procedure considers each turn once, when the turn becomes eligible. Therefore, a turn that survives the turn-level draw stays intact, while a rewritten turn stays rewritten for the rest of the run. Figure 2 illustrates the two granularities and contrasts immediate and delayed timing on a real Trae agent trajectory. The 21 combinations at each of two timings yield 42 configurations. Evaluating every configuration on both agents gives 84 evaluations, with 42 evaluations per timing.
C. Research Questions and Metrics
RQ1. Effectiveness: How do deletion scope, granularity, amount, and timing affect effectiveness and execution length? To answer RQ1, we evaluate all 42 configurations (Section III-B) on both agents and the same 100 tasks (Section III-A). Furthermore, we add five uncompressed runs per agent. Because inference is not deterministic, the repeated baselines characterize execution variability without deletion. For each run, we track four metrics: (1) a task is solved when the patch passes its associated test suite. A failing patch, no patch, or a run that ends with a context-length error counts as not solved. We report the number of tasks solved, or the solved rate when expressed as a percentage; (2) run length is the number of turns, which we summarize by its median across tasks; (3) a run is capped when it reaches the 200-turn budget. A capped run can still solve the task if it already holds a working patch while testing it; (4) a run loops when it repeats an identical tool call at least ten times in a row. We compare each configuration with the uncompressed runs (Section III-D). We first examine scope, granularity, and amount under delayed deletion, following AgentDiet [2], and then compare delayed and immediate deletion to assess the effect of timing.
RQ2. Behavior: How does an agent compensate for content deleted from its trajectory? To answer RQ2, a rule-based labeler classifies each tool call as a read, edit, test, script, or other operation. The labeler identifies file reads performed through shell commands or Python scripts. We manually verify the labels for ten randomly sampled logs, five per agent. For each agent, the five sampled logs comprise one uncompressed run and runs from two delayed and two immediate configurations. The labeler assigns 851 of the 855 labels correctly (99.5% accuracy). The replication package includes the classifier and the ten manually verified logs. We then mark each read as a re-fetch or an initial read: a read is a re-fetch when at least 80% of its distinct lines already appear in the output of an earlier read in the same run. We exclude outputs under five lines to avoid accidental matching. The re-fetch rate is the number of re-fetches divided by the number of reads, per run, reported as a ratio to the uncompressed runs (Section III-D). Normalizing by the number of reads supports comparison across configurations with different run lengths. The analysis also compares re-fetching of deleted and retained outputs and characterizes run behavior. Furthermore, we measure on the uncompressed runs how far back an agent reaches for content. For a re-fetch, we count the turns since its lines last appeared in a read. For an edit, we count the turns since the agent last read the file. The percentage of re-fetches and edits whose source lies within the last k turns indicates what a deletion delay of k turns would leave intact.
RQ3. Cost: How does trajectory deletion affect estimated execution cost under flat and caching-aware pricing? To answer RQ3, we calculate token counts from the logs (Section III-E) and estimate each run's cost relative to the uncompressed baseline under two pricing models. Under flat pricing, every prompt token costs the input price. Under caching-aware pricing, only the longest prefix identical, token for token, to the previous call's prompt costs the cached price, and all remaining prompt tokens cost the input price (Section II-C). Both models bill completion tokens at the output price. An uncompressed trajectory preserves the prefix, whereas a rewrite re-bills tokens from the first change onward. Turn-level deletion breaks the prefix only when a turn is selected for deletion. Token-level deletion breaks it at every call with an eligible turn.
Depending on the provider, a cached token costs 0.05 to 0.5 times the price of a new input token [24–27]. We pick a price ratio of 1 : 0.1 : 5 for input, cached input, and output tokens. The cached-input ratio of 0.1 lies within this range. The caching-aware model ignores cache-write premiums and assumes that every matching prefix is served from the cache, so its cost estimate is a lower bound on realistic costs.
D. Statistical Analysis
The reference for every comparison is the five uncompressed runs of the same agent. For tasks solved and the re-fetch rate, we compare a configuration with the per-task mean of the five runs. Run length and cost have long-tailed distributions, including capped runs, so we summarize these metrics with medians. For these two metrics, we take the median of the configuration over the 100 tasks, divide it by the median of each uncompressed run, and average the five ratios.
We make two kinds of comparison. The first is a configuration against the reference, as above. The second compares two configurations that differ in one dimension, on the same agent: delayed against immediate timing (RQ1 and RQ2), or turn-level against token-level granularity at the same scope, amount, and timing (RQ1). Every comparison is paired by task, and its uncertainty is a paired bootstrap confidence interval over the 100 tasks. We resample the 100 tasks with replacement 10,000 times. On each resample, we compute the statistic of the configuration on the drawn tasks and the statistic of the reference on the same drawn tasks (the mean task-solving outcome, or the median of turns or cost), and then their change or ratio. The 2.5th and 97.5th percentiles of these 10,000 values form the 95% interval. A change is significant when its interval excludes zero (for a change in tasks solved) or one (for a ratio of turns, re-fetch rate, or cost).
E. Implementation and Data
We conduct all experiments on a cluster with NVIDIA GH200 Hopper graphics processing units (GPUs), compute capability 9.0, and CUDA 12.8. The experiments run in Apptainer containers with the vLLM [28] inference stack and incur no metered application programming interface (API) charges. We serve the model with a context window of approximately 262,000 tokens, high reasoning effort, temperature zero, and a limit of 8,192 output tokens per call. We keep full logs for all runs: prompts sent, generated tokens, and the original text of every deleted turn. The replication package holds all 9,400 runs with their logs and the analysis code.
IV. RQ1: How Does Deletion Affect Task Solving?
Table I reports, for each configuration and agent, the number of tasks solved out of 100 and the change in median run length relative to the uncompressed baseline. Bold marks a statistically significant change. The table omits counts of capped runs, loops, and runs without a patch for readability. The following analysis reports these counts where relevant. The replication package includes all counts for every configuration.
A. Delayed Deletion: Scope, Granularity, and Amount
Tasks solved. Only five of the 42 delayed-configuration evaluations (in bold) show a significant loss, while the confidence intervals for the other 37 include zero change. Three of these five solve more than ten fewer tasks than the baseline, and all
TABLE I
RQ1: TASKS SOLVED (OF 100) AND CHANGE IN MEDIAN RUN LENGTH. BOLD MARKS STATISTICALLY SIGNIFICANT CHANGES FROM THE UNCOMPRESSED BASELINE. –: THE MEDIAN RUN REACHES THE 200-TURN BUDGET.
| Scope | Granularity | % Deleted | Mini-SWE-agent | Trae agent | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Delayed | Immediate | Delayed | Immediate | |||||||
| Tasks solved | Turns | Tasks solved | Turns | Tasks solved | Turns | Tasks solved | Turns | |||
| Uncompressed | 72.6 (71–76) | 31.5 | 74.6 (74–76) | 42.5 | ||||||
| Reasoning | Turn | 25 | 71 | 0% | 75 | +11% | 70 | -9% | 76 | +1% |
| 50 | 69 | +5% | 73 | +13% | 72 | -3% | 69 | -5% | ||
| 75 | 71 | +3% | 71 | +13% | 79 | -11% | 72 | -6% | ||
| 100 | 74 | +11% | 75 | +105% | 72 | -4% | 77 | +35% | ||
| Token | 25 | 73 | 0% | 74 | +6% | 74 | -10% | 77 | -7% | |
| 50 | 75 | 0% | 74 | +19% | 75 | -15% | 76 | +2% | ||
| 75 | 74 | -11% | 71 | +49% | 79 | -11% | 74 | +15% | ||
| Tool output | Turn | 25 | 72 | +3% | 75 | +25% | 74 | +3% | 73 | +29% |
| 50 | 73 | +21% | 72 | +86% | 72 | +19% | 73 | +111% | ||
| 75 | 70 | +14% | 56 | +211% | 70 | +36% | 66 | +350% | ||
| 100 | 69 | +19% | 14 | +476% | 70 | +73% | 0 | - | ||
| Token | 25 | 71 | +3% | 71 | +65% | 74 | +16% | 50 | +204% | |
| 50 | 69 | +22% | 65 | +174% | 70 | +39% | 29 | - | ||
| 75 | 70 | +35% | 27 | - | 67 | +45% | 5 | - | ||
| Both | Turn | 25 | 72 | +3% | 72 | +24% | 72 | +15% | 69 | +36% |
| 50 | 74 | +3% | 66 | +68% | 72 | +27% | 74 | +102% | ||
| 75 | 70 | +25% | 67 | +244% | 69 | +92% | 72 | +338% | ||
| 100 | 59 | +98% | 2 | +433% | 43 | - | 0 | - | ||
| Token | 25 | 69 | +16% | 31 | +21% | 71 | +12% | 58 | - | |
| 50 | 66 | +25% | 17 | +52% | 77 | +106% | 34 | - | ||
| 75 | 68 | +32% | 14 | +381% | 60 | - | 5 | - | ||
three delete reasoning and tool output together: Mini-SWE-agent loses 14 tasks and Trae agent 32 when every turn is deleted whole, and Trae agent loses 15 under token-level deletion of 75% of both. The other two drops are seven tasks for Mini-SWE-agent with 50% token-level deletion of both scopes and eight for Trae agent with 75% token-level deletion of tool output.
Scope. Delayed reasoning deletion shows no statistically significant decrease in tasks solved or increase in run length. Across the 14 evaluations of reasoning deletion, the change in tasks solved ranges from -5 to +4 relative to the baseline. Some Trae agent configurations reduce median run length by up to 15%. At a fixed deletion percentage, reasoning deletion removes fewer tokens than deletion of tool output or both scopes (Section VII). The experiment therefore does not isolate the effect of scope from the number of tokens removed.
Granularity. Granularity primarily affects run length in these comparisons. Only one pair differs significantly in tasks solved by the paired bootstrap: Trae agent, both, 75%, where turn-level deletion solves 69 tasks and token-level deletion 60. Granularity also affects run length. Token-level deletion produces longer runs than turn-level deletion in ten of the twelve pairs that delete tool output. The difference increases with the deletion percentage. At 75% deletion of both scopes, Trae agent's median run reaches the turn cap under token-level deletion, compared with a 92% increase over the baseline under turn-level deletion. In the six reasoning pairs, runs are equal or shorter under token-level deletion.
Amount. Up to 50%, only one evaluation (Mini-SWE-agent) loses tasks significantly. At 75%, three evaluations on Trae agent solve six to 15 fewer tasks, all involving tool output deletion. Deleting 100% of both reasoning and tool output significantly reduces tasks solved for both agents. Increased deletion is also associated with longer runs. Of the 28 evaluations that delete tool output, 21 have significantly longer runs, compared with none of the 14 evaluations that delete reasoning alone. Under turn-level deletion of both scopes, Trae agent's median run grows from 15% above the baseline at 25% deletion to the cap at 100%. The number of capped runs increases from four to 92 out of 100, whereas tasks solved decrease significantly only at 100% deletion, from a baseline mean of 74.6 to 43. Longer runs also occur without a statistically significant decrease in tasks solved. Under turn-level 100% deletion of tool output, Trae agent solves 70 tasks, compared with a baseline mean of 74.6, while median run length increases by 73% and 29 runs reach the cap. Reporting only tasks solved thus hides longer runs and budget exhaustion.
Comparison with AgentDiet. AgentDiet [2] evaluates two fixed baselines on Trae agent, on the same 100 tasks and with the same two-turn delay: one deletes 75% of the tokens of a turn at random and the other deletes the turn entirely, both applied to reasoning and tool output together [2]. They correspond to our token-level deletion of 75% of both and our turn-level deletion of 100% of both. Both studies agree that deleting the whole turn costs more tasks and more turns than deleting 75% of its tokens. The magnitudes differ: AgentDiet reports 1 and 7 fewer tasks solved against our 15 and 32, and
13% to 14% more turns where our runs reach the cap. Three design differences limit direct comparison: AgentDiet rewrites only turns longer than 500 tokens rather than every turn, uses Claude 4 Sonnet rather than DeepSeek-V4-Flash, and limits runs to 50 turns rather than 200.
Answer to RQ1: Delayed deletion. With delayed deletion, 37 of 42 evaluations show no statistically significant decrease in tasks solved. However, runs lengthen significantly in 21, all deleting tool output.
Implications for future work. Our results call for evaluations of trajectory reduction that measure tasks solved, execution length, and budget exhaustion under common turn limits, since agents can preserve effectiveness through additional work. The contrast between reasoning and tool output deletion also motivates memory-management policies that treat these content types differently. Future comparisons should match the number of tokens removed to determine whether such policies improve the tradeoff between effectiveness and execution effort.
B. Immediate Deletion: The Effect of Timing
Without the delay, a deleted output is rewritten before the first call that would show it, so the agent never sees it intact. At 100% of tool output or of both, the agent therefore never sees any tool output at all. Immediate deletion raises significant losses in tasks solved (in bold) from five to 19 of the 42 evaluations per timing, and significantly longer runs from 21 to 34. No immediate configuration has significantly shorter runs than the baseline. Paired bootstrap comparisons of configurations that differ only in timing show significantly fewer tasks solved with immediate deletion in 16 of the 42 comparisons. The two agents fail differently. In the eight Trae agent configurations with fewer than 60 tasks solved, 33 to 100 of the runs loop, against two to five in the uncompressed runs. In the six Mini-SWE-agent configurations with fewer than 35 tasks solved, 38 to 94 of the runs end without a patch, and Mini-SWE-agent loops in at most one run in any configuration.
Turn-level deletion. At 25% and 50%, no turn-level configuration differs significantly from its delayed value, although runs are up to twice as long as the baseline when deletion affects tool output. Two of these configurations, Mini-SWE-agent with both and Trae agent with reasoning deleted at 50%, are about six tasks below the reference. At 75% deletion, the effects differ between agents. Mini-SWE-agent loses 14 tasks when tool output is deleted, while Trae agent keeps its delayed value but loops in 41 to 60 of its runs, with a median run close to the cap. At 100% deletion of tool output or both scopes, Trae agent solves no tasks, and with both deleted, it repeats one directory listing until the cap in every run. Mini-SWE-agent solves two tasks with both deleted and 14 with tool output deleted, without ever observing file contents. Its 14 successful patches warrant further analysis to distinguish reliance on issue descriptions, memorized fixes, and other explanations.
Token-level deletion. Immediate token-level deletion of tool output reduces Trae agent's tasks solved at every deletion percentage, to five at 75%, with most runs capped from 50% onward. Mini-SWE-agent shows no significant difference from delayed deletion up to 50% deletion and solves 27 tasks at 75% deletion. With both scopes deleted, Mini-SWE-agent solves 31 tasks at 25% against 69 under delayed deletion. Of the immediate runs, 45 end without a patch, and none reach the cap. Compared with delayed deletion, Trae agent solves 13 fewer tasks at 25% deletion. It solves 34 and five tasks at 50% and 75% deletion, respectively. The content left by each granularity offers an interpretation of this difference, drawn from Trae agent's traces and not an established cause. Turn-level deletion replaces the removed content with an explicit deletion notice, whereas token-level deletion leaves fragments that the agent sometimes reads as repository corruption and attempts to repair. Loop counts are consistent with this interpretation. At 50% of tool output, 67 of Trae agent's runs loop under token-level deletion against eight under turn-level deletion, compared with nine and six looping runs under delayed deletion and two to five in the uncompressed baseline.
Reasoning deletion. Immediate and delayed reasoning deletion yield similar numbers of tasks solved. Confidence intervals include zero change in 13 of the 14 evaluations. The exception solves six fewer tasks than the baseline. Run length shows a different pattern. No delayed reasoning evaluation has significantly longer runs, but seven of the 14 immediate ones do, by under 20% in all but three. Mini-SWE-agent's runs are 49% longer under token-level deletion of 75%, and turn-level deletion of 100% lengthens Trae agent's runs by 35% and Mini-SWE-agent's by 105%. At 75% deletion, the corresponding increase is 13% for Mini-SWE-agent, with no significant change for Trae agent.
Answer to RQ1: Immediate deletion. Without the delay, 19 of 42 evaluations show significantly fewer tasks solved than the baseline, and 34 have significantly longer runs. While reasoning deletion and turn-level deletion of up to 50% of tool output generally retain their delayed effectiveness, token-level deletion of tool output does not.
Implications for future work. The timing comparisons motivate studies of memory management that jointly vary retention delay and deletion scope. Such studies should test whether reasoning and tool outputs require different protection periods and measure tasks solved, execution length, and failure behavior under each policy. Analyses of loops, missing patches, and budget exhaustion would clarify how retention choices affect execution beyond the final task outcome.
V. RQ2: HOW DOES THE AGENT COMPENSATE FOR DELETED CONTENT?
Table II gives, for each configuration and agent, the re-fetch rate as a ratio to the uncompressed runs, where 19 of every 100 reads are re-fetches for Mini-SWE-agent and 9 for Trae agent.
TABLE II RQ2 AND RQ3: RE-FETCH RATES UNDER DELAYED AND IMMEDIATE DELETION, AND COSTS UNDER DELAYED DELETION WITH FLAT AND CACHING-AWARE PRICING, AS RATIOS TO THE UNCOMPRESSED RUNS.
| Scope | Granul. | Del% | Mini-SWE-agent | Trae agent | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Re-fetch | Cost | Re-fetch | Cost | |||||||
| Delay | Imm. | Flat | Cache | Delay | Imm. | Flat | Cache | |||
| Reasoning | Turn | 25 | 1.0 | 1.0 | 0.92 | 1.12 | 0.9 | 1.0 | 0.90 | 1.05 |
| 50 | 1.0 | 1.1 | 0.93 | 1.06 | 1.0 | 0.9 | 0.85 | 1.11 | ||
| 75 | 1.2 | 1.1 | 0.84 | 1.23 | 1.0 | 1.2 | 0.80 | 1.11 | ||
| 100 | 1.1 | 1.9 | 0.99 | 1.44 | 0.9 | 1.9 | 0.82 | 1.22 | ||
| Token | 25 | 1.0 | 1.0 | 1.05 | 1.35 | 0.7 | 0.9 | 0.84 | 1.16 | |
| 50 | 1.1 | 1.1 | 0.87 | 1.24 | 0.8 | 1.2 | 0.74 | 1.09 | ||
| 75 | 1.1 | 1.5 | 0.84 | 1.48 | 1.0 | 1.5 | 0.74 | 1.19 | ||
| Tool output | Turn | 25 | 1.2 | 1.2 | 0.97 | 1.03 | 1.5 | 2.1 | 0.88 | 1.04 |
| 50 | 1.3 | 1.5 | 0.98 | 1.11 | 2.1 | 3.1 | 0.80 | 1.09 | ||
| 75 | 1.5 | 1.5 | 0.85 | 1.19 | 2.9 | 5.0 | 0.92 | 1.37 | ||
| 100 | 1.6 | 1.0 | 0.71 | 1.20 | 4.6 | 5.4 | 1.01 | 1.67 | ||
| Token | 25 | 1.4 | 1.4 | 0.94 | 1.22 | 1.6 | 3.8 | 1.10 | 1.48 | |
| 50 | 1.6 | 1.5 | 1.07 | 1.43 | 2.7 | 5.1 | 1.26 | 1.69 | ||
| 75 | 1.7 | 1.6 | 1.04 | 1.48 | 3.7 | 7.0 | 1.05 | 1.70 | ||
| Both | Turn | 25 | 1.2 | 1.3 | 1.05 | 1.14 | 1.7 | 2.7 | 1.03 | 1.27 |
| 50 | 1.3 | 1.6 | 0.79 | 1.03 | 2.5 | 4.4 | 0.97 | 1.31 | ||
| 75 | 1.7 | 2.1 | 0.86 | 1.31 | 4.0 | 6.5 | 1.13 | 1.74 | ||
| 100 | 2.4 | 2.2 | 0.98 | 1.97 | 7.5 | 10.6 | 1.12 | 3.36 | ||
| Token | 25 | 1.2 | 1.3 | 1.11 | 1.56 | 2.4 | 4.5 | 0.97 | 1.43 | |
| 50 | 1.5 | 1.8 | 1.08 | 1.46 | 3.9 | 8.8 | 1.61 | 2.31 | ||
| 75 | 2.0 | 2.4 | 1.10 | 2.01 | 6.3 | 9.3 | 3.73 | 4.94 | ||
A ratio of 2.0 indicates twice the baseline re-fetch rate. Bold marks a statistically significant difference from the baseline.
Scope. Deletion scope affects re-fetching similarly to the pattern for run length in Section IV. Deleting both scopes triggers the most re-fetching, followed by tool output, then reasoning. At matched amounts and granularities, deleting both scopes yields higher re-fetch ratios than deleting tool output in all Trae agent comparisons and most Mini-SWE-agent comparisons.
Granularity. Agents re-fetch more under token-level deletion than under turn-level deletion in 21 of the 24 pairs that delete tool output or both, at the same scope and amount, and the other three are ties.
Amount. Section IV shows that run length increases with the percentage of tool output deleted. The additional turns include repository exploration, testing, and editing. Table II identifies re-fetching as one source of additional work that increases when deleting tool output. Under delayed turn-level deletion, Trae agent's ratio grows from at to at for both, and from to for tool output. The corresponding ratios at deletion for Mini-SWE-agent are and , respectively. Of the 28 evaluations that delete tool output at each timing, all 28 show a significant increase with the delay and 27 without it. The exception, Mini-SWE-agent at of tool output without the delay , never receives any tool output and explores unread content rather than re-reading: in its 41 capped runs, of all calls read content not seen before, are scripts, and re-read content already seen.
Timing. Immediate deletion produces significantly higher re-fetch rates than delayed deletion in 25 of the 42 paired bootstrap comparisons, 18 of 21 for Trae agent and seven of 21 for Mini-SWE-agent. The increase is largest in the token-level rows. Trae agent goes from with the delay to without it at of tool output, and from to at of both. For Mini-SWE-agent, tool output re-fetch ratios differ little between timings below deletion. The highest value in the table, , is Trae agent under immediate turn-level deletion of both at .
TABLE III RQ2: PERCENTAGES OF RETAINED AND DELETED FILE-READ OUTPUTS SUBSEQUENTLY RE-FETCHED UNDER TURN-LEVEL DELETION. EACH CELL LISTS THE RETAINED-OUTPUT PERCENTAGE FOLLOWED BY THE DELETED-OUTPUT PERCENTAGE.
| Scope | % Deleted | Mini-SWE-agent | Trae agent | ||
|---|---|---|---|---|---|
| Delayed | Immediate | Delayed | Immediate | ||
| Uncompressed | 13% | 9% | |||
| Tool output | 25 | 11% / 22% | 14% / 30% | 9% / 28% | 9% / 45% |
| 50 | 12% / 18% | 10% / 25% | 9% / 27% | 7% / 36% | |
| 75 | 11% / 17% | 8% / 16% | 7% / 21% | 7% / 28% | |
| Both | 25 | 12% / 23% | 12% / 28% | 9% / 37% | 10% / 50% |
| 50 | 11% / 22% | 12% / 27% | 9% / 27% | 7% / 38% | |
| 75 | 8% / 19% | 9% / 19% | 8% / 24% | 6% / 24% | |
Reasoning. Delayed reasoning deletion produces no consistent increase in re-fetching. Re-fetch ratios range from 0.7 to 1.2 across the 14 evaluations, and the four significant differences from the baseline are small, point in opposite directions (two below one, two above one), and show no trend with deletion percentage. Two immediate configurations stand out. In both agents, turn-level deletion of reaches , and token-level deletion of reaches . Under both granularities, removing the latest reasoning increases refetching; removing reasoning older than two turns does not.
Deleted versus retained outputs. A higher re-fetch rate can mean that the agent retrieves deleted content again or that it retrieves both deleted and retained content more. To distinguish these explanations, we compare subsequent retrieval of deleted and retained outputs within each run. Under turn-level deletion, independent random draws determine retention. Assignment therefore does not systematically select outputs by age, file, or position, supporting interpretation of differences in subsequent retrieval as responses to deletion. Table III gives the percentage of kept and of deleted reads whose output is refetched later, for the turn-level configurations that delete tool output or both at to .
In every evaluated configuration, kept outputs are re-fetched about as often as in the uncompressed runs. The extra refetches are of the deleted content. Deleted outputs are refetched 1.5 to five times as often as kept ones, and the paired bootstrap analysis finds the difference significant in all but one of the 24 evaluations, Mini-SWE-agent at of tool output with the delay. The deletion configurations do not distinguish a needed output from an unneeded one, so some of what they delete is content the agent still needs. The comparison supports selective retrieval of deleted content rather than a general increase in retrieval of retained content. This pattern is consistent with the longer runs and mostly preserved effectiveness under turn-level tool output deletion in Section IV.
The shape of a run. Tool calls per turn range from 0.92 to 1.12 times the baseline across all 84 evaluations. Additional refetches therefore primarily appear as additional turns. Deletion scope also affects reasoning length, measured in words per turn. Deleting tool output shortens the reasoning. Immediate tool output deletion at the two highest amounts shortens it by about 50% while run lengths reach four times the baseline. Under delayed tool output deletion, reasoning length remains close to the baseline. Reasoning deletion lengthens it to twice the baseline with the delay, and five times without it, with turn counts below 100% deletion staying close to the baseline. The effect of deleting both scopes depends on the granularity. Immediate turn-level deletion of 100% shortens reasoning by over 50%, similar to tool output deletion. Token-level deletion raises reasoning per turn to as much as seven times the baseline for Mini-SWE-agent and four times for Trae agent, alongside run lengths of three to four times the baseline. The reasoning length of every configuration is in the replication package.
How far back the agent reaches. Lastly, we measure on the uncompressed runs how far back an agent reaches for content. We exclude the 19 Trae agent runs that loop (Section III-C), since their repeated reads place every re-fetch one turn apart. Re-fetches tend to reach further back than edits. The median interval between a read and its re-fetch is twelve turns for Trae agent and six for Mini-SWE-agent, whereas an edit follows the last read of the file by a median of four turns and one turn. A two-turn delay therefore leaves 40% of Trae agent's edits and 68% of Mini-SWE-agent's with their last read intact, but only 9% and 23% of their re-fetches. A ten-turn delay would leave 69% and 92% of the edits and 44% and 66% of the re-fetches intact. These percentages describe the uncompressed agents, and since deletion may change behavior, they do not predict the effect of a longer delay under deletion. They show that retrieval reaches well beyond the two-turn window, motivating evaluation of longer retention windows.
Answer to RQ2. Tool output deletion raises re-fetch rates up to with the delay and without it. The extra re-fetches are of the deleted content, while refetching of retained content stays at the uncompressed baseline. Delayed reasoning deletion produces no consistent increase, and immediate reasoning deletion increases re-fetching only at the highest percentages. The extra refetches appear as turns, and they reach back a median six to twelve turns, well beyond the two-turn delay.
Implications for future work. Future deletion studies should distinguish dependence on retained context from the ability to recover missing information. Selective re-fetching shows why successful execution after deletion does not establish that the removed content is unnecessary. This finding calls for joint evaluation of retention and retrieval, including what remains accessible and the effort required to recover it. Trace analyses should connect repeated reads to the content deleted and subsequent actions, distinguishing recovery of missing observations from unproductive loops. Since re-fetches reach well beyond the two-turn delay, longer retention windows and memory-management approaches that coordinate what stays in the prompt with what remains retrievable are worth evaluating.
VI. RQ3: How Does Deletion Change Cost?
Table II reports, for each delayed configuration and agent, estimated cost relative to the uncompressed baseline under flat and caching-aware pricing (statistically significant differences in bold). Ratios of 0.80 and 1.20 indicate costs 20% below and above the baseline. The table focuses on delayed configurations because most evaluations preserve tasks solved without a statistically significant decrease. Immediate configurations produce larger decreases, which complicates interpretation of per-run cost. The timing paragraph below reports their cost results, while analysis of cost per task solved remains future work. All data is available in the replication package.
A. Cost Under Flat and Caching-Aware Pricing
Pricing. Under flat pricing, estimated costs are below the baseline in 26 of 42 evaluations, six showing significant cost reductions and three being significantly more expensive. Under caching-aware pricing, every evaluation has an estimated cost ratio above one, significantly in 26 of 42. The configurations closest to parity have estimated costs no more than 5% above the uncompressed baseline. Three of the six significant flat-pricing savings become significant increases, among them Mini-SWE-agent under turn-level deletion of all tool output, approximately 30% below the baseline under flat pricing and 20% above it under caching-aware pricing. None of the six shows a significant decrease in tasks solved.
Scope. Reasoning deletion accounts for four of the significant flat-pricing savings, all four of Trae agent's, with estimated costs up to 26% below the baseline. Under caching-aware pricing, all 14 of its ratios exceed one, six significantly. Tool output deletion produces one significantly lower cost under flat pricing, whereas nine of its 14 evaluations have significantly higher costs under caching-aware pricing. Deleting both scopes produces the largest increase. Under caching-aware pricing, 11 of its 14 evaluations are significantly more expensive, reaching approximately five times the uncompressed cost for Trae agent under token-level deletion of 75%, whose median run hits the cap (Section IV).
Granularity. Cost differences between granularities follow the pattern observed for run length. Under caching-aware pricing, turn-level deletion costs no more than token-level deletion in 17 of the 18 matched pairs. The remaining pair differs by 0.02 in cost ratio.
Timing. Without the delay, one evaluation is cheaper under flat pricing and none under caching-aware pricing: Trae agent under turn-level deletion of 100% of both scopes, for which every run repeatedly lists the root directory until reaching the cap, sending approximately half as many tokens as the baseline and solving no tasks. Most evaluations of immediate configurations are significantly more expensive, 29 of the 42 evaluations under flat pricing and 32 under caching-aware pricing. Immediate reasoning deletion mostly preserves tasks solved, supporting cost comparisons with delayed reasoning deletion. None of the 14 evaluations is cheaper under either pricing model. Under caching-aware pricing, all 14 ratios exceed one and seven increases are significant. Immediate turn-level deletion of all reasoning reaches 1.7 times the baseline cost for Trae agent and 4 times the baseline cost for Mini-SWE-agent.
B. Source of the Cost Difference
Token volume and billing. Token counts fall below the baseline in 31 of the 42 delayed evaluations, by up to one third. Most of the other eleven use token-level deletion, where longer runs offset the tokens removed from each prompt. Tokens billed at the full input price increase in all 42 evaluations, ranging from approximately 1.25 to nearly 10 times the baseline count. Re-billed tokens account for this increase (Section III-C). Every rewrite re-bills the prompt from the first changed token onwards. Flat pricing charges all prompt tokens at the input price and does not represent changes in cache reuse. Caching-aware pricing accounts for both the loss of cache discounts and additional tokens from longer runs.
Cost components. The cost decomposition separates four components: cached input, new input, re-billed input, and output. Re-billed tokens incur the new-input price but form a separate component to identify the effect of prefix invalidation. Averaged over the five uncompressed runs, cached, new-input, and output tokens account for 50%, 14%, and 36% of Mini-SWE-agent's cost and 52%, 14%, and 34% of Trae agent's, with no re-billed cost in either baseline.
Deletion reduces the cached-input component for most Mini-SWE-agent configurations. For Trae agent, cached-input cost decreases under reasoning deletion but increases under tool output deletion, where additional calls offset the reduction in retained content. New-input cost stays close to the baseline, and re-billed input appears alongside it. Under turn-level deletion, re-billed cost increases with deletion percentage because only selected turns invalidate the prefix. Under token-level deletion, every call with an eligible turn invalidates the prefix. At 25%, the re-billed component of token-level deletion is about five times that of turn-level deletion.
The output component stays close to the uncompressed level for Mini-SWE-agent and grows for Trae agent, whose runs lengthen most. Re-billed tokens contribute to every configuration's estimated cost increase, whereas reductions in cached-input cost provide limited or no offset. Under tool output deletion, longer runs further increase token costs. Delayed reasoning deletion produces no consistent increase in re-fetching or turns (Section V), yet re-billing offsets the reduction in retained tokens.
What this means for compression. Token counts decrease in 31 of the 42 delayed evaluations, and flat-pricing cost ratios fall below one in 26. Our deletion configurations use no model, selector, or summary, yet token counts and flat pricing already suggest savings that the caching-aware model does not confirm. Under the caching-aware model, none of the 42 delayed evaluations have lower estimated costs than the baseline, and 26 have significantly higher estimated costs. Any approach that replaces an old turn breaks the cache at that turn as a deletion does, so we expect a compressor that rewrites before every call to pay the same re-billing, and one that rewrites once every several calls to pay it less often.
Answer to RQ3. With the two-turn delay, deletion is significantly cheaper than the uncompressed runs in six of 42 evaluations of delayed configurations under flat pricing and in none under caching-aware pricing, where 26 evaluations are significantly more expensive. The removed content otherwise qualifies for the cached-input price, while each rewrite incurs full input pricing from the first change onward. Under delayed reasoning deletion, re-billing offsets the reduction in retained tokens. Under tool output deletion, additional turns and completions further increase cost. We find that token counts and flat pricing overstate what deletion saves, so a compression approach should be evaluated against the uncompressed agent with its prefix cache.
Implications for future work. Our cost results call for studies on memory management that reduce total execution costs while preserving effectiveness under caching-aware pricing. Evaluations should compare against an uncompressed baseline with the same cache assumptions and account for retrieval turns, generated reasoning, cache invalidation, and compression overhead. Reporting tasks solved alongside cost, supplemented by cost per task solved, would clarify whether apparent savings accompany effectiveness losses. Future work should also vary rewrite position and frequency to test whether less frequent rewriting or preserving longer prefixes lowers total cost after accounting for changes in agent behavior.
VII. Threats to Validity
A threat to the internal validity of our study is the variation between runs. We use temperature zero, but LLM inference is not deterministic even then [29], and each configuration runs once per agent and task, with one random draw of what to delete. The reference uses five uncompressed runs per task and agent, and the paired bootstrap resamples the 100 tasks. The confidence intervals quantify task-sampling uncertainty only and exclude variation across repeated intervention runs or random deletion draws. Each metric and timing also involves 42 paired comparisons, which raises the multiple-comparisons problem. Our conclusions are based on patterns across the grid rather than on any single test, but as a sensitivity analysis, we also apply Holm's correction within each family of 42 tests. Fewer individual results remain significant, but the reported trends hold. The results also depend on the experimental settings. We use the agents’ default prompts and tools, a 200-turn cap, and a two-turn delay taken from AgentDiet [2]. Different settings require additional evaluation. Another threat to internal validity is data leakage [30, 31]. The repositories and their fixes are public, so the model may recall them, which would inflate the number of tasks solved. At the same deletion percentage, reasoning deletion removes far fewer tokens than deletion of tool output or both scopes, confounding scope with the number of tokens removed.
A threat to external validity is the generalizability of our findings to other models, agents, tasks, and compression approaches. We use one open-weight model, two agents with contrasting tool interfaces, and a 100-task subset of SWE-bench Verified. The selected grid requires 9,400 runs and over 2,000 GPU hours, limiting the feasible benchmark size. Exact prefix caching invalidates cached states after a modified token, but the resulting cost savings depend on provider pricing and cache availability. The deletion configurations isolate the effects of random removal but do not represent learned selection or summarization approaches. Learned selection might reduce information loss and re-fetching relative to random deletion. Infrequent rewriting also reduces the frequency of prefix invalidation. Neither is evaluated here. An approach that rewrites an old turn still invalidates prefix reuse from the first change onward under the studied cost model.
Passing tests is a proxy for correctness but does not establish that a patch is the intended fix, threatening construct validity. We do not manually validate all 9,400 patches. Another threat to construct validity is the cost model. The caching-aware model omits cache-write premiums and minimum prefix lengths and assumes that every matching prefix is available. Expiry and eviction also limit this assumption. These simplifications can underestimate absolute costs. Their effects on the baseline and deletion configurations need not be equal, so the model does not establish provider-independent relative cost increases. A last threat is the re-fetch measure. The line-overlap measure misses known content returned in a different form, such as combined output from several source files. We assess sensitivity to the 80% threshold by repeating the analysis at 50% and 90%. The ratios differ, but the same configurations show the largest effects.
VIII. RELATED WORK
Context management for agents. Approaches that reduce what an agent resends range from rules that mask old observations [10, 16], through models that select what to remove [2, 17, 32, 33], to agents trained to manage their own context [3, 4]. More generally, long-horizon agents compress their observations and history [34, 35], and prompt compression removes low-information tokens from a single prompt [36, 37], which resembles our token-level deletion except that it chooses tokens by their information content rather than at random. These papers propose context-management approaches and evaluate tasks solved and tokens processed. Our study varies the scope, granularity, amount, and timing of random deletion to characterize the effects of these design choices and provide a baseline for context-management approaches.
Trajectory reduction. Empirical work compares observation masking with summarization [16] and prunes specific content such as reasoning [38]. Four recent studies are close to ours. Satish et al. [39] vary compression primitives from deployed agents across nearly 35,000 runs and report success, tokens, latency, and estimated cost. Weinberger and Hozez [6] measure provider-billed costs and find that removing 38% of tool output tokens coincided with a 6.8% higher cost. Liu [5] isolates the cost of reacquiring dropped states and shows that task completion can miss it. Franke [33] lets agents evict tool results to a recoverable archive and notes that such edits can invalidate cached prefixes. Our study complements these analyses by randomly varying deletion scope, granularity, amount, and timing, linking re-fetches to deleted versus retained outputs, and using complete prompt logs to reconstruct prefix invalidation and explain estimated cost changes.
Behavior of agents. Recent work examines task success alongside common agent actions and recurring misbehavior patterns [14, 40, 41], which can guide future agent runs [42]. Other work studies how users interact with agents and how that impacts the generated code [43]. Our work, especially RQ2, inspects trajectories to understand how agents behave after trajectory reduction.
IX. CONCLUSION
This paper studies how trajectory deletion affects agent effectiveness, behavior, and estimated execution cost. With a two-turn delay, 37 of 42 evaluations show no significant decrease in tasks solved. However, 21 evaluations have significantly longer runs, and the additional re-fetches primarily recover deleted tool output. Immediate tool output deletion causes larger decreases in tasks solved than delayed deletion, particularly at token-level granularity. The inspected traces suggest that fragmented outputs sometimes induce attempts to repair apparently corrupted files. Token reductions do not imply lower estimated execution costs. Deletion yields estimated savings under flat pricing, but no delayed evaluation is cheaper under caching-aware pricing, and 26 of 42 across both agents are significantly more expensive than the uncompressed baseline. Under the caching-aware model, deletion removes content that otherwise qualifies for discounted cached-input pricing, while each rewrite re-bills the suffix at the full input price.
The results have three practical implications. The tested agents rely on recent tool outputs, supporting retention of these outputs until the agent uses them. When recent tool output must be removed, turn-level deletion generally preserves more tasks solved than token-level deletion in the studied setting. Compression approaches require comparison with an uncompressed baseline under caching-aware pricing, because token counts and flat pricing overstate the savings observed here.
The findings motivate evaluation of longer retention delays, selection based on observed reuse, and less frequent history rewriting. Batched rewriting still invalidates the prefix, so its net savings require evaluation and cannot be inferred from reduced rewrite frequency alone.
Data Availability. The replication package [12] contains all runs, every deleted turn’s original text, and analysis code.
REFERENCES
[1] C. E. Jimenez, J. Yang, A. Wettig, S. Yao, K. Pei, O. Press, and K. R. Narasimhan. "SWE-Bench: Can Language Models Resolve Real-World GitHub Issues?" In: The Twelfth International Conference on Learning Representations (ICLR). 2024. URL: https://openreview.net/forum?id=VTF8yNQM66.
[2] Y.-A. Xiao, P. Gao, C. Peng, and Y. Xiong. "Reducing Cost of LLM Agents with Trajectory Reduction." In: Proceedings of the ACM on Software Engineering 3.FSE (2026), FSE056:1241–FSE056:1263. DOI: 10.1145/3797084.
[3] S. Liu, B. Jiang, J. Yang, Y. Li, J. Guo, X. Liu, and B. Dai. "Context as a Tool: Context Management for Long-Horizon SWE-Agents." In: Findings of the Association for Computational Linguistics: ACL 2026. Association for Computational Linguistics, 2026, pp. 20604–20617. DOI: 10.18653/v1/2026.findings-acl.1032.
[4] X. Zhang, L. Zheng, C. Du, B. An, and X. Dong. AutoCompact: Learning When to Compact Context in Long-Horizon Coding Agents. 2026. DOI: 10.48550/arXiv.2610.02163. arXiv:2610.02163.
[5] S. Liu. What Does Context Compression Cost an Agent? Interaction Costs Unrevealed by Task-Completion Metrics. 2026. DOI: 10.48550/arXiv.2608.16370. arXiv: 2608.16370.
[6] S. Weinberger and A. Hozez. Token Reduction Is Not Cost Reduction. 2026. DOI: 10.48550/arXiv.2607.12161. arXiv:2607.12161.
[7] OpenAI. Prompt Caching. URL: https://developers.openai.com/api/docs/guides/prompt-caching. 2026.
[8] Anthropic. Prompt Caching. URL: https://platform.claude.com/docs/en/build-with-claude/prompt-caching. 2026.
[9] B. Xu et al. TokenPilot: Cache-Efficient Context Management for LLM Agents. 2026. DOI: 10.48550/arXiv.2606.17016. arXiv: 2606.17016.
[10] J. Yang, C. Jimenez, A. Wettig, K. Lieret, S. Yao, K. Narasimhan, and O. Press. "SWE-Agent: Agent-Computer Interfaces Enable Automated Software Engineering." In: Advances in Neural Information Processing Systems 37. Neural Information Processing Systems Foundation, Inc. (NeurIPS), 2024, pp. 50528–50652. DOI: 10.52202/079017-1601.
[11] P. Gao et al. Trae Agent: An LLM-Based Agent for Software Engineering with Test-Time Scaling. 2025. DOI: 10.48550/arXiv.2507.23370. arXiv: 2507.23370.
[12] F. Vallecillos-Ruiz, I. Bouzenia, M. Pradel, and L. Moonen. Replication Package for “The Hidden Costs of Forgetting: A Study of Trajectory Deletion in Software Engineering Agents”. URL: https://figshare.com/s/72fce511c3ebe14d9dde. 2026.
[13] X. Wang et al. “OpenHands: An Open Platform for AI Software Developers as Generalist Agents.” In: International Conference on Learning Representations. Vol. 2025. 2025, pp. 65882–65919. URL: https://proceedings.iclr.cc/paper_files/paper / 2025 / hash / a4b6ad6b48850c0c331d1259fc66a69c - Abstract-Conference.html.
[14] I. Bouzenia and M. Pradel. “Understanding Software Engineering Agents: A Study of Thought-Action-Result Trajectories.” In: IEEE/ACM International Conference on Automated Software Engineering (ASE). 2025, pp. 2846–2857. DOI: 10.1109/ASE63991.2025.00234.
[15] L. Bai, Z. Huang, X. Wang, J. Sun, R. Mihalcea, E. Brynjolfsson, A. Pentland, and J. Pei. How Do AI Agents Spend Your Money? Analyzing and Predicting Token Consumption in Agentic Coding Tasks. 2026. DOI: 10.48550/arXiv.2604.22750. arXiv: 2604.22750.
[16] T. Lindenbauer, I. Slinko, L. Felder, E. Bogomolov, and Y. Zharov. "The Complexity Trap: Simple Observation Masking Is as Efficient as LLM Summarization for Agent Context Management." In: NeurIPS 2025 Fourth Workshop on Deep Learning for Code. 2025. URL: https://openreview.net/forum?id=OHVzruJl5k.
[17] Z. Zeng, Y. Li, R. Xie, W. Ye, and S. Zhang. “AttnCompress: Dynamic Attention-Guided Trajectory Compression for Software Engineering Agents.” In: Proceedings of the ACM on Software Engineering 3.ISSTA (2026), ISSTA058:1331–ISSTA058:1353. DOI: 10.1145/3832149.
[18] C. Smith. OpenHands Context Condensation for More Efficient AI Agents. URL: https://hub.openhands.dev/blog/openhands-context-condensation-for-more-efficient-ai-agents. 2025.
[19] Anthropic. Context Editing. URL: https://platform.claude.com/docs/en/docs/build-with-claude/context-editing. 2026.
[20] L. Zheng et al. “SGLang: Efficient Execution of Structured Language Model Programs.” In: Advances in Neural Information Processing Systems. Vol. 37. Curran Associates, Inc., 2024, pp. 62557–62583. DOI: 10.52202/079017-2000.
[21] vLLM Project. Automatic Prefix Caching. URL: https://docs.vllm.ai/en/latest/design/prefix_caching.html. 2026.
[22] SWE-agent Team. History Processors. URL: https://swe-agent.com/latest/reference/history_processor_config/. 2026.
[23] DeepSeek-AI et al. DeepSeek-V4: Towards Highly Efficient Million-Token Context Intelligence. 2026. DOI: 10.48550/arXiv.2606.19348. arXiv: 2606.19348.
[24] Anthropic. Pricing. URL: https://platform.claude.com/docs/en/about-claude/pricing. 2026.
[25] OpenAI. Pricing. URL: https://developers.openai.com/api/docs/pricing. 2026.
[26] DeepSeek. Models & Pricing. URL: https://api-docs.deepseek.com/quick_start/pricing/. 2026.
[27] Google. Gemini Developer API Pricing. URL: https://ai.google.dev/gemini-api/docs/pricing. 2026.
[28] W. Kwon, Z. Li, S. Zhuang, Y. Sheng, L. Zheng, C. H. Yu, J. Gonzalez, H. Zhang, and I. Stoica. "Efficient Memory Management for Large Language Model Serving with Page-dAttention." In: Symposium on Operating Systems Principles. ACM, 2023, pp. 611–626. DOI: 10.1145/3600006.3613165.
[29] S. Ouyang, J. M. Zhang, M. Harman, and M. Wang. “An Empirical Study of the Non-Determinism of ChatGPT in Code Generation.” In: ACM Transactions on Software Engineering and Methodology 34.2 (2025), pp. 1–28. DOI: 10.1145/3697010.
[30] T. Prathifkumar, N. S. Mathews, and M. Nagappan. Does SWE-Bench-Verified Test Agent Ability or Model Memory? 2025. DOI: 10.48550/arXiv.2512.10218. arXiv: 2512.10218.
[31] S. Liang, S. Garg, and R. Z. Moghaddam. “The SWE-Bench Illusion: When State-of-the-Art LLMs Remember Instead of Reason.” In: IEEE/ACM 48th International Conference on Software Engineering: Software Engineering in Practice. ACM, 2026, pp. 395–405. DOI: 10.1145/3786583.3786882.
[32] Y. Wang, Y. Shi, M. Yang, R. Zhang, S. He, H. Lian, Y. Chen, S. Ye, K. Cai, and X. Gu. SWE-Pruner: Self-Adaptive Context Pruning for Coding Agents. 2026. DOI: 10.48550/arXiv.2601.16746. arXiv: 2601.16746.
[33] J.-P. Franke. Agent-Controlled Forgetting for Tool-Using Agents: Reversible Context Curation in Practice. 2026. DOI: 10.48550/arXiv.2610.10590. arXiv: 2610.10590.
[34] M. Kang, W.-N. Chen, D. Han, H. A. Inan, L. Wutschitz, Y. Chen, R. Sim, and S. Rajmohan. "ACON: Optimizing Context Compression for Long-Horizon LLM Agents." In: Forty-Third International Conference on Machine Learning. 2026. URL: https://openreview.net/forum?id=5EmOOLtH5P.
[35] H. Zhang and Z. Sun. AGORA: Adapter-Grounded Observation-Action Retention for Inference-Free Prompt Compression in LLM Agents. 2026. DOI: 10.48550/arXiv.2605.26596. arXiv: 2605.26596.
[36] H. Jiang, Q. Wu, C.-Y. Lin, Y. Yang, and L. Qiu. "LLMLingua: Compressing Prompts for Accelerated Inference of Large Language Models." In: Conference on Empirical Methods in Natural Language Processing. Ed. by H. Bouamor, J. Pino, and K. Bali. Association for Computational Linguistics, 2023, pp. 13358–13376. DOI: 10.18653/v1/2023.emnlp-main.825.
[37] Z. Pan et al. “LLMLingua-2: Data Distillation for Efficient and Faithful Task-Agnostic Prompt Compression.” In: Findings of the Association for Computational Linguistics: ACL 2024. Ed. by L.-W. Ku, A. Martins, and V. Srikumar. Association for Computational Linguistics, 2024, pp. 963–981. DOI: 10.18653/v1/2024.findings-acl.57.
[38] M. Wang, F. Luo, B. Wang, G. Yao, Y. Guo, C. Ning, H. Chen, Y. Ma, and J. Han. When Can Agents Forget Their Reasoning? ICLR for Long-Horizon Agent Context Compression. 2026. DOI: 10.48550/arXiv.2609.29875. arXiv: 2609.29875.
[39] R. Satish, P. Sinha, A. Kawada, and N. J. Yadwadkar. Beyond Token Savings: A Systematic Study of Context Compression in LLM Agents. 2026. DOI: 10.48550/arXiv.2609.32961. arXiv:2609.32961.
[40] S. Liu, Y. Chen, R. Krishna, S. Sinha, J. Ganhotra, and R. Jabbarvand. "Process-Centric Analysis of Agentic Software Systems." In: Proceedings of the ACM on Programming Languages 10.OOPSLA1 (2026), 163:1961–163:1988. DOI: 10.1145/3798271.
[41] I. Ceka, H. Mitchell, S. Pujar, L. Buratti, S. Ramji, J. Yang, G. Kaiser, and B. Ray. “Understanding Automated Program Repair Agents through the Lens of Traceability: An Empirical Study.” In: Proceedings of the ACM on Software Engineering 3.ISSTA (2026), ISSTA194:4450–ISSTA194:4473. DOI: 10.1145/3832285.
[42] R. Nanda, C. Maddila, S. Jha, E. M. Khan, M. Paltenghi, and S. Chandra. "Wink: Recovering from Misbehaviors in Coding Agents." In: 3rd ACM International Conference on AI-Powered Software. ACM, 2026, pp. 208–217. DOI: 10.1145/3805760.3814911.
[43] J. Baumann, V. Padmakumar, X. Li, J. Yang, D. Yang, and S. Koyejo. "SWE-Chat: Coding Agent Interactions from Real Users in the Wild." In: Third Conference on Language Modeling. 2026. URL: https://openreview.net/forum?id=KMAxjswrFe (visited on Oct. 23, 2026).