Manuscript Offprint

arXiv:2610.35496

The Hidden Costs of Forgetting: A Study of Trajectory Deletion in Software Engineering Agents

Fernando Vallecillos-Ruiz, Islem Bouzenia, Michael Pradel, Leon Moonen

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:

  1. A systematic study of trajectory deletion in agents, quantifying how deletion scope, granularity, amount, and timing affect effectiveness, agent behavior, and execution costs.

  2. 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.

  3. 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.

References (33)