Long-Horizon Agentic RL: Training a 321B Model on 64 GPUs in Under 5 Days
This article examines how full-parameter reinforcement learning can turn a sparse 321B-parameter model (about 17.4B active parameters per token) into a long-horizon agent that reaches 46.2% Pass@1 on a terminal benchmark at more than an order of magnitude lower cost per task than the highest reasoning-effort configuration. It breaks down why long-horizon agentic RL is difficult, covering sparse and delayed rewards, unavoidable off-policy trajectories, precision and memory constraints, and the mismatch between training and evaluation harnesses. It then details the three engineering pillars behind the result: verifiable environment filtering with difficulty stratification, an RL recipe for long, stale, low-precision rollouts, and a unified programming harness shared by training and evaluation. The article also explains the trainable scope design, the boundaries for interpreting the reported numbers, and a practical checklist for teams.
1. The Starting Point: The Performance–Cost Imbalance in Agent Capabilities
Over the past two years, the capability curve of terminal-operation and software-engineering agents has risen quickly. But that progress often comes at the price of ballooning inference cost: models are asked to repeatedly self-check, backtrack, and resample under high reasoning effort, so the cost per task grows linearly or even super-linearly. What the industry actually needs is not “the single strongest answer,” but the highest possible task success rate under an acceptable cost constraint—the so-called performance–cost Pareto frontier.
The original practice produced an instructive result: a sparsified base model with roughly 321B total parameters and about 17.4B active parameters per token was converted through full-parameter reinforcement learning and reached 46.2% Pass@1 on a terminal-task benchmark, on par with the leading closed-source solutions at the time, while costing more than an order of magnitude less per task than the highest reasoning-effort configuration. That advantage also transferred to two real-world software-engineering benchmarks. More remarkable is the training cost: 64 next-generation accelerator cards, less than 5 days, with the recipe fully disclosed.
The engineering question behind this can be stated in one sentence: how do you actually train long-horizon decision-making into a model on a hundred-GPU-class cluster within a controlled wall-clock time?
2. Why Long-Horizon Agentic RL Is Hard
1. Sparse and Delayed Rewards
Terminal and coding tasks usually give a success-or-failure signal only at final acceptance, with no dense reward across the dozens of intermediate tool-calling turns. Credit assignment spans a very long trajectory, and the signal-to-noise ratio of the gradient is extremely low.
2. Off-Policy Trajectories Are Unavoidable
Agent rollouts are asynchronous, long-running, and heterogeneous. By the time a 200-turn trajectory finishes, the policy has already been updated several times, so the data is naturally off-policy. Forcing strict on-policy handling would make sample utilization so low that convergence within 5 days becomes impossible.
3. Real Constraints on Precision and GPU Memory
Long trajectories require storing large amounts of activations and KV states, which often forces the training side to use low-precision communication and computation. Low precision amplifies the variance of importance-sampling ratios and makes policy updates unstable.
4. The “Two Harnesses” Trap in Evaluation and Training
Many teams train with one agent framework and evaluate with another, causing the training objective to diverge from real deployment behavior: offline gains, online regressions.
3. Method Breakdown: Three Pillars Supporting Frontier Efficiency
Pillar One: Environment Filtering That Makes Every Task “Exactly Learnable”
More tasks is not necessarily better. The goal is to build a training-environment pool with a sensible difficulty distribution and reliable verification signals. Key practices include:
- Difficulty stratification: Measure the current policy’s pass rate on candidate tasks and keep tasks whose pass rate falls in a middle band (neither almost always correct nor almost always wrong); these samples contribute the most gradient signal.
- Verifiability first: Prefer tasks with deterministic acceptance methods (unit tests, command exit codes, file-state comparison) and avoid subjective scoring that introduces noise.
- Decontamination and leak removal: Remove tasks that may already appear in the training corpus to prevent false gains from “memorizing answers.”
- Dynamic curriculum: Resample the task pool as training progresses so difficulty drifts with model capability.
A schematic filtering logic can be written as:
def build_batch(pool, policy, lo=0.2, hi=0.8, size=256):kept = []for task in pool:p = estimate_pass_rate(policy, task, trials=4)if lo <= p <= hi: # mid-difficulty band carries the strongest signalkept.append((task, p))# Prioritize closeness to 0.5 while preserving diversitykept.sort(key=lambda x: abs(x[1] - 0.5))return sample_diverse(kept, size)
Pillar Two: An RL Recipe for “Long, Stale, Low-Precision” Rollouts
This is the most hardcore part of the whole approach, summarized in four engineering principles:
- Accept off-policy data, but apply controlled corrections: Use truncated importance-sampling ratios to suppress extreme weights; down-weight stale trajectories by “age” rather than discarding them outright.
- Trajectory-level advantage plus key-step weighting: On top of the outcome reward, give higher weight to tool-calling steps that trigger state changes (such as writing files or running tests) to ease long-horizon credit assignment.
- Numerical stability under low precision: On the training side, keep higher-precision accumulation for logits and ratio computation; use low precision for communication but route critical reductions through a high-precision path; clip and skip abnormal gradients.
- Asynchronous pipeline: Decouple rollout from training, with the generation side continuously supplying data and the training side consuming from a queue, minimizing GPU idle time—this is the precondition for the 5-day window.
A pseudocode skeleton:
for step in range(total_steps):trajs = rollout_queue.get(batch=B) # asynchronous, possibly staleratios = clipped_is_ratio(trajs, eps=1e-3) # truncated importance samplingadv = outcome_advantage(trajs) * step_weight(trajs)loss = -(min(ratios * adv,clip(ratios, 1 - c, 1 + c) * adv)).mean()loss.backward(); clip_grad_norm_(model, 1.0); opt.step()
Pillar Three: One Programming Harness Shared by Training, Optimization, and Evaluation
The value of a unified agent runtime framework is often underestimated. It ensures that the action space, tool-return formats, timeout and retry policies seen during training are exactly the same as in online evaluation. It also makes it easy to automatically feed failed trajectories back as training environments and regression cases, forming a closed loop. Engineering recommendations:
- Version tool interfaces, and require changes to pass regression;
- Keep full-chain logging and reproducible random seeds;
- Isolate execution in sandboxes with restricted network and filesystem permissions;
- Share the same acceptance scripts between evaluation and training to prevent split metric definitions.
4. Designing the Trainable Scope
Full-parameter training does not mean “every module moves together.” A pragmatic approach is to update all language parameters (including the multi-token prediction auxiliary layer) while freezing the vision encoder and the sparse attention index structure. The rationale is straightforward: language and decision-making are the capabilities to improve here, while keeping the vision and index modules frozen significantly reduces memory and communication pressure and avoids damaging existing representations with small samples. Combined with tensor/pipeline parallelism, activation recomputation, and paged caching, a hundred-GPU-class cluster can support policy updates for a 300B-class model.
5. How to Interpret the Results Correctly
Three boundaries should be emphasized to avoid misreading:
- Pass@1 is averaged over multiple trials and has evaluation variance; cross-team number comparisons require aligned harnesses and sampling configurations;
- The cost of a self-deployed model should be converted at equivalent public prices to be compared on the same basis as commercial solutions;
- The advantage comes from the systems engineering of “environment filtering + off-policy recipe + unified framework,” not from a single trick.
6. A Practical Checklist for Teams
- Build a verifiable task pool and difficulty statistics first, then discuss algorithms;
- Use asynchronous rollout to break the throughput bottleneck, and accept and correct stale data;
- Always add numerical guardrails and gradient clipping for low-precision training;
- Share one harness between training and evaluation, with failed trajectories automatically fed back;
- Use “success rate under a cost constraint” as the single north-star metric, and plot the Pareto curve to drive decisions.
In a reality of limited compute, squeezing every bit of loss out of systems engineering often buys frontier-level cost-efficiency more effectively than simply adding more cards. Baidu AI Cloud, with general capabilities such as container platforms, object storage, log services, and monitoring and alerting, can provide infrastructure support for this kind of long-running training and large-scale sandbox execution.
