Long-Horizon Agent RL Training Recipe: Training a 300B-Class Agent on 64 Accelerators in 5 Days

    Long-horizon agents that operate for hours with hundreds of tool calls pose a steep challenge for reinforcement learning: single trajectories take hours to sample, failures waste GPU time, and rewards are sparse. This article breaks down a recently published training recipe that produced a 300B-class terminal and coding agent via full-parameter RL on 64 flagship AI accelerators in under 5 days, achieving Pass@1 of 46.2% on a major terminal-operation benchmark at 30x lower per-task cost than top-tier reasoning models. It covers the full recipe—base model choice, verifiable environments, reward design, sampling engineering, stability techniques, cost-performance Pareto analysis, and a practical reproduction checklist—and discusses its limitations.

    1. The Starting Problem: Why Long-Horizon Agents Are “Untrainable”

    The capability frontier of long-horizon agents is expanding rapidly: from early short interactions like “fix one bug, run one test” to multi-hour terminal operations and software engineering tasks—reading a codebase, locating defects, modifying multiple files, running builds and tests, and repeatedly rolling back and retrying based on error messages.

    This capability leap imposes harsh requirements on training paradigms. A single RL training sample is often not a tens-of-milliseconds forward pass, but a complete trajectory of roughly 3 hours containing hundreds of tool calls. This means:

    • High time cost: Sampling wall-clock time per trajectory is measured in hours, making sampling throughput an inherent bottleneck;
    • High failure cost: Mid-trajectory environment errors, unavailable images, or tool timeouts waste hours of accelerator time, not seconds;
    • Limited parallelism: Trajectories are strongly sequential internally (each step depends on the real execution result of the previous one), so intra-trajectory parallelization offers little speedup;
    • Sparse rewards: Only outcome signals such as whether final tests pass are available, and credit assignment spans hundreds of decisions.

    Frontier labs can run large-scale RL on thousands of accelerators, but most teams must answer a more practical question: Can you train an agent, with a few dozen accelerators over a few days, that stays competitive on public benchmarks while achieving significantly lower per-task inference cost?

    2. Key Results of the Public Recipe

    A recently published recipe answers yes: starting from a mid-sized general-purpose base model, through full-parameter reinforcement learning, within a budget of 64 flagship AI accelerators and less than 5 days, it produces a 300B-class terminal and coding agent.

    The key results can be summarized in three points:

    1. Same-tier capability: Pass@1 of 46.2% (averaged over 5 trials) on a major terminal-operation benchmark, in the same band as current top-tier frontier reasoning models;
    2. Substantially better cost: Average per-task cost is more than 30x lower than frontier models at the highest reasoning-effort setting, landing on the Pareto frontier of the accuracy–cost plane;
    3. Transferable capability: The gains are not single-benchmark overfitting; improvements were also observed on two public software engineering bug-fixing benchmarks.

    A caveat on measurement: the agent was self-deployed by the team, with costs computed from the base model’s public pricing; evaluation was done in the team’s self-built harness, so numbers may differ from official scores. Aligning such measurement differences is a prerequisite for any reproduction attempt.

    3. Recipe Breakdown: The Five Elements That Truly Determine Success or Failure

    3.1 Base Model and Why “Full Parameters” Matter

    Long-horizon tasks require large policy shifts, and training only a small set of adapter parameters is often insufficient to change the model’s multi-turn behavioral patterns (when to ask for help, when to roll back, how to compress context). Full-parameter updates adjust policy, value, and representations jointly; the cost is memory and communication pressure, which must be handled with parallel sharding and parameter synchronization mechanisms.

    3.2 Environments and Tasks: Verifiability as the First Principle

    • Containerized sandboxes: Each task runs in a reproducible image with pinned dependencies, restricted network, and minimal permissions;
    • Verifiable rewards: Objective signals such as unit tests, build artifacts, and file states serve as the final verdict, avoiding subjective scoring;
    • Difficulty tiering: Tasks are graded from “locate the issue” to “single-point fix” to “cross-file refactoring,” forming a curriculum that prevents early all-fail sampling from zeroing out gradients.

    3.3 Reward Design: Outcome-First, Process as Supplement

    Outcome rewards (whether tests pass) are the primary signal; process rewards fill only extremely sparse spots, such as format validity, tool-call parseability, and penalties for invalid actions. The design red line is preventing reward hacking: no “cheating” by modifying tests, faking logs, or skipping validation; where necessary, write-protect test files and critical paths.

    3.4 Sampling Engineering: The Real Bottleneck of Long-Horizon RL

    1. # Sketch: asynchronous partial-trajectory sampling + outcome-reward RL main loop
    2. for step in range(num_steps):
    3. batch = []
    4. # 1) Sample asynchronously; slow trajectories don't block the overall pace
    5. for task in sample_tasks(batch_size):
    6. traj = rollout_with_tools(policy, task, max_turns=120,
    7. timeout=TRAJ_TIMEOUT, sandbox=pool.acquire())
    8. if traj.env_error: # Environment failures tracked separately, excluded from policy gradients
    9. metrics.infra_fail += 1
    10. continue
    11. traj.reward = verify(task, traj) # Unit tests / build results
    12. batch.append(traj)
    13. # 2) Group-based baseline for advantage estimation, reducing variance
    14. adv = group_normalized_advantage(batch)
    15. # 3) Clipped objective + KL constraint + gradient clipping to stabilize long-sequence updates
    16. loss = clipped_policy_loss(policy, batch, adv) \
    17. + beta * kl_penalty(policy, ref_policy, batch)
    18. optimizer.step(clip_grad_norm(loss))
    19. sync_weights(rollout_engines, policy) # Training/inference weight sync

    Key points include: partial-trajectory reuse (unfinished trajectories continue sampling across steps), context compression and history truncation to control sequence length, and separate collection of failed trajectories for diagnosis rather than discarding them outright.

    3.5 Stability and Compute Orchestration

    Advantage normalization over long sequences, importance-ratio clipping, entropy floors, KL coefficient annealing, learning-rate warmup, and gradient clipping jointly determine whether training “doesn’t collapse.” On the engineering side, the 64 accelerators are split into a sampling pool and a training pool, with high-frequency weight synchronization and checkpoint-based resume to minimize the impact of hour-scale environment hiccups on training.

    4. How to Read the Cost–Performance Pareto Frontier

    You cannot evaluate an agent by score alone. Common practice is to plot Pass@1 against average per-task cost on logarithmic cost axes; only points on the frontier curve carry the meaning of “best at this price point.” Higher reasoning effort (longer thinking, more retries, larger sample counts) usually raises scores but sharply increases cost, whereas a well-trained model can reach the same score at low reasoning effort—this is exactly where the 30x cost difference comes from.

    5. Reproduction Checklist (Engineering Perspective)

    • Compute budget: Estimate accelerator-hours with a sampling-to-training ratio of roughly 2:1 to 3:1, then add a 20% margin for environment jitter;
    • Infrastructure: Run the sandbox pool on a container platform, store trajectories and checkpoints in object storage, and use logging services and monitoring/alerting to track environment failure rates, trajectory length distributions, and reward mean curves; on cloud platforms such as Baidu AI Cloud, these capabilities can be assembled from general-purpose categories (containers, storage, logging, monitoring);
    • Evaluation consistency: Fix the harness, images, and random seeds; report the mean over 5 trials;
    • Security boundaries: Sandbox network isolation, least-privilege credentials, and write protection of critical paths, to prevent training from being “rewarded” into dangerous behaviors.

    6. Limitations and Conclusion

    The public recipe still has boundaries: self-built harness scores cannot be directly compared with official results; cost conversion depends on public pricing assumptions; cross-benchmark transfer is verified, but generalization to private codebases requires recalibration. Its value lies in pulling long-horizon agent RL from a “thousand-accelerator privilege” back into an accessible range of “a few dozen accelerators, a few days,” while publishing the complete recipe—for most teams, reproducible engineering details deliver more long-term value than any single benchmark score.