Single-Trajectory Asynchronous Optimization for Long-Horizon Agent Reinforcement Learning
Long-horizon agent reinforcement learning is difficult not only because a model must reason, but because it must continue making correct actions across many interaction turns. Longer trajectories increase sampling cost and widen the gap between generated data and the current policy, making off-policy bias in asynchronous training more pronounced. This article presents single-trajectory asynchronous optimization: each input task produces one trainable trajectory that enters the training queue immediately, replacing group-based sampling and its synchronization overhead. It covers the training pipeline, direct bilateral importance sampling, action-level advantage propagation, value-model updates, context compression, and queue-aware scheduling, with engineering guidance for evaluation and stable deployment.
1. Background: Why Long-Horizon Agent Reinforcement Learning Is Hard to Train
The core challenge of long-horizon agent reinforcement learning is not only whether the model can reason, but whether it can keep making correct actions across multi-turn interactions. During a single task, an agent may go through tool calls, environment observations, error recovery, context accumulation, and other stages, which significantly increases trajectory length. The longer the trajectory, the higher the sampling cost, and the larger the time gap between training data and the current policy. As a result, off-policy bias in asynchronous training becomes more obvious.
If group-based sampling is still used, meaning that multiple trajectories are generated for the same input task and then compared together, it can provide a relatively stable intra-group baseline. However, the waiting cost is high, sample freshness is poor, and long-horizon tasks are more likely to suffer from training a new policy on data from an old policy.
Another pain point of group-based sampling is system coupling. The sampling side must collect a full group of trajectories before sending them to training, while the training side must wait for batch assembly. This creates bubbles in the pipeline between sampling and training. In long-horizon tasks, different trajectories finish at very different times, and group waiting amplifies tail latency. The starting point of single-trajectory asynchronous optimization is decoupling: each input task generates only one trajectory that can be used for training immediately. Once completed, it enters the queue, and the training side consumes it asynchronously. This shortens the path from data generation to training and reduces the strong synchronization dependency among multiple trajectories for the same task.
2. Core Idea: Replacing Group Sampling with Single-Trajectory Sampling
The key to single-trajectory asynchronous optimization is not simply sampling less, but changing how samples are organized. Each input task generates one trajectory and immediately enters the training pipeline, bringing training data closer to the current policy distribution and reducing off-policy impact. Because it no longer relies on comparing multiple trajectories within the same task group, advantage estimation must rely more on the value model, action-level credit assignment, and importance correction. This design is friendlier to generalization: the model does not overfit to multiple similar trajectories from the same task, but continuously updates on a broader task stream.
It is important to note that a single trajectory does not mean low quality. From an engineering perspective, each trajectory should be trainable: action boundaries are clear, observation information can be compressed, failures and truncations can be marked, and advantage signals can be propagated back. The asynchronous queue should carry policy version numbers and behavior policy identifiers so that importance sampling correction can be performed later. The training side can use dynamic batching to aggregate trajectories with similar completion times and reduce waiting. For long-horizon tasks, maximum turns, timeouts, and early stopping strategies can also be set to prevent abnormal trajectories from dragging down the pipeline.
3. Training Pipeline Pseudocode and Key Stages
The following simplified pseudocode shows the basic loop of single-trajectory asynchronous optimization. The code only expresses the flow and is not tied to specific interfaces.
def train_loop(task_stream, policy, value_model, sampler, trainer):for task in task_stream:trajectory = sampler.rollout(policy, task, max_turns=N)compressed = compress_context(trajectory)batch = build_single_rollout_batch(compressed)# Propagate advantage only between model-generated actions, skipping token-level GAE for observation tokensadvantage = compute_action_level_advantage(batch, value_model)# Asynchronous correction: compute bilateral importance weights using the behavior policy and current policyweight = direct_bilateral_importance(batch, policy, batch.behavior_policy)weight = clip_bilateral(weight, lower, upper)policy_loss = compute_policy_loss(batch, advantage, weight)value_loss = compute_value_loss(batch, value_model)update(policy, policy_loss)update(value_model, value_loss)update(value_model, value_loss) # Update the policy once and the value model twiceif step % sync_interval == 0:sync_weights(sampler, policy)
This flow contains four key points. First, a trajectory enters the queue as soon as it is complete, and the training side consumes it asynchronously. Second, context compression is completed before enqueueing, reducing long-context transmission and GPU memory pressure. Third, advantage signals act only on action segments, avoiding noise in observation information interfering with credit assignment. Fourth, importance weights are clipped bilaterally to balance bias and variance. In a real system, queue watermark monitoring, backpressure, failure retries, policy version validation, and training-sample deduplication should also be added.
4. Key Technique 1: Direct Bilateral Importance Sampling
In asynchronous training, trajectories are generated by a slightly older behavior policy, while the training target is the current policy. Without correction, gradients will be biased toward the state-action distribution visited by the old policy. Direct bilateral importance sampling considers the probability ratio between the behavior policy and the current policy at the same time and applies bilateral constraints to sample weights: the upper bound controls the variance of high-weight samples, while the lower bound prevents low-weight samples from being discarded completely. In engineering practice, monitor the effective sample ratio, mean weight, and clipping ratio. If the clipping ratio remains too high, policy drift is too fast, and the synchronization interval should be shortened or the learning rate reduced.
The implementation of bilateral importance sampling must pay attention to numerical stability. Probability ratios should be computed in log space, clipped, and then exponentiated. Extreme values should have fallbacks. Multi-turn trajectories should be weighted at the action level rather than the whole-trajectory level to avoid weight explosion on long trajectories. This mechanism cannot eliminate all bias, but it can keep the off-policy impact in asynchronous training within an acceptable range and provide a foundation for high-frequency updates with single trajectories.
5. Key Technique 2: Value Model Reinforcement and Action-Level Credit Assignment
Single-trajectory sampling lacks an intra-group baseline, which increases the importance of the value model. To reduce training variance, an asymmetric frequency of updating the policy once and the value model twice can be used, allowing the value model to track policy changes faster. At the same time, the value model itself may fluctuate, so attention-related parameters can be frozen and only expert projection layers optimized, reducing update degrees of freedom and training jitter. This approach is suitable for mixture-of-experts (MoE) structures: the projection layers carry value function adaptation, while frozen parameters preserve representation stability.
For advantage propagation, token-level GAE for observation information is skipped, and advantage signals are propagated only between model-generated actions. The reason is that observations are returned by the environment or tools, not model actions, and token-level credit assignment on them easily introduces noise. Action-level propagation better matches the semantics of agent decisions: a tool call, a code edit, or a query action is the decision unit that can be optimized. During implementation, action boundary markers should be explicit, truncated and failed actions should be handled, and discounted accumulation should be performed over multi-turn trajectories.
6. Key Technique 3: Multi-Turn Trajectory Processing and Context Compression
Multi-turn agent trajectories consist of alternating actions and observations. The training side needs to retain action segments, observation summaries, turn boundaries, tool return status, and termination reasons. The goal of context compression is not simple truncation, but preserving information valuable for credit assignment: action intent, key observations, error signals, success signals, and turn relationships. After compression, action boundaries must not be lost; otherwise, advantage propagation will be misaligned. For very long trajectories, segmented compression, summary replacement, key-turn retention, and sliding windows can be combined.
Compression also affects system throughput. Long contexts consume resources in sampling, transmission, and training. Moving compression earlier, immediately after sampling is complete, can reduce queue storage and batch-processing pressure; the training side can then expand key segments as needed. In engineering practice, monitor compression loss rate, action-boundary integrity rate, and training loss anomalies to avoid signal distortion caused by over-compression.
7. System Scheduling and Load Balancing
The benefits of single-trajectory asynchronous optimization depend on system coordination. The sampling side and training side should be decoupled through a bounded queue. When the queue watermark is too high, backpressure is triggered; when it is too low, sampling concurrency is increased. The routing component and the training system need joint scheduling: allocate sampling resources according to task type, trajectory length, model load, and queue state to avoid long-trajectory tasks blocking the system in a concentrated way. Batching should use dynamic batch sizes and length bucketing to reduce padding waste. For fault recovery, trajectories should carry task identifiers and version numbers, and failures can be retried without duplicate consumption.
In long-horizon code reinforcement learning tasks, end-to-end throughput can achieve more than a 2x improvement, but this depends on compression, scheduling, and asynchronous correction working together. If only single-trajectory sampling is implemented while queue governance is ignored, trainer starvation or policy drift may occur. In practice, throughput, tail latency, effective sample rate, importance-weight clipping rate, and value loss should be observed together.
8. Evaluation and Engineering Considerations
Evaluation should insist on fair comparison with the same base model, same data, and same budget. Single-trajectory asynchronous optimization can outperform group-based sampling and its variants on public benchmarks for mathematical reasoning and code repair, and can train stably at the thousand-step scale; however, specific gains depend on task distribution, compression strategy, and scheduling quality. Do not focus only on single-point accuracy; also pay attention to training stability, generalization ability, long-horizon task completion rate, and system throughput.
Engineering recommendations include: set the policy synchronization interval and importance clipping threshold; run ablations on value model update frequency; retain boundary validation for action-level advantage propagation; establish compression fidelity monitoring; set queue watermark alerts; and isolate abnormal trajectories. Only by refining algorithm correction and system scheduling together can single-trajectory asynchronous optimization stably deliver value in long-horizon agent reinforcement learning.
