Single-Trajectory Asynchronous Optimization: A Practical Guide to Long-Horizon Agentic RL

    This article explains why long-horizon agent reinforcement learning is hard, then walks through a single-trajectory asynchronous optimization framework that replaces group-based sampling with one rollout per task. It covers Direct Dual-Sided Importance Sampling (DIS), value model reinforcement with four variance-reduction measures, multi-turn trajectory structuring, and the asynchronous pipeline and load-balancing design needed to realize the gains, ending with reported outcomes and a four-step adoption path.

    1. Where the Problem Starts: Why Long-Horizon Agentic RL Is Hard

    When reinforcement learning is applied to agent tasks, engineering teams typically hit three walls: high sampling cost, large off-policy bias, and unstable training. Conventional group-based sampling (such as GRPO-style methods) requires generating multiple trajectories for the same input task and uses within-group relative advantage in place of a value network. This is cost-effective for short-output tasks like math problems, but once the task becomes a long-horizon flow of “read the codebase, locate the defect, modify multiple files, run tests, roll back and retry,” the token count, number of tool calls, and wall-clock time of a single trajectory all balloon, and the cost of group-based sampling deteriorates almost linearly.

    The second problem is asynchrony. To overlap generation (rollout) with training, the cluster is necessarily asynchronous: the inference side uses weights from several steps earlier, and the training side consumes “stale” data. This is the source of off-policy behavior. Group-based sampling also requires a group of trajectories to be ready at roughly the same time, so the slowest one holds up the entire group, creating a long tail.

    The third problem is long-horizon credit assignment. Observation information (tool returns, logs, error stacks) takes up a large number of tokens, but it is not the model’s action, and propagating advantage signals over these positions only introduces noise.

    The core trade-off of single-trajectory asynchronous optimization is this: sample only one trajectory per input task, enqueue it for training as soon as sampling completes, and obtain stability and throughput through mechanism design rather than by “throwing more hardware at it.”

    2. Method Overview: Replacing Group Sampling with a Single Rollout

    The first step of single-trajectory asynchronous optimization is to reduce “a group” to “one.” This brings three direct benefits:

    • Sampling cost drops by an order of magnitude, and the problem of end-to-end time for long-horizon tasks being determined by the slowest trajectory is eliminated;
    • Data freshness improves; a single trajectory is sent for training as soon as it is ready, the version gap between the policy and the sampling policy shrinks, and the degree of off-policyness is naturally lighter;
    • Generalization relies more on absolute value judgments than on within-group comparison, avoiding the “empty gradient” phenomenon where advantage degenerates to zero when a group is all correct or all wrong.

    The cost is the loss of the within-group baseline, so variance rises. Therefore, the rest of the framework is essentially doing one thing: pushing the variance back down.

    3. Breakdown of Key Mechanisms

    3.1 Direct Dual-Sided Importance Sampling (DIS)

    The importance sampling ratio $\rho=\pi\theta(a|s)/\pi{old}(a|s)$ is a standard tool for correcting bias in asynchronous training, but single-sided correction only handles the direction of “new policy relative to old policy,” while the shift in the sampling distribution itself remains. The dual-sided approach corrects both the target policy side and the sampling (behavior) policy side, and clips the ratio, as illustrated below:

    1. def dis_objective(logp_new, logp_old, logp_behav, adv, eps_low=0.8, eps_high=1.2):
    2. # Dual-sided ratios: correct the target and sampling sides separately
    3. ratio_new = (logp_new - logp_old).exp()
    4. ratio_beh = (logp_old - logp_behav).exp()
    5. ratio = (ratio_new * ratio_beh).clamp(eps_low, eps_high)
    6. return -(ratio * adv).mean()

    The engineering key points are: the log-prob of the behavior policy must be persisted at sampling time and cannot be recomputed afterward; the clipping thresholds must be tuned in tandem with the asynchronous depth (the maximum allowed version gap).

    3.2 Value Model Reinforcement

    Reintroduce a value network to provide a baseline, together with four variance-reduction measures:

    1. Increase the value model’s update frequency, updating the value twice for every policy update, so the baseline can always “keep up” with the current policy;
    2. Freeze the attention module parameters and optimize only the projection layers of the mixture-of-experts (MoE), greatly reducing the number of trainable parameters and training volatility;
    3. Expand the scale of pretraining data for the value model to improve value estimation bias during cold start;
    4. Skip token-level GAE on observation information and propagate advantage only between the action tokens the model actually generates, avoiding tool-output noise contaminating credit assignment.

    3.3 Multi-Turn Agent Trajectory Handling

    Long-horizon trajectories require explicit structural segmentation: split a trajectory into a sequence of (state, action, observation) triples, where action segments participate in the policy gradient and observation segments serve only as context; keep failure and rollback segments but down-weight them; introduce a compression mechanism for overly long contexts that trims history while preserving key conclusions (files already read, hypotheses already verified), decoupling the controllable context length from the task length.

    4. Systems Engineering: Asynchronous Pipeline and Load Balancing

    For the algorithm to realize its benefits, scheduling must keep up. The recommended minimum viable architecture:

    • Physically separate the inference pool from the training pool, connecting them via a message queue, with each sample in the queue carrying a policy version number;
    • Set a maximum version gap $K$; discard or down-weight over-age samples, using $K$ as the knob for throughput versus bias;
    • Apply length bucketing and priority scheduling to long-tail tasks to avoid short tasks being starved by long ones;
    • Use a unified routing layer for joint scheduling, placing tool calls (compilation, testing, retrieval) and model generation under the same resource view for load balancing;
    • Full-pipeline observability: build monitoring and alerts separately for sampling throughput, queue depth, version-gap distribution, advantage variance, and value loss.
    1. async_pipeline:
    2. max_version_lag: 4
    3. buckets: [2k, 8k, 32k, 128k]
    4. router:
    5. policy: joint_schedule # unified scheduling of generation and tool calls
    6. load_balance: least_pending
    7. observability: [throughput, queue_depth, version_lag, adv_variance, value_loss]

    5. Results and Adoption Recommendations

    The general publicly reported conclusion is that single-trajectory asynchronous optimization combined with context compression can train stably for on the order of a thousand steps, continuously outperforming group-based sampling and its variants on coding and math reasoning benchmarks, and can achieve a several-fold improvement in end-to-end training throughput for long-horizon coding RL (industry reports commonly cite a magnitude of more than 2x). It should be emphasized that specific numbers vary significantly with the base model, task distribution, and cluster size, so A/B testing against your own baseline is the right approach.

    A four-step adoption path is recommended: first reproduce a group-based sampling baseline on short-output tasks; then switch to single-trajectory sampling and add only DIS, observing changes in variance and throughput; next integrate the value model along with the update frequency and freezing strategy; finally enable context compression and joint scheduling. If an enterprise lacks the conditions to build its own cluster, it can build the above pipeline on top of general-purpose capabilities such as Baidu AI Cloud’s container platform, object storage, message queue, and monitoring and alerting, leaving resource elasticity and observability to the platform layer while focusing its own efforts on the algorithm and data loop.