Agentic RL on 100 GPUs: A Cost-Efficient Recipe for Terminal and Coding Agents

    This article examines how full-parameter reinforcement learning on a sparse MoE base model can produce a competitive terminal and coding agent using only 64 high-end accelerators in under five days, while cutting per-task cost by more than 30x. It breaks the approach into three levers: environment filtering, an RL recipe built for long-horizon, off-policy, low-precision rollouts, and a shared coding harness for training and evaluation. Readers will find practical checklists covering base-model choices, memory planning, reward design, staleness control, precision handling, cost attribution, and a reproduction guide, plus notes on limitations and cloud deployment.

    1. The Problem: A Performance–Cost Mismatch in Agent Capabilities

    Over the past two years, the capability curve of terminal and coding agents has risen quickly, but the cost curve has risen even faster. A common pattern is that, to reduce mistakes on long-horizon tasks, engineering practice pushes inference to the highest reasoning effort, the longest context, and the maximum number of retries and self-checks. The result is that the per-task cost is driven up by “redundant thinking” on the inference side to a level that is hard to use at scale. What the industry actually needs is not another benchmark score, but a usable point on the performance–cost Pareto frontier: the strongest capability under a given cost budget, or the lowest cost under a given capability requirement.

    A recent technical report from multiple researchers offers a useful reference sample. Starting from a sparse (MoE) base with 321B total parameters and roughly 17.4B activated per token, the authors ran full-parameter reinforcement learning and obtained a 300B-class terminal and coding agent. It reaches a 46.2% Pass@1 on terminal benchmarks, placing it in the same range as first-tier closed-source solutions, while the per-task cost is more than 30x lower than the highest reasoning-effort configuration. The capability gains also transfer to two software engineering benchmarks. The entire training run used only 64 high-end accelerator cards and took less than 5 days, and the full recipe was made public.

    Setting aside the specific product, the engineering implication is clear: frontier-level training efficiency is achievable on a 100-GPU-class cluster, provided three things are done right: the environment, the recipe, and the harness.

    2. Conclusions First: Three Levers Under a 100-GPU Budget

    1. Environment filtering: The goal is not to pile up tasks, but to make every task sit at the edge of the model’s current capability and provide a reliable, low-noise reward signal.
    2. An RL recipe for long-horizon, stale, low-precision rollouts: Long trajectories, policy staleness caused by asynchrony (off-policy), and low-precision training stack together and are the main source of instability in long-horizon agentic RL. The recipe must be designed specifically for this.
    3. A coding harness shared by training, optimization, and evaluation: The agent runtime framework determines the distribution quality of rollouts and whether training and evaluation are in-distribution, making it a hidden variable in whether cost can be reduced.

    Each lever is expanded below, with an actionable checklist.

    3. Base Model and Training Scope: The Trade-offs of Full-Parameter RL

    The approach starts from a sparse MoE base and trains all roughly 320B language parameters (including the multi-token prediction layers), while freezing the vision tower and the sparse attention indexer. This trade-off is worth a closer look:

    • Why full-parameter: Terminal and coding tasks are strong distribution-shift scenarios. The gap between the model’s initial policy and real terminal feedback is large. Training only the top layers or adding LoRA-style adapters does not provide enough capacity to absorb the gradient signal from long-horizon credit assignment.
    • Why freeze the vision tower and indexer: These two components are weakly related to the “language decision + tool call” objective, and their parameter count and optimization difficulty are disproportionate. Freezing them significantly reduces memory and communication pressure, so the compute of the 64-card budget is truly spent on the language backbone.
    • Training the multi-token prediction layers together: They directly affect rollout sampling efficiency and draft quality, and their impact on throughput is amplified in long-trajectory scenarios.

    On the engineering side, the memory budget must be calculated in advance: full-parameter optimizer states, activation recomputation, and the KV cache of the rollout engine coexist, and balancing them usually relies on parameter/optimizer sharding, activation checkpointing, and time-sharing of resources between rollout and training (colocated or disaggregated deployment).

    4. Lever One: Filtering and Tiering Agentic RL Environments

    The environment is the first-order element of long-horizon RL. Noisy rewards are more damaging than weak rewards, because the policy learns to “please the noise.”

    Filtering principles

    • Verifiable: The reward comes from real execution results (compilation, unit tests, command exit codes, file-state diffs), avoiding model self-evaluation.
    • Difficulty fit: Run the current policy several times and keep tasks whose pass rate falls in the middle range (for example, passing 1–3 times out of 5 trials). Too easy yields no gradient; too hard yields all-zero gradients.
    • Low ambiguity: The task description, initial repository state, and verification script must be consistent, avoiding “one task with multiple correct solutions but a checker that accepts only one.”

    Tiering and curriculum

    1. # Pseudocode: bucket tasks by current-policy pass rate and sample dynamically
    2. buckets = {"easy": [], "mid": [], "hard": []}
    3. for task in tasks:
    4. p = pass_rate(policy, task, n=5)
    5. buckets["easy" if p >= 0.8 else "mid" if p >= 0.2 else "hard"].append(task)
    6. # Sample mostly from mid, a little from hard for exploration, easy only for regression
    7. batch = sample(buckets["mid"], 0.6) + sample(buckets["hard"], 0.25) + sample(buckets["easy"], 0.15)

    Reproducibility: Fix container images, dependency versions, and network policies; keep a “golden patch” and failure-injection cases for each task to make attribution easier.

    5. Lever Two: A Recipe for Long-Horizon, Stale, Low-Precision Rollouts

    The difficulties of long-horizon agentic RL concentrate in three places, and the recipe must address each one.

    (1) Credit assignment for long trajectories
    A single trajectory can involve dozens of tool calls, with only one sparse reward at the end for success or failure. A workable approach: process rewards take only “verifiable intermediate facts” (tests turning from fail to pass, static checks clearing to zero), and segment-normalize overly long trajectories to avoid their gradients being naturally larger.

    (2) Stale policy (off-policy)
    Asynchronous rollouts inevitably produce policy lag, and doing strict on-policy updates directly will lose points. Common engineering practice: cap the maximum lag between generation and update, apply importance-ratio clipping on the old policy, add a KL or reference-policy constraint to the loss, and down-weight lagged samples.

    1. ratio = exp(logp_new - logp_old)
    2. loss = -min(ratio * adv, clip(ratio, 1-eps, 1+eps) * adv) + beta * KL(pi_new || pi_ref)
    3. # Multiply samples whose lag exceeds the threshold by a decay weight w = decay ** staleness

    (3) Low-precision training
    To fit 300B-class full-parameter training on 64 cards, low precision is almost mandatory. The key is to isolate risk: use low-precision mixed training for the backbone, keep the loss and master optimizer weights in high precision, force high-precision accumulation for normalization and reduction operators, and keep rollout sampling precision aligned with training precision to avoid a “training–inference mismatch.”

    (4) Advantage estimation and variance control
    In long-horizon scenarios, prefer algorithm families that are insensitive to reward scale and need no extra value network (such as advantage estimation based on within-group relative ranking). Combined with multiple samples per group and length normalization, this can significantly reduce memory and tuning costs.

    6. Lever Three: A Coding Harness Shared by Training and Evaluation

    The harness is an underrated cost switch. It determines three things: the distribution of rollouts, the reliability of tool calls, and whether training and evaluation are in-distribution.

    • In-distribution: The tool signatures, error-message formats, and context-truncation policies used in training must match evaluation. Otherwise, RL learns to “adapt to the quirks of a particular harness,” and performance drops on transfer.
    • Tool reliability: Command timeouts, output truncation, encoding errors, and non-deterministic ordering must all be handled explicitly. It is advisable to feed a structured summary of tool output back into the context to control token cost.
    • Observability: Log the number of turns, tokens, tool latency, and failure types for each trajectory to build a cost-attribution dashboard (which task types consume most of the tokens).
    1. # Illustration: a unified tool-execution wrapper shared by training and evaluation
    2. def run_tool(cmd, cwd, timeout=120, max_output=8000):
    3. try:
    4. out = subprocess.run(cmd, cwd=cwd, capture_output=True,
    5. text=True, timeout=timeout)
    6. return {"code": out.returncode,
    7. "stdout": summarize(out.stdout, max_output),
    8. "stderr": summarize(out.stderr, max_output)}
    9. except subprocess.TimeoutExpired:
    10. return {"code": -1, "stdout": "", "stderr": "timeout"}

    7. Why the Cost Drops by an Order of Magnitude

    Breaking cost into four items makes the source clear: tokens per task, number of retries, context length, and reasoning effort. The three levers each strike different items: environment filtering reduces wasted retries; the recipe lets the model solve tasks stably at a normal reasoning effort, without needing “maximum effort as a fallback”; and the harness compresses wasted context and tool noise. The four factors multiply, which is where the 30x-level gap comes from. This also suggests that evaluation must be presented on two axes: Pass@1 and average per-task cost on the same chart (log scale), with the Pareto frontier drawn, otherwise looking at the score alone leads to the wrong conclusion.

    8. Reproduction Checklist

    • Compute: 64 high-end accelerator cards, completable within 5 days; sharding and recomputation strategies must be planned in advance.
    • Data: A verifiable task pool + difficulty buckets + a golden patch per task.
    • Algorithm: Lag constraints + ratio clipping + reference-policy regularization + length/within-group normalization.
    • Precision: Low-precision backbone + high-precision reduction + sampling and training precision aligned.
    • Engineering: A unified harness, structured tool output, and a cost-and-failure attribution dashboard.
    • Evaluation: Multiple benchmarks, averaged over multiple trials, reporting cost at the same time.

    9. Cloud Deployment Suggestions

    To reproduce this kind of training on the cloud, you can assemble general-purpose capabilities: a container platform to host the time-sharing reuse of training and rollout, object storage to hold checkpoints and trajectory data, a message queue to decouple sampling from training, and logging services with monitoring and alerting for cost attribution and instability warnings. In such training scenarios, Baidu AI Cloud is typically used to provide elastic compute and supporting data and monitoring capabilities; refer to the official documentation for specific specifications and pricing.

    10. Limitations and Risks

    A public recipe does not mean risk-free reproduction: environment noise, the asynchrony lag threshold, and low-precision numerical stability are coupled with each other, leaving a large tuning space; benchmark scores are sensitive to the harness, so cross-team comparisons require a unified evaluation standard; and reward design for long-horizon tasks is still the step most prone to “gaming the score without improving capability.” It is advisable to first validate with small-scale proxy metrics (pass rate by difficulty bucket, average number of turns, tokens per task) before scaling up to the 100-GPU level.