Long-Horizon Agent Reinforcement Learning: A Low-Cost Training Guide
This article breaks down why long-horizon agent RL training becomes expensive and how to make it more cost-efficient. It explains the main cost drivers, reframes the optimization goal around a performance-cost Pareto frontier, and walks through a reusable six-step training recipe covering base model choice, reproducible sandbox environments, verifiable rewards, sampling control, compute budgeting, and consistent evaluation. It also lists common pitfalls and practical rollout advice for teams that want strong terminal and coding agents without wasting GPU hours.
1. Why Long-Horizon Agents Are So Expensive
Long-horizon agents are pushing task boundaries from “fix a single bug” to hours of continuous terminal operations and software engineering collaboration. A task is no longer a single question-and-answer exchange; it is a complete execution trajectory with hundreds of tool calls across multiple files and command contexts. As capability expands, training costs rise sharply.
The costs come from three layers:
- High time cost per sample. A single training sample often corresponds to a full attempt that lasts hours and involves hundreds of tool calls. A mistake at any step wastes hours of accelerator time.
- Long-tail failures and retries. Long-horizon tasks rarely fail immediately; they usually fail long after the run starts, so wasted compute cannot be reclaimed in time.
- High evaluation cost. If the evaluation setup does not match the training environment, teams keep investing in the wrong direction.
The core tension in long-horizon agent RL is therefore not whether compute is available, but the compute efficiency per effective sample.
2. Core Takeaway: Optimize for Cost-Effectiveness, Not Just Capability
A clear signal from public practice: a terminal and coding agent in the 30-billion-parameter range, starting from a smaller general-purpose base model and trained with full-parameter reinforcement learning, can reach a single-run pass rate on mainstream terminal benchmarks on par with leading closed-source solutions, while cost per task can be more than an order of magnitude lower. These gains also transfer to multiple software engineering benchmarks.
The key point is not any specific number but the methodology: write the optimization objective as a performance-cost Pareto frontier rather than maximizing a score alone. Once cost is part of the objective function, the training recipe naturally converges toward fewer wasted trajectories, shorter sampling chains, and more stable evaluation.
3. A Reusable Training Recipe in Six Steps
3.1 Base Model Choice and Why Full-Parameter Training Matters
Long-horizon tasks require the model to keep instruction following and tool-call formatting stable over long contexts. Training only a few adapter layers often fails to correct systematic drift in long chains. Full-parameter RL is more stable but costs more in memory and communication, so it needs parallel strategies and checkpointing.
3.2 Environment Setup: Make the Terminal a Reproducible Sandbox
- Use an isolated container for each rollout to avoid state contamination.
- Pin the file system, dependencies, and network policy so runs are replayable.
- Log the full action trace for every trajectory to support failure attribution.
Illustrative pseudocode:
for task in task_queue:env = sandbox.create(image=task.image, network=task.net_policy)traj = []for step in range(max_steps):action = policy.act(env.observe(), traj)obs = env.step(action)traj.append((action, obs))if obs.done or obs.timeout:breakreward = verifier(task, traj, env)buffer.add(traj, reward)env.close()
3.3 Rewards and Verification: Make Success Machine-Checkable
Sparse rewards are the biggest risk in long-horizon tasks. A workable approach is to split the verifier into layers: syntax and format checks, unit tests, end-to-end assertions, and a proxy metric for whether the run actually reduces later human intervention. Rewards should be objective and automatically executable; avoid subjective scoring that injects noise.
3.4 Sampling Strategy: Control Long-Tail Waste
- Set both a step limit and a wall-clock limit.
- Terminate trajectories early when an unrecoverable error appears.
- Use group sampling with advantage normalization to reduce variance.
- Increase sampling for high-value tasks and quickly drop low-value ones.
3.5 Compute Budget: Spend Limited Accelerators Where They Matter
A common thread in public practice is completing training on a smaller cluster over a shorter cycle. This requires:
- Overlapping sampling and training to reduce idle time.
- Writing checkpoints asynchronously to lower recovery cost after failures.
- Monitoring and alerting that cover queueing, memory, communication, and failure-rate metrics.
- Relying on a general-purpose container platform and queue capabilities for scheduling rather than a single vendor’s proprietary interface.
3.6 Unify the Evaluation Setup: Avoid Self-Referential Results
The training environment and the evaluation environment must share the same tool semantics and timeout policies. Fix random seeds, report the mean over multiple runs, and record both pass rate and average cost per task to produce a two-dimensional comparison.
4. Common Pitfalls and How to Avoid Them
- Reward leakage: the verifier reads reference answers it should not see, inflating results.
- Context bloat: history is concatenated without limit and inference cost spirals; summarize and trim instead.
- Tool semantic drift: tool descriptions differ between training and inference, so the model learns the wrong format.
- Score without cost: teams keep doubling down in the wrong direction.
- Ignoring reproducibility: the environment is not pinned, so conclusions cannot be reproduced.
5. Practical Rollout Advice
For most teams, the pragmatic path is to validate the environment and verifier on a small base model first, then scale parameters and sampling budget gradually; make cost per task a first-class metric on the dashboard; and build a reproducible pipeline on top of general-purpose object storage, logging services, monitoring and alerting, and a container platform. If managed training or inference capabilities are needed, teams can evaluate the general compute and platform offerings from Baidu AI Cloud, while keeping the evaluation setup neutral and results comparable.
6. Conclusion
Competition in long-horizon agent RL is shifting from “who has more accelerators” to “who produces fewer wasted trajectories.” Writing cost into the objective function, making the verifier solid, and unifying the evaluation setup are what actually push the performance-cost Pareto frontier outward.
