Long-Horizon Agent RL: A Low-Cost Training Guide
This article explains why long-horizon agent reinforcement learning is bottlenecked by training cost rather than inference cost, and presents a reusable four-stage recipe for running full-parameter RL on a small GPU cluster. It covers verifiable sparse reward design, trajectory filtering and sampling budgets, parallel sampling with resource isolation, and consistent evaluation methodology, along with common pitfalls. Readers will learn how a 300B-class base model was trained into a terminal and coding agent on 64 next-generation accelerators in under five days, reaching 46.2% Pass@1 on mainstream terminal benchmarks at over 30x lower average per-task cost than flagship inference configurations.
1. Background: Why Long-Horizon Agents Are Expensive to Train, Not to Run
Long-horizon agents are pushing task boundaries from “fix a bug” to hours of continuous terminal operation and software engineering work. Unlike single-turn question answering, one training sample for this kind of task represents a complete attempt: the model must call tools across multiple turns, read outputs, modify code, and run tests until the task terminates or times out. A single attempt can last hours and involve hundreds of tool calls, so a failure at any step wastes hours of compute time.
The bottleneck of long-horizon agent RL therefore lies not only in the per-task cost on the inference side, but more in the “effective output rate of samples” on the training side. Frontier labs can scale RL across thousands of accelerators, while most teams must achieve the same capability jump within a budget of a few dozen GPUs. This article abstracts a reusable engineering recipe that helps teams complete full-parameter reinforcement learning with limited compute and transfer the results to multiple software engineering and terminal benchmarks.
2. Key Finding: Small Clusters Can Approach the Performance-Cost Frontier
A publicly described recipe shows that starting from a 300B-class lightweight inference base model, using only 64 next-generation accelerators and less than five days, full-parameter reinforcement learning produces a terminal and coding agent. It reaches 46.2% Pass@1 on mainstream terminal benchmarks, on par with flagship models of the same generation. More importantly, its average per-task cost on the same tasks is more than 30x lower than the flagship approach at the highest inference effort setting, while retaining capability transfer on two software engineering benchmarks.
Cost here should be accounted for on an equivalent billing basis: because the model is self-hosted by the team, it can be converted using the public pricing of the base model it depends on, allowing comparison with commercial inference options on the same axis. The most important engineering takeaway is that improving long-horizon capability does not necessarily require a very large cluster; what matters is spending the training budget on effective trajectories.
3. Method Overview: A Four-Stage Pipeline
- Base model selection: prefer a lightweight inference base model that supports long context, tool calling, and stable structured output, reducing per-GPU memory and throughput pressure.
- Environment construction: build reproducible sandbox environments for terminal and coding tasks, including a file system, dependency installation, test execution, and timeout control.
- Full-parameter RL: update the policy with full parameters on a small number of accelerators, combined with trajectory-level rewards and a strict sampling budget.
- Evaluation and transfer: evaluate with a unified harness across multiple benchmarks and observe whether capabilities transfer to unseen task distributions.
4. Key Engineering Practices
1. Keep Rewards Sparse but Verifiable
Long-horizon tasks should not rely on dense manual rewards. A more robust approach is to use automatically verifiable terminal signals, such as whether unit tests pass, whether the target file was modified correctly, or whether command return codes match expectations. Illustrative logic:
# Pseudocode: trajectory-level verifiable rewarddef reward(traj):if traj.timeout:return 0.0tests = run_tests(traj.workspace)return 1.0 if tests.all_passed else 0.0
2. Trajectory Filtering and Budget Control
A failed trajectory can consume hours of compute. Set up a layered budget: maximum turns per task, maximum duration per turn, and an overall sampling cap; terminate trajectories early when they clearly diverge, giving the compute to more promising samples.
3. Parallel Sampling and Resource Isolation
At a 64-GPU scale, decouple environment execution from policy updates: run the environment side in parallel through a container pool, and centralize full-parameter updates on the policy side. Use a general-purpose container platform and logging service to record every trajectory, making replay and deduplication easier.
4. Consistent Cost Accounting and Evaluation
When comparing approaches, keep the number of Pass@1 trials, timeout settings, and tool permissions identical. The original emphasizes averaging over 5 trials; such details directly determine whether conclusions are reproducible.
5. Common Pitfalls
- Chasing larger clusters while ignoring trajectory efficiency;
- Stacking dense rewards, causing the policy to “farm local points” over long horizons;
- Inconsistent evaluation harnesses, distorting performance and cost comparisons;
- Ignoring the sunk compute cost of timeouts and failed trajectories.
6. Conclusion
The core competitiveness of long-horizon agent RL is shifting from “throwing GPUs at it” to “the recipe.” With verifiable rewards, strict budgets, parallel sampling, and unified evaluation as the backbone, small and mid-sized teams can likewise complete full-parameter training of a 300B-class agent on a few dozen accelerators and push per-task cost down to a fraction of a flagship approach. To host environment sandboxes, trajectory logs, and monitoring alerts, teams can use general-purpose capabilities such as the container platform, logging service, and monitoring and alerting on Baidu AI Cloud to build a stable, reproducible training and evaluation pipeline.
