Manuscript Offprint

arXiv:2608.29363

TRACER: Per-Tool Context Retention for LLM Agents via Consequence-Attributed Reinforcement Learning

Ziqi Lin, Ye Wu, Mengying Yang, Xu Liu, Yizhou Liu, Qiang Ke, Qin Guo

Abstract

Enterprise data agents answer business queries by chaining many tool calls over multiple reasoning steps, routinely accumulating hundreds of thousands of context tokens per session. Existing compression strategies typically allocate retention budgets without accounting for the downstream consequences of removing individual tool outputs. Aggressive compression may therefore trigger costly tool re-invocations that offset the initial savings. We call this the compression–consequence gap. To close it, we propose TRACER, which formulates compression as a sequential per-tool decision problem. A lightweight REINFORCE policy assigns query-conditioned retention ratios using only information available at each compression event. Its consequence-aware objective jointly accounts for task success, total token consumption, and post-compression tool re-invocations. To improve credit assignment, TRACER uses a learned outcome model to compare the predicted consequences of the selected retention ratio with those of fully retaining each tool output. On held-out production queries across three compressor backends, TRACER reduces total token consumption by 29–46% relative to keeping all context while maintaining comparable or higher task success. Compared with a tool-type-conditional static policy, TRACER provides an additional 15–18% of token savings. Interventional rollouts show that the learned per-tool credit scores correlate with measured single-tool consequences. The learned policy also yields positive savings when transferred across agent backbones and compressor architectures, and reduces token consumption by 18–25% on five held-out LOCA-bench environments. These results demonstrate the value of consequence-aware, per-tool context retention for improving the efficiency of long-horizon language agents.

1 Introduction

Enterprise data agents answer business questions by chaining tool calls over many reasoning steps (Yao et al. 2023; Schick et al. 2024). Because each tool output is appended to the context and never discarded, the working memory grows monotonically. A single SQL result alone can exceed ten thousand tokens, and a typical task spans five to ten such calls. The accumulated context therefore routinely reaches hundreds of thousands of tokens, exceeding model windows, exhausting cost budgets, and degrading reasoning through diluted attention. Therefore, context compression becomes essential.

Figure

Figure 1: The compression–consequence gap. Token cost falls as compression becomes more aggressive, but total cost also accounts for downstream re-invocations.

Existing compression methods operate at various granularities: token-level pruning (Jiang et al. 2023, 2024; Pan et al. 2024), turn-level summarization (Xu, Shi, and Choi 2024), and step-level dropping (Zhang and Sun 2026). Yet they all apply a uniform strategy across heterogeneous content. In an agentic session, tool outputs vary widely in downstream importance: a schema lookup may be referenced by every subsequent step, whereas a permission check is never revisited. What is needed is a query-conditioned, per-tool retention policy that allocates the token budget according to each output's future utility.

A deeper limitation is that existing methods evaluate compression in isolation. In an agentic loop, the model continues to act after compression. When a needed detail has been removed, the agent re-invokes the tool to recover it. For data agents, a single compensatory SQL call can consume tens of thousands of additional tokens. Because compression recurs as new outputs accumulate, such costs compound across steps. We call this mismatch between compression-time savings and downstream cost the compression–consequence gap, illustrated in Figure 1.

To close this gap we propose TRACER, a reinforcement-learning framework that dynamically determines the retention ratio for each tool output. The policy emits a continuous action per output, letting the token budget flow to outputs whose removal would trigger expensive recovery. The training reward combines task success, token efficiency, and the fraction of tools re-invoked after compression, so that savings purchased through costly recovery never yield a net gain. We train the policy with REINFORCE (Williams 1992) on full agent episodes.

A further challenge is credit assignment: each episode yields only one scalar reward across many per-tool decisions. To produce dense gradient signals, we introduce a learned outcome model that predicts per-tool consequences through single-tool counterfactuals.

Our contributions are:

• We formalize the compression–consequence gap as a sequential, per-tool decision problem whose reward explicitly prices downstream re-invocations.

• We propose a reinforcement learning framework that dynamically determines per-tool retention ratios, parameterized by a Beta distribution over a bounded action space.

• We introduce a learned attributor that predicts per-tool re-invocation consequences through single-tool counterfactuals. On semantic compressors, the attributor reduces both token consumption and re-invocation rate. On positional compressors, it protects task success by steering retention toward high-consequence outputs.

References (34)