Large language models (LLMs) are widely used to power agents that interact with tools and environments to solve complex tasks. Repeated attempts improve the quality of tool-using agents, but continued execution incurs additional costs even when it is unlikely to improve the best result ultimately returned. This raises the question of when to stop an attempt to reduce execution cost while preserving task-level Best-of-N quality. To address this question, we introduce GainCtrl, a gain-based execution controller for LLMs. In GainCtrl, a lightweight CPU predictor uses interaction histories to estimate expected positive gains over retained scores, which are then used to guide stopping decisions with calibrated thresholds to limit the loss in mean Best-of-N task quality. We evaluate the controller through trajectory replay across three environments and three LLM actors. Comparisons of interpolated quality-cost Pareto frontiers show that GainCtrl generally uses fewer tokens than baselines at matched target quality. Fixed policies also achieve quality close to that of full execution while substantially reducing token consumption. The predictor runs at millisecond latency on a single CPU thread, supporting repeated monitoring without access to LLM internals.
Figures & tables
Figure 1: Overview of GainCtrl. At predefined checkpoints during each attempt, the controller extracts action-text and statistical features from the visible interaction history h . A lightweight CPU ExtraTrees predictor produces a ten-dimensional vector F(h) , where each dimension estimates the expected positive remaining gain relative to one of ten fixed reference scores rk∈{0,0.1,…,0.9} (e.g., 0.20 at rk=0.5 and 0.14 at rk=0.6 ). GainCtrl-T uses the current attempt’s retained score c as its reference r , while GainCtrl-P uses r=max(c,b) , where b is the best score retained from previous attempts. Linear interpolation of F(h) then gives g^(h,r) at the selected reference score, yielding 0.17 at r=0.55 in the example. The controller continues the attempt if g^(h,r)>τ and stops it otherwise, using a validation-calibrated threshold τ . A stopped attempt consumes one attempt slot, and a fresh attempt begins if slots remain. The task ends when any attempt reaches full score.
Figure 2: Empirical quality-cost Pareto frontiers across nine settings. Five fixed policies per method (GainCtrl loss budgets 1/2/5/10/25%; FailFast FPR targets 5/10/15/20/25%) are evaluated at N=1,…,15 . Full has 15 evaluated points, one for each attempt limit. Line segments interpolate between evaluated points in quality-log(token) coordinates.
Setting
Full
FailFast
GainCtrl-T
GainCtrl-P
ScienceWorld
4B
294.2
227.1
161.3
143.5 (36.8%)
9B
175.8
176.7
133.8
110.8 (37.3%)
Luna
27.9 †
29.7
27.1
27.2 (8.3%)
ALFWorld
4B
791.1
494.4
234.3
234.3 (52.6%)
Table 1: Actor-token cost (thousands) at matched targets. Costs use linear interpolation in quality–log(token) coordinates. Controlled-method frontiers contain their five fixed policies. † marks an observed endpoint already above the target. Parentheses in the GainCtrl-P column give token savings relative to FailFast. The two configurations coincide in ALFWorld.
Setting
Budget (k)
Full
FailFast
GainCtrl-T
GainCtrl-P
ScienceWorld
4B
242.8
41.42
44.86
48.30
49.80 (+4.94)
9B
180.0
52.38
52.14
55.16
59.18 (+7.04)
Luna
85.0
86.75
84.21
85.14
88.43 (+4.22)
ALFWorld
4B
466.6
60.30
65.38
67.50 †
67.50 † (+2.12)
Table 2: Mean retained score at a common token budget anchored to Full at N=5 . Results use quality–log(token) interpolation without adding Full points. † denotes unused budget at the best observed endpoint. Parentheses show GainCtrl-P’s score improvement over FailFast.
Setting
k=1
k=2
k=3
ScienceWorld
4B
96.79 / 40.52
95.98 / 45.54
96.05 / 48.54
9B
97.88 / 33.54
97.80 / 38.30
98.25 / 38.20
Luna
97.14 / 43.34
97.02 / 46.24
97.74 / 44.81
ALFWorld
4B
99.04 / 53.64
96.88 / 68.61
97.12 / 72.56
Table 3: GainCtrl-P quality retention / token savings (%) at N=15 with a 2% validation loss allowance. Results average 60 balanced orders over 200 test tasks. For k=1,2 , results additionally average three data-sampling seeds; k=3 uses the full training pool.
Setting
Statistics
Statistics + Action text
Statistics + Action text + Feedback text
ScienceWorld
4B
96.50 / 31.27
96.05 / 48.54
96.96 / 41.22
9B
97.60 / 28.85
98.25 / 38.20
98.60 / 36.55
Luna
97.31 / 31.33
97.74 / 44.81
97.93 / 44.04
ALFWorld
4B
98.56 / 57.02
97.12 / 72.56
99.28 / 61.32
Table 4: GainCtrl-P quality retention / actor-token savings (%) at N=15 with a 2% validation loss allowance, relative to Full. Statistics uses 14/140/91 features in ScienceWorld/ALFWorld/WebShop. Both other configurations add a 64-dimensional text vector; Feedback text additionally includes recent observations and available actions. Statistics + Action text is used in the main experiments (Figure 2 ).
Predictor input
Dim.
Retain (%)
Save (%)
ScienceWorld
Statistics
14
96.50
31.27
Action text
64
98.37
27.89
Statistics + Action text
78
96.05
48.54
ALFWorld
Statistics
140
98.56
57.02
Table 5: Feature-source ablation with Qwen3.5-4B ( N=15 , 2% validation loss allowance, three training trajectories per task). Statistics and Action text use the two feature groups separately; Statistics + Action text uses both and matches the main input in Table 4 . Retention and savings are relative to Full.
Appendix figures & tables18 assets
Supplementary material from the paper’s appendix.
Appendix
Environment
Train/val/test
Train trials
Cap
Checkpoints
Features
ScienceWorld
897/200/200
3
20
2,6,10,14,18
78
ALFWorld
2220/200/200
3
30
5,10,15,20
204
WebShop
1161/200/200
3
10
2,4,6
155
Appendix
Table 6: Shared settings across the three actors within each environment. Validation and test have 15 trials per task. The 64 action text feature dimensions are included in the feature count.
Algorithm 1: Training and Inference of the Gain Predictor
Input: training tasks I ; three selected complete trajectories ρi,j per task; environment e , step cap Ce , checkpoints Ke , and score retention rule; grid rk=k/10 , k=0,…,9 .
Output: fitted feature map Φe , one ten-output forest F , and the gain predictor F(h)=F(Φe(h)) .
Training
1
Initialize training records B←∅ .
2
For each training task i∈I : initialize Bi←∅ .
3
For each selected trajectory ρi,j :
Appendix
Table 9
Setting
GainCtrl-P bracket
α
FailFast bracket
α
ScienceWorld/4B
D10/10–D10/11
0.241
F5/12–F5/13
0.645
ScienceWorld/9B
D10/6–D10/7
0.326
F5/12–F5/13
0.131
ScienceWorld/Luna
D2/1–D1/1
0.137
F5/1–F5/2
0.279
ALFWorld/4B
D5/15–D2/13
0.051
F5/12–F5/13
0.654
ALFWorld/9B
D2/12–D2/13
0.213
F5/14–F5/15
0.925
ALFWorld/Luna
D5/8–D5/9
0.917
F10/9–F10/10
0.457
Appendix
Table 7: Interpolation endpoints for Table 1 . D b / n denotes loss budget b% at N=n ; F b / n denotes target FPR b% . Each bracket gives the lower and upper endpoints and the weight α assigned to the upper endpoint.
Figure 3: Single-policy quality-cost curves at a 1% validation loss allowance. GainCtrl-T, GainCtrl-P, and FailFast each select one rule under the same quality constraint and minimum normalized token-cost objective; FailFast searches its complete candidate grid. Each curve fixes its rule and varies N=1,…,15 .
Figure 4: Single-policy quality-cost curves at a 2% validation loss allowance, with the same matched selection objective and plotting conventions as Figure 3 .
Figure 5: Single-policy quality-cost curves at a 10% validation loss allowance, with the same matched selection objective and plotting conventions as Figure 3 .
Setting
δ (%)
Full
GainCtrl-P
Saved (%)
FailFast-task
Saved (%)
ScienceWorld/4B
1
55.25
54.83
29.2
54.91
10.5
ScienceWorld/4B
2
55.25
53.07
48.5
54.01
14.5
ScienceWorld/4B
10
55.25
46.97
74.0
47.06
58.8
ScienceWorld/9B
1
65.00
64.37
28.2
64.12
12.8
ScienceWorld/9B
2
65.00
63.86
38.2
63.34
22.8
ScienceWorld/9B
10
65.00
59.05
63.6
59.54
43.6
Appendix
Table 8: Fixed-policy outcomes at N=15 under matched validation task-loss allowances. FailFast-task selects from its full candidate grid using the same quality constraint and mean normalized token-cost objective as GainCtrl. Quality is on the 0–100 scale; savings are relative to Full.
Setting
δ (%)
GainCtrl-T τ
GainCtrl-P τ
FF θ
FF floor
FF hits
ScienceWorld/4B
1
0.01000
0.00200
0.9882
0.0
count 1
ScienceWorld/4B
2
0.02512
0.01000
0.9632
0.0
count 4
ScienceWorld/4B
10
0.06310
0.03981
0.9773
0.0
count 1
ScienceWorld/9B
1
0.01585
0.00316
0.9783
0.0
count 1
ScienceWorld/9B
2
0.03162
0.00631
0.9683
0.0
count 2
ScienceWorld/9B
10
0.06310
0.03162
0.9686
0.0
count 1
Appendix
Table 9: Frozen rules for the 1%, 2%, and 10% matched-allowance comparisons. FailFast-task uses the displayed failure-probability cutoff, minimum progress fraction, and cumulative (count) or consecutive (sustained) hit requirement. GainCtrl thresholds are selected from the logarithmic grid defined in Section 4.1 and displayed to five decimal places.
Figure 6: Token savings as training trajectories per task vary, with a 2% validation loss budget and N=15 . All configurations average evaluation over 60 balanced candidate orders per test task and then over 200 tasks. For k=1,2 , points and error bars additionally summarize the mean and standard deviation across three seeds. The result for k=3 uses the model trained on all training data.
Figure 7: Token savings as training-task coverage varies, retaining three trajectories per included task, with a 2% validation loss budget and N=15 . Every fitted model is evaluated over the same 60 balanced candidate orders per test task and then averaged over 200 tasks. Below 100% coverage, points and error bars summarize the mean and standard deviation across three data-sampling seeds. The result at 100% coverage uses the model trained on all training data.
Environment
Input
Score difference [95% CI]
Saving difference [95% CI]
ScienceWorld
Statistics
+0.245 [-0.639, +1.132]
-17.27 [-19.55, -15.02]
ScienceWorld
Action text
+1.277 [+0.364, +2.411]
-20.65 [-23.26, -18.02]
ALFWorld
Statistics
+1.000 [-1.000, +3.000]
-15.54 [-20.39, -10.71]
ALFWorld
Action text
-0.500 [-2.500, +1.000]
-18.93 [-24.27, -13.82]
WebShop
Statistics
+0.714 [+0.082, +1.615]
-10.22 [-13.35, -7.19]
WebShop
Action text
+0.378 [-0.205, +1.319]
-12.25 [-14.60, -9.97]
Appendix
Table 10: Results for Statistics and Action text minus those for Statistics + Action text at the 2% validation allowance and N=15 . Scores use the 0–100 scale; saving differences are percentage points relative to Full cost. Intervals use 3,000 paired bootstrap draws of 200 task means after averaging the 60 orders. These intervals are conditional on the trajectory pool and the models fitted using seed 42.
Figure 8: Qwen3.5-4B feature-source ablation at the 2% validation allowance and N=15 . Upper panels show quality retention; lower panels show actor-token savings, each relative to Full. The 95% confidence intervals are computed by paired bootstrap resampling of tasks, with the models fitted using seed 42 held fixed. ALFWorld has GainCtrl-T = GainCtrl-P.
Environment
Predictor input
Retain (%)
Save (%)
ScienceWorld
Statistics
94.01
49.89
ScienceWorld
Action text
92.44
47.64
ScienceWorld
Statistics + Action text
91.32
62.57
ALFWorld
Statistics
97.12
71.49
ALFWorld
Action text
94.96
68.21
ALFWorld
Statistics + Action text
94.96
79.11
Appendix
Table 11: Feature ablation at the 5% validation loss allowance and N=15 , using the same fitted predictors as Table 5 . Retention and savings are relative to Full.
Figure 9: Fixed-policy quality-cost curves for the feature ablation, using 2% (upper) and 5% (lower) validation allowances. Each line fixes its input configuration, predictor, reference rule, and cutoff, and varies N from one to fifteen. The lines are individual policies, without combining points across input configurations into a Pareto frontier.
GainCtrl
FailFast
Setting
Fit (s)
Check (ms)
Fit (min)
Fwd (ms)
ScienceWorld/4B
4.44
7.29
31.5
66.08
ScienceWorld/9B
4.15
7.11
26.7
69.51
ScienceWorld/Luna
4.01
6.97
12.8
81.12
ALFWorld/4B
12.88
10.74
47.7
127.21
ALFWorld/9B
11.84
11.86
47.0
89.77
Appendix
Table 12: Monitor training times and measured latencies. CPU fitting includes TF–IDF/SVD and forest fitting with 4 threads, excluding data collection and prefix preparation. CPU checks include features extracted from the visible execution, TF–IDF/SVD, forest inference, and output normalization on 1 thread. FailFast training uses 4 RTX 3090 GPUs and 1,500 steps, excluding data collection and input preprocessing. FailFast forward-pass latency uses 1 RTX 3090 at batch size one and excludes input construction, tokenization, and GPU transfer.
Actor
δ (%)
Q15
Retain (%)
Save (%)
4B
1
54.83
99.24
29.19
4B
2
53.07
96.05
48.54
4B
5
50.45
91.32
62.57
4B
10
46.97
85.02
73.99
4B
25
40.39
73.11
86.00
9B
1
64.37
99.03
28.18
Appendix
Table 13: ScienceWorld GainCtrl-P at N=15 . Retention and savings are relative to Full.
Actor
δ (%)
Q15
Retain (%)
Save (%)
4B
1
67.50
97.12
69.96
4B
2
67.50
97.12
72.56
4B
5
66.00
94.96
79.11
4B
10
62.50
89.93
84.10
4B
25
56.50
81.29
91.14
9B
1
79.50
98.15
47.71
Appendix
Table 14: ALFWorld GainCtrl-P at N=15 . Retention and savings are relative to Full; the two configurations coincide in ALFWorld.
Actor
δ (%)
Q15
Retain (%)
Save (%)
4B
1
34.90
96.86
16.19
4B
2
34.41
95.52
37.24
4B
5
34.39
95.46
41.13
4B
10
32.75
90.89
59.99
4B
25
28.29
78.53
78.30
9B
1
33.03
100.00
21.99
Appendix
Table 15: WebShop GainCtrl-P at N=15 . Retention and savings are relative to Full.
University of Science and Technology of China, Hefei, Anhui, China · Suzhou Institute for Advanced Research, University of Science and Technology of China