A Practical Guide to Reducing Costs in Long-Horizon Agent Reinforcement Learning
This article explains why long-horizon agent reinforcement learning is expensive to train rather than to run, and argues that accuracy must be evaluated together with per-task cost on a performance-cost Pareto frontier. It breaks down a training recipe for limited compute: choosing a long-context base model and running full-parameter RL, filtering trajectories by difficulty with early stopping and failure clustering, combining sparse outcome rewards with dense process signals, optimizing rollout and parallelism, and holding a few stability baselines. It then covers inference-side cost reduction through adaptive thinking budgets, parallel sampling with early-stop voting, context compression, caching, and tiered model routing, followed by evaluation and reproducibility practices, a checklist for running on general cloud resources, and common pitfalls.
A Practical Guide to Reducing Costs in Long-Horizon Agent Reinforcement Learning
1. Background: Why Long-Horizon Agents Are Expensive to Train, Not to Run
Long-horizon agents are pushing task boundaries from “fix one bug” to hours of continuous terminal operation and software engineering work. They need multiple rounds of observation, planning, and tool calls, and they must roll back and retry based on errors until the task is genuinely complete. This shape has two direct consequences:
- One sample is one full attempt. A single training trajectory may contain hundreds of tool calls and take hours; a failure at any step wastes hours of compute.
- Feedback is sparse and delayed. Rewards usually appear only when the task ends, with no reliable signal for intermediate steps, which drives up policy gradient variance and slows convergence.
The common industry response is to scale up GPU fleets for large-scale reinforcement learning, but most teams can neither obtain thousands of accelerators nor afford the wall-clock cost of repeated trial and error. So the question worth studying is not “can we throw more compute at it,” but: under limited compute, how do we optimize a trajectory’s information efficiency, training stability, and inference cost at the same time?
A recent public technical report offers one reference answer: starting from a general-purpose base model in the 300B class, built for terminal and coding scenarios, the research team completed full-parameter reinforcement learning on only 64 next-generation accelerators in under five days. It reached a Pass@1 of 46.2% on terminal benchmarks, on par with state-of-the-art frontier approaches running at the highest inference intensity, while cutting per-task cost by more than 30x, and it transferred the gains to two software engineering benchmarks. The reusable engineering points are abstracted below into a hands-on guide that is independent of any specific product.
2. Core Conclusion: The Performance-Cost Pareto Frontier Is the Right Evaluation Axis
Traditional evaluation looks only at accuracy, but in long-horizon agent scenarios accuracy has to be read together with per-task cost. The reason is simple: higher inference intensity (longer chains of thought, more samples, larger models) almost always buys a higher score, but cost can rise by one or two orders of magnitude.
It is therefore better to fix the evaluation as two-dimensional:
- Vertical axis: Pass@1 (averaged over multiple trials to reduce randomness);
- Horizontal axis: average cost per task (a log scale is recommended so values across orders of magnitude stay comparable).
On this chart, the only meaningful conclusion is whether the Pareto frontier has moved forward: a higher score at the same cost, or a lower cost at the same score. Achieving this in engineering requires three things to hold simultaneously:
- Treat “cost” as one of the optimization targets during training, not just success rate;
- Allow adaptive compute allocation at inference time, so easy tasks think less and hard tasks think more;
- Unify the harness and the billing basis during evaluation, so results are not self-referential.
3. Breaking Down the Training Recipe: Five Key Designs Under Limited Compute
3.1 Base Model Choice and the Need for Full-Parameter Training
Long-horizon tasks require the model to maintain instruction following, stable tool-call formatting, and error recovery across thousands of turns of context. Training only a few adapter layers often fails to change the model’s “behavioral habits,” so full-parameter reinforcement learning is more reliable. When choosing a base model, prioritize a general-purpose model that natively supports long context, has well-formed tool-call formatting, and carries enough prior knowledge from code and terminal corpora.
3.2 Trajectory Filtering: Spend Compute on Informative Samples
The biggest waste in long-horizon RL comes from low-information samples. Filtering strategies that work in practice include:
- Difficulty stratification: bucket tasks into easy, medium, and hard by historical pass rate, and sample the middle band first;
- Early stopping: terminate once several consecutive turns show no state progress (no new file changes, no increase in passing tests), avoiding useless long trajectories;
- Deduplication and clustering: cluster similar failure modes so the same class of error does not repeatedly consume budget.
Illustrative logic (pseudocode):
for task in sample_tasks(difficulty="medium"):traj = rollout(policy, task, max_steps=200)if not has_progress(traj): # early stop when no progresscontinueif traj.success or is_informative_failure(traj):buffer.add(traj) # keep both successes and valuable failures
3.3 Reward Design: Sparse Outcome Reward Plus Dense Process Signals
Using only final success or failure as the reward produces extremely high variance. In practice, teams layer on:
- Outcome reward: whether the task passes all tests;
- Process reward: fraction of tests passing, whether compilation succeeds, whether a valid patch is produced;
- Format and efficiency penalties: illegal tool calls, excessively long useless output, redundant turns.
Note that the weight of process rewards should not be too high, otherwise the model will “game the metrics” and drift away from the real objective.
3.4 Sampling and Parallelism: Rollout Is the Time Bottleneck
Most of the training time is often not backpropagation but waiting for the environment to respond. Optimization points include pooling environment instances, asynchronous rollout, bucketed scheduling by task length, and fast rebuilding of failed environments. Queuing long-tail tasks separately can significantly shorten overall wall-clock time.
3.5 Stability Engineering: Three Baselines Even a Small Team Can Hold
- Fix the evaluation harness and random seeds so results stay comparable over time;
- Use a small learning rate plus gradient clipping to avoid gradient explosion on long trajectories;
- Continuously record the cost-success rate curve, and roll back immediately once cost drift appears.
4. Inference-Side Cost Reduction: Make Cost Adapt to Difficulty
Training completion is only the beginning of cost optimization. Techniques that can be combined include:
- Adaptive thinking budget: short chains for easy tasks, long chains for hard ones, instead of always using maximum intensity;
- Parallel sampling plus early-stop voting: run a small number of samples in parallel and stop early once the majority agrees;
- Context compression: summarize and trim historical tool output, keeping only fragments relevant to the current decision;
- Caching and reuse: retrieval results and environment snapshots for similar tasks can be reused;
- Tiered model routing: use a lightweight model for low-risk steps and escalate only for complex decisions.
In engineering terms, it is better to make the cost budget an explicit parameter inside the scheduler rather than something tallied after the fact.
5. Evaluation and Reproducibility: Making Conclusions Hold Up
- Average over multiple trials: variance is high on long-horizon tasks, so a single run is not trustworthy;
- Unified harness: identical tool sets, timeouts, and retry policies, otherwise scores are not comparable;
- Transparent cost basis: convert self-hosted models at published prices, or state resource usage and duration explicitly;
- Cross-benchmark transfer validation: after gains on a terminal benchmark, re-test on software engineering benchmarks to confirm the result is not overfitting to a single environment.
6. Running It on General Cloud Resources: An Executable Checklist
To reproduce similar results on the cloud, you can assemble the setup from general-purpose capabilities:
- Container platform: spin up an elastically scaling sandbox environment pool to host parallel rollouts;
- Object storage: store trajectories, checkpoints, and evaluation artifacts for auditing and reproducibility;
- Message queue: decouple the scheduler from the environment executors and smooth out peaks and troughs;
- Logging plus monitoring and alerting: track per-task duration, turn counts, failure types, and cost drift;
- Elastic compute: separate pools for training and evaluation to avoid idle resources.
Recommended order of work: first get a small-scale baseline running (a few dozen tasks, short horizons) and confirm the harness and rewards are correct; then scale to medium size to validate stability; only then max out compute for full-parameter training.
7. Common Pitfalls
- Looking at scores but not cost, which makes a solution impossible to ship;
- Overweighting process rewards, so the model learns to game intermediate metrics;
- Ignoring the environment bottleneck and spending all wall-clock time waiting;
- Inconsistent evaluation basis, so conclusions cannot be reproduced;
- Jumping straight to full-scale training without small-scale validation, making failure extremely costly.
8. Conclusion
Competition among long-horizon agents is shifting from “who has more cards” to “whose recipe is cheaper.” By bringing cost into the training objective, compressing wasted compute with trajectory filtering and early stopping, controlling per-task overhead with adaptive inference, and using the Pareto frontier as a unified evaluation axis, small and mid-sized teams can achieve results close to the frontier with limited resources. General practices from Baidu AI Cloud in containerized sandboxes, elastic compute, and observability also offer a reference engineering pattern for this kind of high-variance, long-cycle workload.
