Low-Cost Training of Long-Horizon AI Agents with Reinforcement Learning

    This article presents a practical, low-cost recipe for training long-horizon AI agents with reinforcement learning. Starting from a 300B-class Flash-style base model and applying full-parameter RL on 64 high-bandwidth accelerators in under five days, the approach reaches a 46.2% Pass@1 on a terminal benchmark, matching top-tier closed-source solutions, with transfer gains on software engineering benchmarks and per-task costs more than 30x lower. It covers verifiable rewards, sampling efficiency, context and tool-call management, training stability, compute and parallelism strategy, evaluation, and limitations.

    1. Why Long-Horizon Agents Are Expensive to Train

    Long-horizon agents are moving beyond short interactions like fixing a single bug toward continuous terminal operations and software engineering tasks that run for hours. Their capability ceiling is determined by multi-turn tool calls, state observation, and self-correction—and this is exactly what drives up the cost of reinforcement learning (RL) training.

    A single training sample often corresponds to one complete attempt lasting about three hours and involving hundreds of tool calls. If any step fails along the way—a command timeout, a broken environment, a missing dependency—the wasted time is measured in accelerator hours. Frontier labs can run large-scale sampling across thousands of accelerators, but most teams face a more practical question: can you train an agent that approaches first-tier performance with a few dozen accelerators in a few days?

    The answer is yes, but you have to treat training as a systems engineering problem rather than simply piling on compute. The following is a complete, actionable recipe.

    2. Key Takeaways

    • Starting point: begin from a 300B-class general-purpose Flash-style base model rather than pretraining from scratch.
    • Training method: full-parameter reinforcement learning, not just training a few adapter layers.
    • Resource scale: 64 high-bandwidth accelerators, with a training cycle under five days.
    • Results: 46.2% Pass@1 on a terminal benchmark, on par with first-tier closed-source solutions; transfer gains also appear on software engineering benchmarks.
    • Cost: per-task cost is more than 30x lower than the highest inference-intensity option, creating a clear performance–cost Pareto advantage.

    3. Why Choose a “Flash-Style Base + Full-Parameter RL”

    3.1 The Base Model Sets the Cost Floor

    The per-task cost of an agent is mainly determined by the inference price of its base model. Choosing a Flash-style base that emphasizes high throughput and low latency lowers the starting point of the cost curve; subsequent RL only continues to optimize from that low starting point.

    3.2 Full-Parameter Training Sets the Capability Ceiling

    Long-horizon tasks require the model to continuously adjust its strategy within a “plan–execute–observe–correct” loop. Training only a small number of parameters is not enough to change the model’s underlying behavioral tendencies; full-parameter RL is what allows the model to genuinely learn to maintain goal consistency over long sequences.

    3.3 Combining the Two Creates a Pareto Advantage

    The low-price base handles cost, and full-parameter RL handles performance. Only by combining them can you occupy the upper-left region of the performance–cost plane at the same time.

    4. Six Key Modules of the Training Recipe

    Module 1: Task Environments and Verifiable Rewards

    The first principle of long-horizon RL is that rewards must be automatically verifiable. Terminal and coding tasks are naturally suited to this: whether unit tests pass, command exit codes, and file state differences can all serve as objective signals, avoiding the noise introduced by manual labeling and subjective scoring.

    It is recommended to divide tasks into three difficulty tiers: single-file fixes, cross-file changes, and multi-step terminal orchestration. Difficulty tiering keeps the sampling success rate within a learnable range (neither all correct nor all wrong).

    Module 2: Sampling Efficiency and Reusing Failed Samples

    Because a single trajectory is extremely expensive, you must maximize the information gained from each sample:

    • Keep multiple attempts at the same task and compute group-relative advantages, reducing dependence on the absolute reward scale;
    • Do not discard failed trajectories; use them to construct “error–correction” contrast signals;
    • Apply segment-level credit assignment for very long trajectories to avoid reward dilution.

    Illustrative pseudocode:

    1. for batch in task_queue:
    2. group = [rollout(task, temperature=t) for t in (0.7, 1.0, 1.3)]
    3. rewards = [verify(g) for g in group] # verifiable rewards
    4. adv = group_relative_advantage(rewards) # group-relative advantage
    5. loss += ppo_objective(group, adv, old_logp) # full-parameter update

    Module 3: Context and Tool-Call Management

    Hundreds of calls mean context management is the key to success or failure. Practical points include: structured compression of historical observations, retaining key error information, limiting ineffective repeated calls, and setting a uniform timeout and retry limit for tool returns. These engineering details directly determine whether a single trajectory can converge within three hours.

    Module 4: Stability of Full-Parameter Training

    • Use a small learning rate with sufficient warmup;
    • Clip policy updates to prevent advantage estimation jitter over long sequences;
    • Periodically monitor capability regression with a fixed evaluation set;
    • Decouple high-concurrency sampling on the environment side from updates on the training side, using a queue buffer to smooth out peaks.

    Module 5: Compute and Parallelism Strategy

    A workable way to split 64 accelerators: divide the cards into a sampling pool and a training pool. The sampling pool runs multiple environment replicas to produce trajectories, while the training pool performs full-parameter updates; the pace of both sides is controlled by a parameter synchronization interval. Use high-bandwidth inter-card interconnect to carry tensor and pipeline parallelism, use a container platform to orchestrate environment replicas, use object storage to save checkpoints and trajectories, and use logging, monitoring, and alerting services to locate stuck samples.

    Module 6: Evaluation and Cost Accounting

    Evaluation should fix the harness and random seeds, average over multiple runs, and report Pass@1 rather than a single result. Cost accounting must include sampling failures, retries, and environment rebuilds; otherwise, it will severely underestimate the real expenditure.

    5. Interpreting the Results: Consistent Transfer Across Three Benchmarks

    On a terminal benchmark, the trained model reaches 46.2% Pass@1, on par with first-tier solutions. More importantly, this improvement is not overfitting to a single benchmark—it transfers to two types of software engineering benchmarks. This shows that full-parameter RL learns a general long-horizon execution policy, not surface-level tricks targeting a specific test set.

    The cost side is equally clear: when per-task cost drops by more than an order of magnitude, the way agents are used shifts from “cautious trials” to “default large-scale invocation,” which in turn drives more long-horizon scenarios into production.

    6. A Reusable Implementation Checklist

    1. Choose a low-price, high-throughput base model to lower the cost starting point first;
    2. Build a tiered task set with verifiable rewards;
    3. Improve sampling efficiency with group-relative advantages and failed-sample reuse;
    4. Pair full-parameter updates with clipping and fixed-evaluation monitoring for stability;
    5. Separate the sampling pool from the training pool, using general cloud product categories for orchestration, storage, and observability;
    6. Accept results using two metrics: Pass@1 and a full-cost accounting basis.

    7. Limitations and Considerations

    The gains from this recipe depend on the verifiability of tasks; for open-ended tasks where rewards are hard to judge automatically, additional proxy metrics need to be designed. At the same time, long-horizon sampling places high demands on environment stability, and the engineering investment in the environment itself cannot be ignored. When reproducing this, teams should first validate reward signal quality at a small scale before scaling up to dozens of accelerators, avoiding wasting compute on the wrong objective function.

    In summary, the key to long-horizon agent RL is not compute scale but the combination of four things: a low-cost base, verifiable rewards, efficient sampling, and stable full-parameter training. Master this method, and small and medium-sized teams can likewise obtain near-first-tier agent capabilities within a matter of days and push per-task cost down to a range suitable for large-scale invocation.