StateComp: Learning When to Compress History in Long Horizon Agents
Organizations: TierFlow Team · Gaoling School of Artificial Intelligence, Renmin University of China · Tsinghua University
Abstract
Long-horizon agents continuously accumulate interaction history during task execution, yet the importance of past interactions changes as the agent state evolves. Existing context management methods largely compress history based on fixed windows, periodic schedules, or current relevance, overlooking a more fundamental question: when has a past interaction become safe to replace? Premature compression may remove information still needed for future actions, while overly conservative retention leads to substantial context overhead. To address this, we propose State Conditioned Compression (StateComp), a framework that determines when historical interactions can be safely compressed according to the current agent state. StateComp constructs KEEP and READY supervision through a two-stage annotation procedure and trains an imbalance-aware router on hidden representations from a frozen language model. A bounded state representation further reduces the cost of evaluating long histories, while adjacent READY interactions are grouped into continuous spans and replaced with compact summaries during execution. Experiments on WorkBuddyBench show that StateComp reduces total agent and summarization tokens by 52.27% while maintaining task performance, and achieves a 12.67-fold speedup in representation extraction.
Figures & tables
| Method | Max. tokens | Wall clock (s) | Peak GPU (GiB) | Workspace (GiB) | Test F1 |
| Full history | 203,675 | 76.40 | 29.426 | 11.867 | 0.7000 |
| Bounded | 5,120 (-97.49%) | 6.03 (12.67 ) | 18.620 (-36.72%) | 1.062 (-91.05%) | 0.7818 (+0.08) |
| Method | Code | Office | Sec. | Web | Avg. | Tokens (M) |
| Baseline | 76.99 | 81.84 | 47.76 | 72.14 | 69.87 | 698.17 |
| StateComp | 77.12 0.13 | 82.77 0.93 | 47.31 0.45 | 73.14 1.00 | 70.26 0.39 | 333.24 |
| Method | Code | Office | Sec. | Web | Avg. | Tokens (M) |
| Baseline | 72.93 | 81.64 | 44.58 | 71.00 | 67.54 | 75.50 |
| Sliding Window ( ) | 66.81 6.12 | 67.43 14.21 | 32.32 12.26 | 59.00 12.00 | 56.39 11.15 | 118.08 |
| Sliding Window ( ) | 74.37 1.44 | 73.05 8.59 | 40.07 4.51 | 61.00 10.00 | 62.12 5.42 | 79.39 |
| Sliding Window ( ) | 79.31 6.38 | 85.11 3.47 | 40.28 4.30 | 70.00 1.00 | 68.67 1.13 | 80.82 |
| Periodic Summary ( ) | 65.44 7.49 | 67.66 13.98 | 26.32 18.26 | 82.66 11.66 | 60.52 7.02 | 88.57 |
| Periodic Summary ( ) | 83.60 10.67 | 75.74 5.90 | 40.03 4.55 | 81.32 10.32 | 70.17 2.63 | 94.85 |
| Backbone | Method | Code | Office | Sec. | Web | Avg. | Tokens (M) |
| Base | 55.30 | 79.24 | 60.24 | 46.00 | 60.19 | 41.00 | |
| Hunyuan | StateComp | 64.31 9.01 | 82.20 2.96 | 60.14 0.10 | 49.00 3.00 | 63.91 3.72 | 12.83 |
| Base | 75.25 | 83.42 | 45.28 | 86.00 | 72.49 | 49.75 | |
| Qwen3.8-Flash | StateComp | 93.46 18.21 | 88.71 5.29 | 41.20 4.08 | 88.00 2.00 | 77.84 5.35 | 38.23 |
| Base | 79.49 | 66.13 | 34.67 | 66.51 | 61.70 | 47.58 | |
| GLM-5.3-Flash | StateComp | 66.15 13.34 | 69.90 3.77 | 38.64 3.97 | 85.00 18.49 | 64.92 3.22 | 38.49 |
Appendix figures & tables9 assets
Supplementary material from the paper’s appendix.
Appendix
| Symbol | Meaning |
| Complete historical interaction | |
| Uncompressed reference prefix before interaction | |
| Effective history and identifiers of surviving raw interactions | |
| Reference label: KEEP , READY | |
| Earliest supported compression checkpoint | |
| Frozen representation model and trained router |
| Quantity | Value |
| Trajectories | 300 |
| Recorded states | 7,931 |
| Checkpoint groups | 7,631 |
| Interaction–state pairs | 244,526 |
| KEEP pairs | 228,893 |
| READY pairs | 15,633 |
| Method | Total tokens (M) | Summary tokens (M) |
| Baseline | 75.50 | 0 |
| StateComp | 43.76 | 0.077 |
| Sliding Window | 118.08 | 0 |
| Sliding Window | 79.39 | 0 |
| Sliding Window | 80.82 | 0 |
| Periodic Summary | 88.57 | 4.50 |
| Model | Method | Total tokens (M) | Summary tokens (M) |
| Hunyuan | Base | 41.00 | 0 |
| Hunyuan | StateComp | 12.83 | 0.130 |
| Qwen3.8-Flash | Base | 49.75 | 0 |
| Qwen3.8-Flash | StateComp | 38.23 | 0.236 |
| GLM-5.3-Flash | Base | 47.58 | 0 |
| GLM-5.3-Flash | StateComp | 38.49 | 0.101 |
Context Compression
Context compression reduces the information or memory a model must carry while preserving what it needs to answer questions and act.
See all 90 papers