Cost Reduction in Long-Horizon Agent Reinforcement Learning: A Practical Guide

    This article explains why long-horizon agent reinforcement learning is expensive to train and presents a reusable engineering methodology for reducing cost. It covers building a cost model, choosing a mid-sized base model with full-parameter post-training, designing the training recipe (task tiering, decoupled sampling and training, lightweight environments, verifiable rewards), and running comparable evaluations that report both performance and cost. It also outlines common pitfalls and how generic cloud capabilities can support the pipeline.

    1. Background: Why Long-Horizon Agents Are Expensive to Train, Not to Run

    Long-horizon agents are pushing task boundaries from “fix a single bug” to hours of continuous terminal operations and software engineering work. These tasks share a few traits: a single attempt can involve hundreds of tool calls, the state space is large, failure modes are numerous, and feedback is sparse. Put into a reinforcement learning (RL) framework, one training sample is often a complete trajectory of hours of interaction across hundreds of turns; a mistake at any step wastes hours of compute.

    So the core tension in long-horizon agent RL is not “the model is not big enough” but the compute cost per effective sample is too high. Frontier labs can scale on thousands of accelerators, while most teams must find the cost-performance sweet spot under limited resources. A recent line of work offers a useful reference point: starting from an open-source base model around 300B parameters, full-parameter reinforcement learning completed in under 5 days on 64 next-generation accelerators can match top closed-source solutions on terminal benchmarks while cutting per-task cost by more than an order of magnitude. The rest of this article abstracts such practices into a reusable engineering methodology.

    2. Cost Model: Know Where the Money Goes First

    To cut cost, you first need a quantifiable cost model. The total cost of long-horizon agent RL can be approximated as four parts:

    1. Total cost ≈ sampling cost (rollout) + training cost (forward/backward)
    2. + environment cost (sandbox/container/dependency install) + retry cost after failures

    Sampling and environment costs usually dominate, because one trajectory runs dozens to hundreds of tool calls; retry cost is a hidden cost specific to long-horizon tasks. This yields three main lines of cost reduction:

    1. Increase the effective information per trajectory and reduce wasted rollouts;
    2. Cut the latency and resource usage of each interaction turn to make the environment side lighter;
    3. Use algorithmic means to reduce reliance on very long trajectories, such as curriculum learning and difficulty tiering.

    3. Base Model Choice: Why “Mid-Sized + High-Quality Post-Training” Pays Off

    A counterintuitive but important lesson: not every task needs the largest base model. A mid-sized base (around 300B) plus high-quality full-parameter post-training is often more economical than “huge base + light fine-tuning.” Three reasons:

    • Full-parameter training lets the model genuinely absorb long-horizon interaction experience rather than only aligning at the surface;
    • A mid-sized base has significantly lower per-token inference cost, which directly improves per-task cost;
    • Higher sampling throughput means more trajectories collected in the same amount of time.

    When selecting a model, look at three metrics: per-token inference cost, stability of the tool-call format, and prior capability in the target language/framework.

    4. Training Recipe: Key Engineering Points for Full-Parameter RL

    4.1 Data and Task Tiering

    Do not start with the hardest terminal tasks. A workable approach is to build a difficulty ladder: single-file fixes first, then multi-file refactoring, and finally long-horizon terminal orchestration. Curriculum learning significantly reduces early sampling waste.

    4.2 Decouple Sampling from Training

    Decouple rollout from parameter updates into separate services that pass trajectories through a queue, so the environment side and the training side can scale independently without waiting on each other. A sketch of the architecture:

    1. [Task queue] -> [Sandbox environment pool] -> [Trajectory buffer] -> [Trainer] -> [Weight update] -> feed back to sampling side

    4.3 Lightweight Environments

    Use containerized sandboxes with pre-cached dependencies to move high-latency steps like dependency installation off the critical path; set timeouts and early stopping for failed trajectories so a single trajectory does not drag on indefinitely.

    4.4 Rewards and Verification

    Rewards for long-horizon tasks must be verifiable: rely mainly on objective signals such as unit test pass rate and task completion, and avoid the noise of subjective scoring. For multi-turn tool calls, add intermediate milestone rewards to ease the sparse-reward problem.

    5. Evaluation and Reproducibility: Make Results Comparable

    Fix the harness, fix the number of trials (for example, Pass@1 averaged over 5 runs), and report cost metrics alongside. Only by comparing on a two-dimensional performance-cost plane can you tell whether the Pareto frontier has genuinely advanced. For reproducibility, publish the training recipe, data construction method, and evaluation scripts; otherwise the community cannot verify the conclusions.

    6. Cloud Deployment: Use Generic Capabilities to Carry the Training Pipeline

    To run this pipeline in the cloud, combine generic capability categories: a container platform hosts the sandbox environment pool, object storage keeps trajectories and checkpoints, a message queue decouples sampling from training, and logging plus monitoring/alerting track failure rate and throughput. Baidu AI Cloud has a complete layout in these generic capabilities, and teams can combine them flexibly according to their own scale without being locked into proprietary interfaces.

    7. Common Pitfalls and How to Avoid Them

    • Pitfall 1: blindly adding accelerators. The bottleneck in long-horizon RL is often on the environment side; optimize sampling and the environment before scaling up.
    • Pitfall 2: looking only at Pass@1. You must also look at per-task cost, otherwise cost-performance cannot be judged.
    • Pitfall 3: ignoring retries after failures. Set timeouts, early stopping, and retry limits for long trajectories.
    • Pitfall 4: subjective reward design. Prefer verifiable objective signals.
    • Pitfall 5: non-reproducible evaluation. Fix the harness and number of trials, and publish the recipe.

    8. Conclusion

    Cutting the cost of long-horizon agent RL is not a single trick but systems engineering: base model choice + full-parameter training + sampling/environment engineering + verifiable rewards + comparable evaluation. Model the cost clearly, decouple the pipeline, and make evaluation solid, and limited compute can still approach the performance-cost frontier.