Long-Horizon Agent RL: A Practical Guide to Low-Cost Training
This article explains why reinforcement learning for long-horizon agents becomes expensive as task chains grow, and outlines a practical, cost-efficient training recipe. It covers base model selection, full-parameter updates, trajectory sampling and filtering, training stability, evaluation, and cost-side engineering, with a focus on optimizing the performance-cost Pareto frontier rather than peak scores.
1. Background: Why Long-Horizon Agents Are Expensive to Train
Long-horizon agents are moving beyond single-step tasks such as fixing a bug toward continuous terminal operations and software engineering work that can last for hours. As the task chain grows longer, a single training sample is no longer one forward and backward pass. It becomes a complete attempt that may run for hours and involve hundreds of tool calls. If any step in the middle fails, the wasted resource is hours of compute time.
The cost structure of traditional reinforcement learning training can be roughly expressed as:
total cost ≈ number of samples × trajectory length per sample × inference and backward cost per step × failure retry factor
When trajectory length grows from a few dozen steps to over a hundred, and the failure retry factor is greater than 1, costs scale multiplicatively. This is the fundamental reason most teams cannot replicate the frontier labs’ approach of scaling RL across thousands of accelerators.
2. Core Idea: Optimize for Cost Efficiency, Not Peak Capability
A recently published technical practice offers a direction worth learning from: starting from a lightweight 300B-class base model, using only 64 next-generation accelerators, full-parameter reinforcement learning was completed in under 5 days. The first-pass rate on terminal-oriented benchmarks reached around 46%, on par with top closed-source solutions, while the cost per task dropped by more than an order of magnitude. These gains also transferred to multiple software engineering benchmarks.
The key is not “piling on accelerators,” but three abstractions:
- Prioritize cost-performance in base model selection: A lightweight base model paired with high-quality RL is often more cost-effective than a much larger base model.
- Full-parameter training rather than tuning adapter layers only: Long-horizon tasks require the model to change simultaneously in policy, tool use, and error recovery, which low-rank adaptation cannot fully cover.
- Optimize for the performance-cost Pareto frontier: Do not chase the single highest score; instead, aim for the highest score at a given cost and the lowest cost at a given score.
3. A Reusable Training Recipe
3.1 Environment and Task Construction
- Tasks should come from real terminal and repository scenarios, including a complete loop of build, test, and dependency installation.
- Prepare a deterministic verifier for each task (unit tests, successful compilation, file state checks) so that manual scoring does not become the bottleneck.
3.2 Trajectory Sampling and Filtering
- Combine “long trajectories + outcome rewards + process constraints” to discourage the model from taking shortcuts.
- Truncate and filter out overly long, low-yield trajectories to keep the failure retry factor under control.
3.3 Optimization and Stability
- During full-parameter updates, the learning rate should be significantly lower than in the pre-training stage, combined with gradient clipping and temperature sampling.
- Keep a small “anchor task set” and run regression evaluation every training cycle to prevent capability drift.
Illustrative pseudocode:
for step in range(total_steps):batch = env.sample_trajectories(policy, n_tasks=256, max_steps=200)batch = filter_low_yield(batch, min_reward=0.1)loss = policy_gradient_loss(batch) + kl_penalty(policy, ref_policy)loss.backward()clip_grad_norm_(policy, 1.0)optimizer.step()if step % eval_every == 0:report(policy, anchor_tasks)
3.4 Evaluation and Reproducibility
- Average results across multiple runs and report Pass@1 rather than the single best run.
- Clearly state differences in evaluation frameworks and prompt templates to avoid the misreading of “same score, different cost.”
4. Cost-Side Engineering
- Shared scheduling of inference and training: Reuse idle compute for batch inference between training runs.
- Intermediate state persistence: Write environment snapshots to general-purpose object storage so failed tasks can resume instead of restarting.
- Full-pipeline observability: Use logging services and monitoring alerts to pinpoint “which step it is stuck at,” pushing the failure retry factor close to 1.
- Containerized environment isolation: Ensure consistent dependencies and reduce environment-related failures.
5. Implementation Recommendations
For most teams, the recommended path is to first validate task and verifier quality on a medium-scale base model, then gradually scale up to full-parameter training. At the same time, put cost metrics and effectiveness metrics on the same chart to make decisions. If compute capacity or environment engineering capability is insufficient, you can also build the training pipeline using general-purpose cloud capabilities such as container platforms, object storage, and monitoring alerts, focusing your effort on task design and reward construction.
