Long horizon language model agents continuously accumulate interaction history, increasing computational cost while making relevant information harder to preserve and reuse. Existing context management methods mainly focus on how to compress or retrieve history, but largely leave open whether the model itself already represents the need for these memory operations before they occur. We study the hidden state immediately before each agent action and find that compression and recall needs are already encoded in the model's internal representations. These signals cannot be explained by simple context length or interaction progress, and they exhibit distinct formation patterns across model depth. We further show that most memory decision information is preserved in a compact recent context, while selectively restored historical evidence complements the long range dependencies that recent context misses. Based on these findings, we propose Preaction Memory with Evidence Retrieval (PaMER), which combines state guided compression with external evidence retrieval. PaMER+ further introduces step level evidence selection to recover only the historical information required by the current task. Experiments on WorkBuddyBench, across multiple context management baselines and model backbones, show that our framework substantially reduces context consumption while maintaining competitive task performance.
Figures & tables
Signal
Comp. ↑
Recall ↑
Length / Turn
0.751
0.552
Metadata
0.758
0.549
Hidden (Linear)
0.831
0.765
Hidden (MLP)
0.827
0.763
Table 1: Memory decision signals. Mean AUROC.
Figure 1: Memory-decision signals across layers. (a) AUROC of independently trained probes using the final input token or mean-pooled states. (b) Mean positive-minus-negative probe logit. Results are aggregated over five question-grouped splits.
Figure 2: Reading memory needs before an action. The diagram illustrates compression and recall as prediction targets. In the deployed controller, the compression heads read the final state from the task prefix and Recent2. The recall probe is used for analysis, not as an online retrieval gate.
History
Tokens ↓
Comp. ↑
Recall ↑
Full Context
100.0
0.829
0.780
Compact context
Recent2
26.0
0.776
0.761
+ Decision KD
26.0
0.781
0.753
Recovered history
Hidden Bank
16.8
0.769
0.730
Table 2: Compact context and historical evidence. Tokens are relative to Full Context.
Figure 3: Online behavior and component comparisons. (a) Compression and evidence recall. (b) Component results. (c) Input context across interaction turns. The horizontal line marks 128K as an analysis reference, not a hard limit enforced by the controller.
Model
Code
Office
Sec.
Web
Avg.
Tokens ↓
DeepSeek-V4-Flash
77.0
81.8
47.8
72.1
69.9
2.69M
+ PaMER
75.3 (-1.7)
79.8 (-2.0)
52.3 (+4.5)
70.0 (-2.1)
69.4 (-0.4)
0.72M (-73.2%)
+ PaMER +
76.7 (-0.3)
80.9 (-0.9)
51.6 (+3.8)
76.3 (+4.2)
71.6 (+1.7)
0.76M (-71.7%)
Table 3: Full benchmark system performance and token usage. Scores are multiplied by 100 . Green and red indicate favorable and unfavorable changes from the base system.
Method
Code
Office
Sec.
Web
Avg.
Tokens ↓
Base and Ours
DeepSeek-V4-Flash 44
72.9
81.6
44.6
71.0
67.5
1.89M
+ PaMER
76.3 (+3.4)
79.9 (-1.7)
43.9 (-0.7)
72.0 (+1.0)
68.0 (+0.5)
0.90M (-52.4%)
+ PaMER +
71.3 (-1.6)
86.6 (+5.0)
47.5 (+2.9)
70.0 (-1.0)
68.9 (+1.3)
0.98M (-48.1%)
Simple Context Baselines
Sliding Window ( K=5 )
66.8 (-6.1)
67.4 (-14.2)
32.3 (-12.3)
59.0 (-12.0)
56.4 (-11.2)
2.95M (+56.3%)
Table 4: Comparison with context management methods on WorkBuddyBench Pilot40. All methods use the same fixed 40 tasks. Scores are multiplied by 100 . Parenthesized values show changes from the DeepSeek-V4-Flash base agent.
Model
Code
Office
Sec.
Web
Avg.
Tokens ↓
GPT-5.6-Luna
44.8
72.1
55.7
56.0
57.2
676K
+ PaMER
54.4 (+9.6)
57.8 (-14.3)
52.2 (-3.5)
55.0 (-1.0)
54.9 (-2.3)
81K (-88.0%)
+ PaMER +
41.4 (-3.4)
57.7 (-14.4)
55.3 (-0.4)
66.0 (+10.0)
55.1 (-2.1)
97K (-85.7%)
GLM-5.3-Flash 48
43.2
85.0
66.1
61.7
64.0
762K
+ PaMER
44.4 (+1.2)
86.5 (+1.5)
70.7 (+4.6)
66.7 (+5.0)
67.1 (+3.1)
318K (-58.3%)
+ PaMER +
39.6 (-3.6)
84.4 (-0.6)
70.7 (+4.6)
60.0 (-1.7)
63.7 (-0.3)
310K (-59.3%)
Table 5: Cross-model evaluation on WorkBuddyBench Pilot40. Scores are multiplied by 100 . All models are evaluated on the same fixed 40 tasks, with 10 tasks per domain. Parenthesized values show changes from the corresponding base agent. Bold indicates the best overall score and lowest token consumption within each backbone.
Appendix figures & tables16 assets
Supplementary material from the paper’s appendix.
Appendix
Target
AUROC ↑
AUPRC ↑
F1 ↑
Compression
0.829
0.690
0.639
Recall
0.780
0.597
0.558
Appendix
Table 6: Full Context reference for the compact-context analysis. Five-seed mean test metrics for the faithful-hint MLP; F1 uses per-seed validation-selected thresholds. Values are rounded only for display.
Signal
Compression
Recall
AUROC ↑
AUPRC ↑
AUROC ↑
AUPRC ↑
Length + turn
0.751±0.066
0.533±0.053
0.552±0.074
0.336±0.036
Last tool type
0.562±0.026
0.335±0.054
0.527±0.056
0.315±0.043
Last action type
0.583±0.019
0.346±0.057
0.535±0.056
0.319±0.039
Length + turn + tool type
0.758±0.056
0.543±0.054
0.549±0.058
0.361±0.066
Recent2 TF-IDF
0.616±0.027
0.416±0.072
0.610±0.056
0.398±0.075
Appendix
Table 7: Memory-decision prediction controls. Diagnostic rows show mean ± reported standard deviation over five question-grouped splits. The faithful-hint MLP reference is listed separately with mean metrics.
Setting
AUROC ↑
AUPRC ↑
F1 ↑
Compression
No hint, linear
0.831
0.670
0.601
No hint, MLP
0.827
0.665
0.606
Faithful hint, linear
0.836
0.697
0.624
Faithful hint, MLP
0.829
0.690
0.639
Recall
Appendix
Table 8: Additional probe-capacity and memory-hint measurements. Mean AUROC, AUPRC, and validation-threshold F1 over five splits. Each row denotes the named probe and hint configuration.
Representation
Pooling
Compression
Recall
AUROC ↑
AUPRC ↑
AUROC ↑
AUPRC ↑
Block 4
Last
0.757±0.051
0.563±0.063
0.722±0.058
0.526±0.087
Mean
0.706±0.027
0.483±0.063
0.632±0.073
0.435±0.079
Block 8
Last
0.799±0.044
0.623±0.082
0.768±0.053
0.594±0.112
Mean
0.735±0.044
0.493±0.068
0.690±0.058
0.483±0.093
Block 16
Last
0.810±0.031
0.644±0.082
0.780±0.054
0.583±0.108
Appendix
Table 9: Layerwise linear diagnostics and the compact-context reference. Diagnostic rows show mean ± reported standard deviation over five question-grouped splits. The bottom row uses the faithful-hint MLP reference from the compact-context analysis and is not part of a same-capacity layer comparison.
Comparison
Target / metric
Mean difference
Sign-flip p
Recent2 KD − Recent2
C / AUROC
+0.0058
0.500
R / AUROC
− 0.0080
0.500
C / F1
+0.0570
0.0625
R / F1
+0.0278
0.3125
Raw Top5 − Hidden Bank Recent5
C / AUROC
+0.0627
0.0625
R / AUROC
+0.0389
0.1875
Appendix
Table 10: Paired compact-context differences across split seeds. C and R denote compression and recall; positive differences favor the first method. The listed tests concern compact-context interventions and do not reuse significance results from an earlier main-reference configuration.
Representation
Tokens(%)
Compression
Recall
Agreement
AUROC
F1
AUROC
F1
Comp.
Recall
Full Context
100.0
0.829
0.639
0.780
0.558
⋅
⋅
Recent context
Current
8.8
0.604
0.451
0.717
0.532
⋅
⋅
Recent1
17.7
0.746
0.520
0.725
0.524
⋅
⋅
Recent2
26.0
0.776
0.541
0.761
0.520
⋅
⋅
Appendix
Table 11: Compact-context and historical-evidence comparison. C and R denote compression and recall; dots denote unreported teacher agreement.
Figure 4: Decision information at different input budgets. Left: recent context. Right: historical evidence recovery. Token fractions refer to the corresponding offline comparison.
Retriever
Tokens(%)
AUROC
Agreement
Comp.
Recall
Comp.
Recall
Random Top3
47.2
0.793
0.752
0.786
0.849
Recency Top3
46.2
0.792
0.753
0.818
0.857
Selective Raw Top1
35.9
0.799
0.761
0.826
0.817
Selective Raw Top3
52.3
0.809
0.766
0.826
0.834
Selective Raw Top5
66.2
0.832
0.769
0.859
0.865
Appendix
Table 12: Offline retrieval controls. Token percentages are relative to Full Context; agreement is measured against the corresponding teacher.
Variant
Recalled tokens
Agreement
Mean
P95
Max
Comp.
Recall
Top3 cap 8K
5,540
8,021
8,192
0.818
0.835
Top3 cap 16K
8,765
14,801
16,383
0.843
0.837
Top3 uncapped
9,167
16,509
32,245
0.838
0.838
Appendix
Table 13: Qwen Top3 evidence budgets. Mean, P95, and maximum describe recalled evidence tokens, not total prompt length.
Parameter
Value
Compression controller
Retained complete blocks
2
Feature extractor
Frozen, provenance-matched Qwen3.5-9B
Feature dimension
4,096
Compression heads
5 Recent2 decision-distillation MLPs
Vote rule
3 of 5
Appendix
Table 14: Controller settings. Character budgets, token budgets, and embedding dimensions are distinct quantities.
Condition
Required behavior
Missing session identifier
Return the original request and record the condition.
Unsafe tool protocol
Return the original request without applying a memory transformation.
Candidate below 1,024 tokens
This is not a failure: skip compression; recall from existing memory remains possible.
Probe failure or OOM
Skip compression and record the error; existing-memory recall may still be attempted.
Summary, embedding, or storage failure
Return the original request, commit no incomplete memory, and remove no raw block.
Recall transport or shape failure
Return the original request rather than a partially rewritten context.
Appendix
Table 15: Memory-operation fallback rules.
Backbone
Variant
Code
Office
Sec.
Web
Avg.
Δ
GPT-5.6-Luna
Base agent
44.8
72.1
55.7
56.0
57.2
0.0
PaMER
54.4
57.8
52.2
55.0
54.9
-2.3
PaMER +
41.4
57.7
55.3
66.0
55.1
-2.1
GLM-5.3-Flash
Base agent
43.2
85.0
66.1
61.7
64.0
0.0
PaMER
44.4
86.5
70.7
66.7
67.1
+3.1
PaMER +
39.6
84.4
70.7
60.0
63.7
-0.3
Appendix
Table 16: Cross-model results on the fixed Pilot40 task set. Scores are multiplied by 100. All variants use the same 40 tasks, with ten tasks per domain. Avg. is the equal-weight average of the four domain scores; Δ is the change from the corresponding base agent.
Backbone
Variant
Tokens/task (K) ↓
Change (%)
GPT-5.6-Luna
Base agent
676
0.0
PaMER
81
-88.0
PaMER +
97
-85.7
GLM-5.3-Flash
Base agent
762
0.0
PaMER
318
-58.3
PaMER +
310
-59.3
Appendix
Table 17: Cross-model token usage on fixed Pilot40. K denotes thousands of tokens. Totals include the counted main-agent and auxiliary memory calls. Changes are relative to the corresponding base agent.
Variant
Reward ↑
Tokens/task ↓
Reported peak ↓
Base agent
0.6868
3.066M
280.1K
PaMER
0.7000
0.899M
97.5K
w/o Recall
0.6370
0.924M
107.1K
w/o Compression
0.6887
3.180M
253.3K
Appendix
Table 18: Component ablation in a separate execution batch. Reward uses the original scale.
Turn
Recorded operation
Evidence in the saved trace
19
manage_context
41 messages are summarized into memory 1.
28
manage_context
19 messages are summarized into memory 2.
36
query_memory
The agent requests memory 1 during continued search.
47
manage_context
39 messages are summarized into memory 3.
71
manage_context
49 messages are summarized into memory 4.
87
get_document
Document 20026 is retrieved as candidate supporting evidence.
Appendix
Table 19: Selected events in the illustrative trajectory.