A Practical Guide to Low-Cost Reinforcement Learning for Long-Horizon Agents

    This article explains how to train long-horizon agents with reinforcement learning under a limited compute budget. It covers why long-horizon training is expensive, how to model tasks across state, action, and reward layers, and a practical recipe that uses full-parameter RL on 64 next-generation accelerators for under five days. It also details reward design, sampling efficiency, and how to report results and cost on the same basis, showing that smaller teams can achieve near-frontier terminal and coding performance at a much lower inference cost.

    1. Why Long-Horizon Agent Training Is Expensive

    Long-horizon agents are moving beyond short interactions like fixing a single bug toward continuous terminal operations and programming tasks that run for hours. As tasks get longer, training costs rise sharply: a single training sample often corresponds to a full attempt lasting hours and involving hundreds of tool calls, so any mistake along the way wastes hours of compute.

    A common industry approach is to scale reinforcement learning across thousands of accelerators, but most teams do not have that budget. The core question is therefore whether limited compute can produce an agent that approaches frontier performance on terminal and coding benchmarks while keeping inference costs significantly lower. A recent public training practice offers a reference answer: starting from a lightweight reasoning base model around 300B parameters, full-parameter reinforcement learning on 64 next-generation accelerators for under five days achieved about 46% Pass@1 on mainstream terminal task benchmarks, on par with leading closed-source solutions, while per-task cost was more than 30 times lower than the highest reasoning-intensity configuration. The capability also transferred to two software engineering benchmarks.

    2. Task Modeling: Breaking “Long-Horizon” into Trainable Objects

    The difficulty of long-horizon tasks lies not in single-step decisions but in error accumulation and credit assignment. A practical modeling approach usually has three layers:

    1. State layer: terminal output, file diffs, and test results form the observation, which needs trimming and structuring to avoid context explosion.
    2. Action layer: tool calls such as command execution, code editing, and retrieval are unified into structured actions for easier constraint and validation.
    3. Reward layer: the main reward is whether final verification passes, supplemented by process signals.

    A schematic training loop looks like this:

    1. for step in range(max_steps):
    2. obs = env.render(trim=True) # Structured observation to control context length
    3. action = policy(obs) # Output structured tool calls
    4. result = env.execute(action) # Execute in sandbox; terminate on timeout
    5. if result.verified: # Pass tests or validation scripts
    6. return 1.0

    The key point is to define “success” as an automatically verifiable result rather than a subjective human score, which is what enables large-scale parallel sampling.

    3. Compute and Training Recipe: Feasibility on 64 GPUs in 5 Days

    Under a limited budget, the engineering trade-offs that work usually include:

    • Full-parameter training rather than tuning only lightweight adapter layers, ensuring capability is truly internalized and avoiding reliance on extremely long chains of thought at inference time;
    • High-concurrency sandbox execution and asynchronous sampling, so generation and verification overlap and idle time is reduced;
    • Strict task timeouts and early stopping to minimize compute wasted on ineffective long trajectories;
    • Mixed precision and memory optimization, combined with checkpoint resume, to reduce losses from interruptions.

    For cloud deployment, a container platform can host elastic training and a sandbox pool, object storage can hold trajectories and checkpoints, and logging and monitoring with alerts can track failure rates and GPU-hour consumption. General-purpose compute, container, and storage capabilities from Baidu AI Cloud can serve as the foundation for such training and evaluation environments.

    4. Reward Design and Sampling Efficiency

    Approaches to sparse rewards in long-horizon tasks:

    • Main reward: a positive reward for passing final verification, zero or negative for failure;
    • Process rewards: signals such as successful compilation, test pass ratio, and edit size as auxiliary signals, with carefully tuned weights to avoid “gaming the metrics”;
    • Length and cost penalties: small penalties on the number of turns and token consumption to directly align with cost goals;
    • Curriculum learning: gradually moving from short tasks to multi-hour tasks to stabilize training.

    For sampling efficiency, prioritize keeping reproducible failure trajectories for analysis, and sample in layers by failure type, which converges faster than uniform sampling.

    5. Evaluation and Cost Accounting

    Evaluation should report both effectiveness and cost: Pass@1 reflects the single-attempt success rate, and per-task cost needs a clearly defined statistical boundary that includes generation, tool execution, and verification. Only by comparing the “highest reasoning-intensity configuration” and the “standard configuration” under the same accounting basis does a 30x-level cost difference become meaningful. Teams are advised to build a small-scale regression set to continuously track whether capability transfer remains stable.

    6. Conclusion

    The barrier for long-horizon agents is shifting from “having a large amount of compute” to “whether the training recipe is efficient.” With automatically verifiable rewards, strict timeouts and early stopping, asynchronous sampling, and full-parameter training at the core, combined with general-purpose cloud capabilities such as elastic containers, object storage, and monitoring alerts, small and medium-sized teams can likewise obtain terminal and coding agents that approach frontier performance at a controllable cost within tens of accelerators and a few days.