Long-Horizon Agent RL: A Practical Guide to Low-Cost Training
This article explains why long-horizon agent reinforcement learning is expensive to train rather than to run, and how to reduce the cost per effective sample on a small cluster. It covers environment and task construction, verifiable layered reward design, rollout and sampling strategies, engineering constraints for full-parameter updates, and evaluation discipline. It also breaks down single-task cost into optimizable terms and outlines a four-stage implementation path, along with common pitfalls such as judging by benchmark scores alone or comparing results across different harnesses.
1. Why Long-Horizon Agents Are Expensive to Train, Not to Run
Long-horizon agents are pushing task boundaries from “fix a bug” toward terminal operations and software engineering work that runs for hours at a stretch. These tasks share a few traits: a single attempt involves hundreds of tool calls, the state space is large, failure points are scattered, and feedback is sparse. Put such a task into a reinforcement learning (RL) training loop and the cost structure changes fundamentally — one training sample is no longer a single forward pass, but a complete trajectory that spans hours and hundreds of environment interactions.
This leads to three direct consequences:
- Expensive samples: Collecting one trajectory costs far more than text generation, and GPU time is consumed largely by waiting for the environment to respond and by retrying failures.
- High variance: Whether a long-horizon task succeeds often hinges on one decision made very early, which makes credit assignment difficult and gradient noise high.
- Limited throughput: Environment execution, tool calls, and sandbox isolation tend to become the bottleneck, not model computation itself.
So the core tension in long-horizon agent RL is not “can it be trained” but “can the cost per effective sample be pushed into an acceptable range under a limited compute budget.” The common industry response is to scale up the cluster, but for most teams the more realistic question is how to complete one high-quality, reproducible full-parameter run on a small cluster.
2. Core Idea: Push the Performance–Cost Curve to the Pareto Frontier
A publicly documented recipe offers one answer: start from a mid-sized base model (roughly 300B parameters, a general-purpose base with fast inference characteristics), apply full-parameter reinforcement learning to optimize specifically for terminal and coding work, and reach parity with top closed-source solutions on a set of well-known benchmarks while keeping per-task inference cost significantly lower (the public material claims more than 30x lower).
Three abstractions matter here:
- Base model choice comes before stacking compute. Picking a base that is cheap to run inference on, supports long context, and handles tool calls reliably is equivalent to writing the cost advantage into the objective function, rather than compressing after training.
- Full-parameter training beats tuning lightweight modules only. Long-horizon tasks require the model to change behavior across the whole “plan–call–recover” chain, and adjusting a small number of parameters rarely produces a stable policy shift.
- Evaluation criteria must be unified. Pass@1 is only meaningful when compared under the same harness, the same maximum number of turns, and the same timeout settings; numbers measured across different harnesses cannot be compared directly.
3. Breaking Down the Training Recipe: Five Steps You Must Get Right
3.1 Task and Environment Construction
The first-order problem in long-horizon RL is not the algorithm but the environment. You need a task set whose success can be judged automatically, covering terminal operations, repository-level code changes, test-driven fixes, and similar types. Each task should have:
- A clear initial state snapshot and a rollback mechanism;
- Automated verification scripts (unit tests, integration tests, static checks);
- Strict resource and time limits, so a single trajectory cannot drag on indefinitely.
3.2 Verifiable Reward Design
Sparse rewards are the natural enemy of long-horizon tasks. A more robust approach in practice is layered rewards:
reward = w1 * test pass rate+ w2 * key milestones reached (e.g., compilation succeeds, target file produced)- w3 * number of ineffective tool calls- w4 * timeout and resource-limit penalties
The key points: rewards must be produced automatically by the environment to avoid manual labeling, and the penalty terms must suppress degenerate behavior such as inflating tool call counts.
3.3 Rollout and Sampling Strategy
Sampling for long-horizon tasks has to solve the problem of a long tail slowing everything down. Options include:
- Grouped sampling: sample multiple trajectories for the same task and normalize advantages within the group to reduce variance;
- Length stratification: bucket by historical trajectory length so short trajectories return results first and long ones are filled in asynchronously;
- Early stopping and pruning: terminate trajectories that clearly drift from the goal early, giving compute to more promising samples.
3.4 Engineering Constraints for Full-Parameter Updates
Full-parameter training at the 300B scale puts heavy demands on memory and communication. A common combination is tensor parallelism + pipeline parallelism + sequence parallelism, together with activation recomputation and optimizer state sharding. The easiest pitfall to hit in practice: when rollout and training share a cluster, long trajectories push peak memory usage up and cause frequent OOMs. It is advisable to isolate resources between the inference engine and the training processes, and to set a hard cap on context length.
3.5 Evaluation and Regression
Run a small regression set continuously during training, tracking Pass@1 and average trajectory length. If Pass@1 rises while trajectory length explodes, the model is trading longer attempts for success rate, and the cost benefit does not hold — you need to go back to the reward design.
4. Cost Control: Break Single-Task Cost Into Optimizable Terms
Single-task cost can be approximated as:
cost ≈ (average turns × context length per turn × unit token price) + environment execution cost
The optimization directions are therefore clear:
- Reduce average turns: better planning prompts and tool descriptions cut down ineffective probing;
- Control context growth: summarize and compress historical observations, keeping only information relevant to the decision;
- Improve cache hits: use prefix caching for repeated system prompts and tool descriptions;
- Cut environment-side cost: reuse sandboxes, pre-warm images, run independent subtasks in parallel.
When the model’s own inference price is low, the leverage of each of these optimizations is amplified — which is the fundamental reason to pick a cheap base first and do RL afterward.
5. Implementation Advice: A Phased Roadmap
- Phase 1 (1–2 weeks): Build the environment and verification scripts, get 50–100 automatically judgeable tasks running, and confirm the reward signal is reliable.
- Phase 2 (1–2 weeks): Validate at small scale whether RL produces a positive return, focusing on variance and the distribution of trajectory lengths.
- Phase 3 (3–5 days): Run full-parameter training on a cluster of around 64 GPUs, with strict limits on context length and single-trajectory duration.
- Phase 4 (ongoing): Establish unified evaluation criteria and a regression dashboard, tracking the performance–cost curve rather than a single metric.
6. Common Pitfalls
- Watching benchmark scores but not cost: the value of long-horizon agents lies in completing tasks affordably, so cost must be part of the objective function.
- Comparing across harnesses: differences in turn limits, timeouts, and tool sets across evaluation frameworks change results significantly.
- Neglecting environment engineering: when the environment is unstable, RL learns noise as if it were signal, and a training curve that looks like it is rising is actually degrading.
- Blindly scaling the cluster: adding capacity before sampling and the environment are optimized only scales the waste proportionally.
7. Conclusion
The barrier to long-horizon agent RL is shifting from compute scale to recipe quality. Starting from a mid-sized base and combining verifiable rewards, stratified sampling, strict resource constraints, and unified evaluation, a small cluster can complete a high-quality full-parameter run within days and push single-task cost significantly lower. For engineering teams, the most worthwhile investment is not more expensive GPUs, but a cleaner environment, more reliable rewards, and more disciplined context management.
