When Should an Agent Refresh? Adaptive Index Reuse for Efficient Long-Horizon Reasoning
Organizations: Mila – Québec Artificial Intelligence Institute · McGill University · Princeton University · Columbia University
Abstract
Language agents read code, tool output, and dialogue in contexts that grow at every step. Dynamic sparse attention lets a small indexer choose the earlier tokens each query attends to, but the indexer still scores the whole prefix at every layer. Cross-layer reuse methods such as IndexCache rerun the indexer at only some layers, with one fixed pattern for every input. In an agent, the relevant evidence can change abruptly when a traceback or test result arrives, so fresh selections matter more at some steps than at others. We propose Adaptive Index Reuse (AIR), which keeps IndexCache's execution and learns, for each segment of an agent episode, how many layers refresh their selection. A small controller reads signals from completed computation and the latest tool event, chooses a pattern from a nested library, and learns from terminal task reward under an expected compute budget. On Qwen3-4B-Instruct-2507 with a 128K context, AIR improves success over the strongest static schedule at matched cost on SWE-bench Verified (27.0% to 32.4%), Terminal-Bench 2.0, and three -bench domains, and it lowers time per successful task on all five. Across 50 backbone, context, and benchmark settings, it matches or exceeds that schedule in 44.
Figures & tables
| Success (%) | Min/success | ||||
| Benchmark | Static | AIR | Static | AIR | |
| SWE-bench Verified | 27.0 | 32.4 | 64.6 | 52.7 | |
| Terminal-Bench 2.0 | 22.5 | 24.7 | 61.9 | 56.4 | |
| retail | 53.3 | 57.2 | 14.1 | 13.1 | |
| airline | 42.5 | 46.5 | 14.1 | 12.9 | |
| telecom | 42.5 | 46.5 | 19.5 | 17.9 | |
| SWE-bench V. | Terminal-Bench | retail | airline | telecom | ||||||
| Method | Succ. | Min/s. | Succ. | Min/s. | Succ. | Min/s. | Succ. | Min/s. | Succ. | Min/s. |
| References | ||||||||||
| Native attention | 32.0 | 71.5 | 28.1 | 67.3 | 57.7 | 20.8 | 50.0 | 19.1 | 46.5 | 27.8 |
| All-refresh | 31.6 | 56.8 | 27.0 | 54.1 | 57.0 | 14.6 | 48.5 | 13.8 | 45.4 | 20.2 |
| Static allocation | ||||||||||
| Static ( ) | 27.0 | 64.6 | 22.5 | 61.9 | 53.3 | 14.1 | 42.5 | 14.1 | 42.5 | 19.5 |
| Variant | SWE | Term. | Retail | Airl. | Tel. |
|---|---|---|---|---|---|
| Static and state-free | |||||
| Greedy mask, | 27.0 | 22.5 | 53.3 | 42.5 | 42.5 |
| Staggered mask, | 24.0 | 21.3 | 50.4 | 40.5 | 40.1 |
| State-free mixture | 27.0 | 22.5 | 52.9 | 42.5 | 42.5 |
| Rules and local learning | |||||
| Event trigger | 29.4 | 23.6 | 53.3 | 48.0 | 41.7 |
Appendix figures & tables74 assets
Supplementary material from the paper’s appendix.
Appendix
| Axis | IndexCache | AIR |
|---|---|---|
| Layer action | Full or Shared | Full or Shared |
| Patterns | One deployed pattern | One pattern per budget, nested |
| Decision state | None (global) | Current agent segment |
| Pattern selection | Calibration LM loss | Calibration LM loss |
| Controller training | None | NLL-regret warm start, then terminal reward and cost |
| Compute target | Fixed retention ratio | Expected trajectory budget |
| Symbol | Meaning |
|---|---|
| Number of decoder layers ( for the primary backbone) | |
| , , | Ordered set of eligible layers, its size, and its first layer, which is always Full |
| Sequence length | |
| Indices for layers, agent steps, controller decisions, query positions, and key positions | |
| , | Selected positions per query, and |
| , | Fixed sink positions, and those available at query : |
| Block | Example fields | Requirement and cost treatment |
|---|---|---|
| Trajectory position | Segment index, context length, elapsed tool steps | Read from history at the boundary and normalize with training-only statistics |
| Interface event | Traceback, test result, file read, edit, API reply | Derive from the latest completed tool event, with no verifier or future outcome |
| Budget history | Previous budget, cumulative normalized cost, target gap | Compute only from executed actions and the frozen cost model |
| Cache state | Previous mask, distance to last Full layer, completed index age | Record source token, layer, timestamp, cache version, and action-history dependence |
| Lagged uncertainty | Completed-segment entropy and logit margin | Read retained logits from segment , with a missing flag at |
| Lagged index state | Completed-query overlap, score entropy, selection margin | Reuse statistics already produced in segment , with no new prefix scoring |
| Term | Floating-point operations | Bytes |
|---|---|---|
| for key projections, plus input normalization | written, plus amortized weight reads | |
| for query and gate projections; for dot products; for scaling, ReLU, and gating; for top- selection | of index keys read, plus amortized weight reads | |
| , | None | written at a Full layer or read at a Shared layer |
| , per segment | None | for the new mask when |
| , per segment | Entropy and margin over the retained final-token logits; PCA projections; overlap statistics | Logits, stored position sets, and projection weights read |
| , per segment (paid-probe comparison only) | For the appended tokens: embeddings and native layers below (standard per-token counts); at ; at ; entropy, margin, and overlap statistics | Weight and embedding reads; temporary writes and reads of layer inputs and index keys; prefix index keys of read; previous selection read |
| Checkpoint (role) | Params (total/ active) | Attention | / | Menu (fractions) | Supported context | Context caps | Reasoning mode | Precision |
|---|---|---|---|---|---|---|---|---|
| Qwen3-4B-Instruct-2507 (primary) | 4.0B | GQA, 32 Q / 8 KV heads | 36 / 36 | 3, 5, 9, 18, 36 (.08, .14, .25, .50, 1) | 262,144 native | 32K, 128K | non-thinking only | BF16 |
| Qwen3-1.7B (smaller) | 1.7B | GQA, 16 Q / 8 KV | 28 / 28 | 3, 4, 7, 14, 28 (.11, .14, .25, .50, 1) | 32,768 | 32K | hybrid; thinking off | BF16 |
| Qwen3-8B (larger) | 8.2B | GQA, 32 Q / 8 KV | 36 / 36 | 3, 5, 9, 18, 36 (.08, .14, .25, .50, 1) | 32,768; 131,072 with YaRN | 32K; 128K with YaRN | hybrid; thinking off | BF16 |
| Gemma-3-4B-it (second family) | 4B | 5 local (1,024) : 1 global; 8 Q / 4 KV | 34 / 5 | 1, 2, 3, 5 (.20, .40, .60, 1) | 128K (131,072) | 32K, 128K | none | BF16 |
| MiniMax-M2 (MoE extension) | 230B / 10B | GQA, 48 Q / 8 KV; 256 experts, 8 active | 62 / 62 | 6, 9, 16, 31, 62 (.10, .15, .26, .50, 1) | 196,608 | 32K, 128K | interleaved thinking, retained | FP8 weights |
| Qwen3-4B (release control) | 4.0B | GQA, 32 Q / 8 KV | 36 / 36 | as primary | 32,768; 131,072 with YaRN | 32K | hybrid; thinking off | BF16 |
| Population | Tasks (published / pinned) | Release, harness, and scorer | Endpoint | Role |
|---|---|---|---|---|
| SWE-bench Verified | 500 / 500 | Pinned dataset revision; official swebench harness (version and image digests fixed) | Official resolved rate: all FAIL_TO_PASS and PASS_TO_PASS tests pass | Primary claim; repair controller |
| Terminal-Bench 2.0 | 89 / 89 | Harbor, dataset [email protected] | Official task-verifier success | Transfer |
| retail | 115 / 114 | tau2-bench v0.2.0, base tasks | pass@1 and pass 4 over 4 trials | Transfer |
| airline | 50 / 50 | tau2-bench v0.2.0, base tasks | pass@1 and pass 4 over 4 trials | Transfer |
| telecom | 114 / 114 | tau2-bench v0.2.0, base tasks, default dual control | pass@1 and pass 4 over 4 trials | Transfer |
| Track | Methods | Extension rule | What must be controlled |
|---|---|---|---|
| Shared indexer | Anchor, static, periodic, staggered; mixture, temporal, event, staleness, supervised, bandit, AIR | Every accepted backbone | Frozen backbone and indexer; paired budget and state controls |
| Alternative indexer | Training-aware IndexCache; LatentIndex; MISA; HISA; LongCat CLI / HI | Every compatible injected indexer | Separate calibration; key, pooling, routing and training costs |
| Temporal adaptation | ReTopK with injected indexer | Every compatible injected indexer | Exact prefill; decode reuse; cache invalidation on prefix rebuild |
| Native-score methods | Published ReTopK; HShare; SFI; TidalDecode; Quest; Kascade | Qwen family; other families after adapter check | Different selector; own scores, caches and complete runtime charged |
| AIR composition | AIR with HISA, MISA-4 or LongCat HI | Where both components qualify | Own all-refresh reference, static library and fitted controller |
| Retrained backbone | Full LongCat Sparse Attention | Primary model only | Continual training and changed support; upfront cost disclosed |
| Backbone | Cap | Dev. % | Dev. cost | Deployment | Final R values | |
|---|---|---|---|---|---|---|
| Qwen3-1.7B | 32K | R=14 | 9.4 | 0.485 | Learned | 14 |
| Qwen3-4B-Instruct-2507 | 32K | R=18 | 23.0 | 0.485 | Learned | 18, 36 |
| Qwen3-4B-Instruct-2507 | 128K | R=18 | 23.0 | 0.485 | Learned | 18 |
| Qwen3-8B | 32K | R=18 | 30.6 | 0.485 | Learned | 18 |
| Qwen3-8B | 128K | R=18 | 30.6 | 0.485 | Learned | 18 |
| Gemma-3-4B-it | 32K | R=2 | 12.2 | 0.388 | Static R=2 | 2, 3 |
| All tasks | SWE-Gym | SWE-smith | ||||||
|---|---|---|---|---|---|---|---|---|
| Partition | Target | Tasks | Repos | Owners | Tasks | Share | Tasks | Share |
| Indexer training | 20% | 7,592 | 24 | 23 | 484 | 19.9% | 7,108 | 20.0% |
| Schedule calibration | 10% | 3,788 | 13 | 12 | 228 | 9.4% | 3,560 | 10.0% |
| Static selection | 10% | 3,801 | 12 | 12 | 251 | 10.3% | 3,550 | 10.0% |
| Controller training | 45% | 17,087 | 52 | 51 | 1,101 | 45.2% | 15,986 | 45.0% |
| Controller validation | 15% | 5,700 | 21 | 17 | 374 | 15.3% | 5,326 | 15.0% |
| Comparison | Held fixed | Question |
|---|---|---|
| Native vs. all-refresh sparse | Backbone, prompts, tools, limits | Does the injected sparse attention preserve agent capability? |
| All-refresh vs. static IndexCache | Backbone, indexer, , runtime | How much indexer work does static reuse remove, and at what quality? |
| Dynamic-ready vs. specialized static runtime | Masks and model outputs | What does keeping all index keys cost? |
| Anchor-only, periodic, staggered vs. greedy static | Refresh count | Does layer placement matter within a budget? |
| Static vs. mixture and temporal schedule | Action frequencies or time sequence | Does varying the budget without state help? |
| Heuristics vs. supervised router | State, menu | Do simple rules capture the allocation signal? |
| Method | What changes | Fixed | Calibration or training | Question |
|---|---|---|---|---|
| Native backbone | Unmodified attention, no indexer | Harness, decoding | None | Does the injected sparse attention preserve agent success? |
| All-refresh sparse | Every eligible layer Full | Indexer, | None | Upper end of refresh cost |
| Anchor-only ( ) | Only Full | Indexer, | None | Is any depth refresh needed? |
| Periodic depth mask | Full layers at a fixed interval, same | Refresh count | None | Does greedy placement matter? |
| Staggered depth mask | Full layers at seeded random positions, same | Refresh count | Preregistered mask seeds | Is the greedy pattern better than chance? |
| Static IndexCache | One greedy library pattern for the episode | Library | Greedy calibration search | Static reuse at each budget |
| Method | What changes | Fixed | Calibration or training | Question |
|---|---|---|---|---|
| Phase / model / index / model+index / full state | Controller inputs | Training recipe | As AIR | Which signals carry allocation value? |
| Decision interval | and model-call-only decisions | Menu | As AIR | Responsiveness vs. overhead |
| Library construction | Uniform, staggered, or independently searched patterns | Refresh counts | As AIR | Outer policy vs. inner schedule |
| Budget sweep | Ratio | Everything else | As AIR | Shape of the trade-off |
| Overhead | Feature blocks added one at a time | Everything else | As AIR | Does added overhead remove the saving? |
| Method | Source | Code we start from | Reproduction |
|---|---|---|---|
| Training-aware IndexCache | arXiv 2603.12201 v1 | THUDM/IndexCache 08d22d69 (DSA models only) | Ours, on injected indexer |
| LatentIndex | arXiv 2610.04635 v1 | None in the linked TransArch repository | Ours; targets are our indexer’s keys |
| MISA (head routing) | arXiv 2605.07363 v1 | TransArch, directory MISA_preprint (decode router differs from paper) | Ours, paper’s router |
| HISA | arXiv 2603.28458 v4 | TileLang example dsa_hisa ; SGLang branch hisa_pr (DSA models) | Ours, on injected indexer |
| ReTopK | arXiv 2607.27692 v1 | No public code | Published per-head version and indexer-based adaptation, both ours |
| LongCat cross-layer indexing | arXiv 2608.01662 v2 | Inference reuse in SGLang main 9ddbba5 ; distillation code unpublished | Adapter to our indexer and distillation, ours |
| Method | Calibration or training | Persistent state and invalidation | Extra cost counted |
|---|---|---|---|
| Training-aware IndexCache | Multi-layer distillation per pattern on indexer-training data | One indexer bank per pattern; caches as flat indexer | Adaptation compute; bank memory |
| LatentIndex | Closed-form reduced-rank ridge fit on fitting data | One latent per token per layer group; append-only | Latent projections, latent cache, per-layer selection, candidate rescoring (hierarchical) |
| MISA (head routing) | None; active heads preregistered | Block-pooled keys, appended per block | Router scoring and pooled-key maintenance |
| HISA | None | Block-pooled keys, appended per block | Block scoring, pooled-key maintenance |
| ReTopK | None; defaults fixed in advance | Per-head FIFO of queries and supports; cleared on prefix change | Similarity lookup, cache storage, candidate scoring, fallbacks, refreshes |
| LongCat cross-layer indexing | Cross-layer distillation of the indexer | As flat indexer | Distillation compute |
| Population | Tasks | Comparator | (pp) | |
|---|---|---|---|---|
| SWE-bench Verified | 500 | |||
| Terminal-Bench 2.0 | 89 | |||
| retail | 114 | |||
| airline | 50 | |||
| telecom | 114 |
| Backbone | Cap | Deployed type | Candidate | Success LB % | Cost UB |
|---|---|---|---|---|---|
| Qwen3-1.7B | 32K | Learned | s47_n12288 | 6.2 | 0.477 |
| Qwen3-4B-Instruct-2507 | 32K | Learned | s11_n12288 | 22.0 | 0.481 |
| Qwen3-4B-Instruct-2507 | 128K | Learned | s47_n12288 | 22.6 | 0.473 |
| Qwen3-8B | 32K | Learned | s11_n12288 | 27.2 | 0.476 |
| Qwen3-8B | 128K | Learned | s11_n6144 | 29.0 | 0.488 |
| Gemma-3-4B-it | 32K | Static fallback | static_r2 | 5.7 | 0.412 |
| Minutes per attempt (speedup over all-refresh, ) | |||||
| Method | SWE | Terminal | Retail | Airline | Telecom |
| References | |||||
| Native attention | 22.9 (0.78) | 18.9 (0.77) | 12.0 (0.70) | 9.6 (0.70) | 12.9 (0.71) |
| All-refresh sparse | 17.9 (1.00) | 14.6 (1.00) | 8.3 (1.00) | 6.7 (1.00) | 9.2 (1.00) |
| Strongest feasible static | 17.4 (1.03) | 13.9 (1.05) | 7.5 (1.11) | 6.0 (1.11) | 8.3 (1.10) |
| Alternative injected selectors | |||||
| Backbone | Caps | Speedup | Success change (pp) |
|---|---|---|---|
| Qwen3-4B-Instruct-2507 | 32K, 128K | 0.99–1.11 | to |
| Qwen3-8B | 32K, 128K ‡ | 1.00–1.13 | to |
| Gemma-3-4B-it | 32K † , 128K | 0.96–1.03 | to |
| MiniMax-M2 | 32K, 128K | 1.01–1.12 | to |
| Qwen3-4B (original) | 32K | 0.99–1.08 | to |
| Method | SWE | Terminal | Retail | Airline | Telecom | Speedup |
|---|---|---|---|---|---|---|
| All-refresh reference | 31.6 | 27.0 | 57.0 | 48.5 | 45.4 | 1.00 |
| Placement and state-free variation | ||||||
| Strongest feasible static ( ) | 27.0 | 22.5 | 53.3 | 42.5 | 42.5 | 1.03 |
| Staggered mask, | 24.0 | 21.3 | 50.4 | 40.5 | 40.1 | 1.00 |
| State-independent mixture | 27.0 | 22.5 | 52.9 | 42.5 | 42.5 | 1.03 |
| Rules and local learning | ||||||
| Backbone | Cap | Success change (pp) | Added cost | Time change (%) |
|---|---|---|---|---|
| Qwen3-1.7B | 32K | 0.0 to +2.0 | 0.019 to 0.031 | 0.0 to +0.4 |
| Qwen3-4B-Instruct-2507 | 32K | +0.4 to +2.0 | 0.013 to 0.024 | 0.0 to +0.4 |
| Qwen3-4B-Instruct-2507 | 128K | +0.7 to +2.2 | 0.014 to 0.024 | +0.1 to +0.6 |
| Qwen3-8B | 32K | 0.0 to +1.5 | 0.014 to 0.024 | 0.0 to +0.4 |
| Qwen3-8B | 128K | +1.0 to +1.6 | 0.014 to 0.024 | +0.3 to +0.6 |
| Gemma-3-4B-it | 32K | +2.0 to +3.9 | 0.217 to 0.352 | -1.5 to +3.6 |
| Success (%) | Speedup over all-refresh | |||||||||
| Method | SWE | Term. | Retail | Airl. | Tel. | SWE | Term. | Retail | Airl. | Tel. |
| References | ||||||||||
| Native attention | 32.0 | 28.1 | 57.7 | 50.0 | 46.5 | 0.78 | 0.77 | 0.70 | 0.70 | 0.71 |
| All-refresh sparse | 31.6 | 27.0 | 57.0 | 48.5 | 45.4 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 |
| Strongest feasible static | 27.0 | 22.5 | 53.3 | 42.5 | 42.5 | 1.03 | 1.05 | 1.11 | 1.11 | 1.10 |
| Alternative injected selectors | ||||||||||
| Success (%) | Speedup | Break-even attempts | |||||
|---|---|---|---|---|---|---|---|
| Population | Unadapted | LongCat | + AIR | LongCat | + AIR | LongCat | + AIR |
| SWE | 31.6 | 30.8 | 31.8 | 1.09 | 1.07 | 6,403 | 7,290 |
| Terminal | 27.0 | 27.0 | 25.8 | 1.10 | 1.08 | 7,369 | 8,390 |
| Retail | 57.0 | 56.6 | 57.9 | 1.17 | 1.15 | 8,987 | 10,231 |
| Airline | 48.5 | 48.5 | 49.5 | 1.17 | 1.15 | 11,294 | 12,858 |
| Telecom | 45.4 | 45.0 | 46.7 | 1.15 | 1.14 | 8,652 | 9,851 |
| Held-out success (%) | Minutes per attempt | |||||
|---|---|---|---|---|---|---|
| Subset | Tasks | Transfer | In-domain | (pp) | Transfer | In-domain |
| Terminal-Bench 2.0 | 20 | 15.0 | 20.0 | 15.5 | 15.5 | |
| retail | 40 | 56.9 | 58.1 | 7.5 | 7.5 | |
| airline | 20 | 35.0 | 40.0 | 6.5 | 6.5 | |
| telecom | 40 | 44.4 | 45.6 | 9.0 | 9.0 | |
| 32K | 128K | |||||
|---|---|---|---|---|---|---|
| Method | Retail | Airline | Telecom | Retail | Airline | Telecom |
| Native attention | 16.7 | 16.0 | 10.5 | 21.1 | 10.0 | 10.5 |
| All-refresh sparse | 16.7 | 16.0 | 10.5 | 21.1 | 10.0 | 10.5 |
| Strongest feasible static | 13.2 | 16.0 | 8.8 | 15.8 | 8.0 | 7.9 |
| Training-aware IndexCache | 16.7 | 14.0 | 10.5 | 21.1 | 10.0 | 10.5 |
| LatentIndex + HS | 14.0 | 14.0 | 11.4 | 18.4 | 10.0 | 10.5 |
| Population | Tasks | |||
|---|---|---|---|---|
| SWE | 500 | 392 | 271 | 172 |
| Terminal | 89 | 71 | 50 | 32 |
| Retail | 114 | 96 | 75 | 52 |
| Airline | 50 | 41 | 31 | 18 |
| Telecom | 114 | 99 | 77 | 49 |