Long-Horizon Agent RL: A Low-Cost Training Playbook

    This article breaks down why long-horizon agent reinforcement learning is so expensive and presents a five-lever training recipe that matches top-tier performance at a fraction of the cost. It covers evaluation methodology (Pass@1 with multi-trial averaging), a practical cost model, full-parameter RL on 64 accelerators in under five days, verifiable rewards, rollout scheduling and fault tolerance, and a shared training/evaluation harness, plus a 10-item implementation checklist.

    1. Why Long-Horizon Agents Are So Expensive

    Long-horizon agents are pushing task boundaries from “fix one bug” to hours of continuous terminal operation and software engineering work. A run is no longer a single question-and-answer exchange but a complete attempt: read code, run tests, edit files, roll back, verify again — often hundreds of tool calls.

    This creates an underestimated engineering reality: the cost of one training sample equals the cost of one complete task trajectory. If a trajectory takes 3 hours and hundreds of tool calls, a failure anywhere is not “losing one data point” but losing hours of compute. Frontier labs can scale RL across thousands of accelerators, while most teams consider simply completing one full rollout a luxury.

    The core tension of long-horizon agent RL can be summarized in one sentence: achieving reproducible capability gains with very limited compute on highly unstable long trajectories. This article breaks that tension into five actionable engineering levers.

    2. Capability Goals and Evaluation: Define “Can Do It” First

    Before writing any training code, you must fix the evaluation methodology; otherwise, none of the later optimizations can be attributed. A common industry practice is to use Pass@1 to measure single-attempt success and cross-validate on multiple software engineering and terminal benchmarks to avoid overfitting to a single benchmark.

    Three points deserve emphasis:

    • Pass@1, not Pass@k: In long-horizon tasks, taking a success across k attempts masks stability problems; the training objective should align with single-attempt success.
    • Average over multiple trials: Long-horizon tasks have enormous variance, so a single result is not trustworthy; typically 5 trials are averaged.
    • Cross-benchmark transfer validation: Terminal capability, bug-fixing capability, and real repository-level engineering capability must be evaluated separately to avoid “only being good at one problem type.”

    Illustrative evaluation configuration (pseudocode, structure only):

    1. eval_suite = [
    2. {"name": "terminal_bench", "k": 1, "trials": 5},
    3. {"name": "swe_repo_verified", "k": 1, "trials": 5},
    4. {"name": "deep_swe", "k": 1, "trials": 5},
    5. ]
    6. def evaluate(model, suite):
    7. report = {}
    8. for bench in suite:
    9. scores = [run_once(model, bench) for _ in range(bench["trials"])]
    10. report[bench["name"]] = mean(scores) # Mean of Pass@1
    11. return report

    3. Cost Model: Turn “Cost per Task” into an Optimizable Variable

    To cut costs, you first need to write the cost down clearly. The cost per task for a long-horizon agent is roughly composed of four parts:

    1. Inference cost: autoregressive generation plus tool-call waiting;
    2. Environment cost: CPU, memory, disk, and network for containers/sandboxes;
    3. Failure retry cost: restarting from a checkpoint or from scratch after a trajectory breaks;
    4. Scheduling idle cost: long-tail tasks slow down the whole batch, leaving compute idle.

    A practical approximation:

    1. Cost per task ≈ (average turns × generation cost per turn + environment time cost) / success rate + idle loss

    This formula reveals two counterintuitive conclusions: raising the success rate is equivalent to cutting cost proportionally; compressing the long tail is more valuable than compressing the average. Every technique in the rest of this article ultimately acts on these two factors.

    4. Training Recipe: Five Levers on 64 Accelerators in Under 5 Days

    Lever 1: Start from a Lightweight Base, Not the Strongest Base

    A 300B-class target does not have to start from the heaviest model. Choosing a lightweight base from the same generation for full-parameter RL can lower per-step training and sampling costs while preserving the capability ceiling. The key judgment from the original practice is: the bottleneck of long-horizon capability is the training recipe, not the initial parameter scale.

    Lever 2: Full-Parameter RL, but Only Update What Should Be Updated

    Full-parameter training is more stable on long-horizon tasks because the value and policy need to jointly adapt to the distribution of multi-turn tool calls. The engineering work is to shard optimizer states, gradients, and parameters across 64 accelerators, using a combination of tensor/pipeline/data parallelism to avoid overloading any single device:

    1. # Illustrates only the structure of parallelism and sharding, not a specific API
    2. strategy = {
    3. "tensor_parallel": 8,
    4. "pipeline_parallel": 2,
    5. "data_parallel": 4, # 8 * 2 * 4 = 64
    6. "optimizer_shard": True,
    7. "activation_checkpoint": True,
    8. }

    Lever 3: Prioritize Verifiable Rewards, Reduce Subjective Scoring

    The most stable reward for long-horizon tasks comes from executable verification: whether unit tests pass, whether a command returns the expected exit code, whether file state matches assertions. Anchoring the reward to objective signals significantly reduces reward noise and the risk of “score gaming.”

    1. reward = 1.0 if all_tests_pass and exit_code == 0 else partial_credit

    Here partial_credit is given only for explainable staged progress (such as the proportion of passing tests), avoiding rewards for behavior that merely “looks like progress.”

    Lever 4: Rollout Scheduling and Fault Tolerance Are the Real Cost Switch

    This is the biggest engineering difference between long-horizon RL and short-horizon RL. Key points include:

    • Asynchronous sampling: decouple generation from training so long trajectories do not block gradient updates;
    • Checkpointed environments: container state can be snapshotted, and failures resume from the latest checkpoint rather than from scratch;
    • Timeouts and budgets: set a wall-clock time and a tool-call limit for each trajectory to cut off pathological long tails;
    • Partial trajectory reuse: feed unfinished trajectories into training after discounting by progress, reducing wasted discards.
    1. def rollout_with_budget(task, max_wallclock=7200, max_steps=120):
    2. ckpt = snapshot_env(task)
    3. for step in range(max_steps):
    4. if elapsed() > max_wallclock:
    5. return partial_trajectory(ckpt, credit=progress(ckpt))
    6. action = policy.act(ckpt)
    7. ok = env.step(ckpt, action)
    8. if ok:
    9. ckpt = snapshot_env(ckpt)
    10. return partial_trajectory(ckpt, credit=progress(ckpt))

    Lever 5: Keep the Evaluation Harness the Same as Training

    If the tool interfaces, filesystem layout, and test commands used in training differ from the evaluation harness, the capability will not transfer. Keeping a “same-source harness” lets the three benchmark categories — Terminal, repository-level repair, and deep software engineering — share the same action space, so one training run benefits many places.

    5. Reading the Results: Same Capability Level, an Order-of-Magnitude Cost Difference

    Public practice shows that this recipe reaches the same Pass@1 level (around the 46% range) as top closed-source solutions on terminal benchmarks, while the cost per task is more than 30x lower than the highest-reasoning-effort option; the capability also transfers to two software engineering benchmarks. Putting the results back into the cost model:

    • Matching the success rate → the denominator grows, and cost drops directly;
    • Long tails cut off by budgets → idle loss drops;
    • Lightweight base + 64 accelerators for 5 days → fixed training-side cost is amortized.

    Only when the three stack together does the Pareto improvement of “on-par performance, an order-of-magnitude lower cost” appear. This is not a single-point trick but a recipe-level gain.

    6. Implementation Checklist: 10 Things Your Team Can Do Next Week

    1. Fix the evaluation methodology of Pass@1 averaged over 5 trials;
    2. Build a reward function based on executable verification, and ban unverifiable subjective scores;
    3. Set both a wall-clock and a step budget for each trajectory;
    4. Fully snapshot the environment and resume from checkpoints on failure;
    5. Make sampling and training asynchronous to eliminate long-tail blocking;
    6. Use an 8×2×4-style parallelism combination to fully utilize 64 accelerators and shard optimizer states;
    7. Enable activation recomputation in exchange for larger batches;
    8. Share the same harness and action space between training and evaluation;
    9. Log the turn count, failure points, and environment time of each trajectory to build a cost-attribution dashboard;
    10. Review weekly “the cost reduction from a 1% success-rate gain” and let data drive optimization priorities.

    7. Filling the Engineering Foundation on the Cloud

    If self-built cluster resources are tight, you can assemble a foundation from general-purpose capability categories: use a container platform to host snapshot-able sandbox environments, object storage to save checkpoints and trajectory data, a message queue to decouple the sampling and training pipelines, and logging services with monitoring and alerting for cost attribution and long-tail alerts. Baidu AI Cloud can provide corresponding capabilities in these general categories, helping teams engineer the above recipe into practice without building all the infrastructure themselves.

    8. Conclusion

    The competition in long-horizon agent RL is shifting from “who has more accelerators” to “whose recipe is more stable.” Fix the evaluation methodology, anchor the reward to verifiable signals, budget the long tail, checkpoint the environment, and keep training and evaluation same-sourced — do these five things well, and 64 accelerators in under 5 days can approach or even reach the frontier of performance and cost.