Single-Trajectory Asynchronous Optimization: A Practical Guide to Long-Horizon Agent Reinforcement Learning
This article explains why long-horizon agent reinforcement learning is difficult and how single-trajectory asynchronous optimization addresses the main bottlenecks. It covers the shift from group-based sampling to single-trajectory sampling, key mechanisms such as dual-sided importance sampling, critic strengthening, and context compression, as well as the scheduling and load-balancing requirements needed to realize throughput gains. Readers will find a practical, reusable engineering path for stabilizing long-horizon agent RL training.
1. Why Long-Horizon Agent RL Is Hard
As AI coding tools and autonomous task execution mature, reinforcement learning (RL) is increasingly used to improve model performance on long-horizon tasks. A long-horizon task requires the model to keep making decisions across dozens or even hundreds of interaction turns: reading a code repository, locating a defect, modifying files, running tests, and continuing to fix issues based on errors. Compared with single-turn question-answering tasks, long-horizon tasks have longer trajectories, larger state spaces, and sparser reward signals, which raises training difficulty by an order of magnitude.
In this setting, engineering teams commonly run into three pain points.
The first is high sampling cost. A complete trajectory may require the model to generate tens of thousands of tokens of context, along with many tool calls and observation data fed back into the context. With group-based sampling, which generates multiple trajectories for the same input to compute within-group relative advantages, sampling overhead grows linearly with group size, while GPU utilization often drops significantly because of long-tail trajectories.
The second is off-policy bias. In an asynchronous training architecture, the sampler and the trainer run decoupled, so the policy version used for sampling often lags behind the current training policy. The longer the trajectory, the larger the accumulated version difference, and the more easily the importance ratio explodes or collapses, destabilizing training.
The third is the difficulty of reward and advantage estimation. In long-horizon tasks, only the end of a trajectory carries a clear success-or-failure signal, and intermediate steps lack dense rewards. If observation data such as test logs and compilation errors is also included in advantage propagation, noise is amplified and the variance of value estimation rises sharply.
Single-trajectory asynchronous optimization is a systematic approach designed for these three pain points. Its core idea is to replace group-based sampling with a single rollout and to redesign bias correction and value modeling around an asynchronous architecture.
2. Core Design: From Group-Based Sampling to Single-Trajectory Sampling
Traditional group-based sampling requires each input task to generate a group of trajectories and then normalize within the group to obtain relative advantages. This approach is mathematically simple, but it is costly in long-horizon agent scenarios: the larger the group, the longer the wait for the slowest trajectory, and the more easily the overall pipeline is held back by the long tail.
The key shift in single-trajectory sampling is that each input task generates only one trajectory, and once that trajectory finishes, it is immediately sent to the training queue. This brings three direct benefits.
- Higher sampling throughput: there is no need to wait for a whole group to finish, so the sampler can keep producing and the trainer can keep consuming, forming true pipeline parallelism.
- Lower off-policy degree: the interval between producing a trajectory and consuming it is shorter, so the version gap between the sampling policy and the training policy is smaller.
- Better generalization: a single trajectory does not rely on within-group relative comparison, avoiding the problem where within-group difficulty differences are flattened by normalization, so the model performs more stably on unseen tasks.
Of course, giving up the within-group baseline means the question of “where advantages come from” must be solved. This requires introducing a value model (critic) to provide per-state value estimates, together with a set of variance-reduction techniques.
The following pseudocode illustrates the training loop logic (it only expresses the scheduling idea):
# Sampler and trainer are decoupled; each single trajectory is queued immediatelyfor step in range(total_steps):task = task_queue.get()traj = rollout(policy, task) # generate only one trajectoryadvantage = compute_advantage(traj, critic) # estimate advantage based on the value modeltrain_batch.put((traj, advantage)) # make it available for training immediatelyif step % 2 == 0:update_critic() # update the value model more frequentlyupdate_policy()
3. Breakdown of Key Mechanisms
3.1 Dual-Sided Importance Sampling
In asynchronous training, the importance sampling ratio is used to correct the distribution difference between the sampling policy and the training policy. One-sided correction can usually suppress bias in only one direction and tends to cause one-sided ratio inflation. Dual-sided importance sampling constrains both the numerator and denominator directions at the same time, keeping the ratio within a controllable range and significantly reducing training oscillation caused by accumulated bias over long trajectories. In practice, this mechanism is usually combined with ratio clipping to prevent individual tokens from dominating the entire gradient.
3.2 Strengthening the Value Model
The single-trajectory approach relies much more heavily on the value model, so its reliability needs to be strengthened systematically. Common practices fall into four directions.
- Increase update frequency: update the value model twice for every policy model update, so value estimates keep up with policy changes faster and advantage estimation variance is reduced.
- Scale up pre-training data: give the value model a more sufficient state-value prior before training starts, reducing noise during cold start.
- Freeze attention module parameters: optimize only the projection layers of the mixture-of-experts layers, reducing the number of trainable parameters and suppressing abrupt fluctuations during value model training.
- Skip token-level advantage computation for observation data: propagate advantage signals only among the action tokens generated by the model, excluding tool-returned observation content from the advantage path to avoid external noise contaminating the gradient.
3.3 Multi-Turn Agent Trajectory Processing and Context Compression
The context of a long-horizon trajectory expands rapidly and can exceed the training window. A context compression mechanism summarizes, trims, and structurally preserves historical interactions so the model can retain key task information within a limited window. Combined with the single-trajectory asynchronous pipeline, compressed trajectories are shorter and more regular, giving both the sampling and training sides stable throughput.
4. A Systems Engineering View: Scheduling and Load Balancing
Gains at the algorithm level can only be realized with support at the systems level. The defining characteristic of long-horizon agent workloads is “extremely large length variance”: a few tasks may run for hundreds of turns, while most finish within dozens. With static sharding, long tasks concentrate on a few nodes and leave resources idle.
Therefore, the routing layer and the training system need joint scheduling: assign tasks dynamically based on estimated trajectory length and spread long tasks across different sampling instances; reclaim completed short trajectories immediately and trigger training; and continuously monitor queue depth and version lag through monitoring and alerting. In engineering practice, these capabilities are typically built on general cloud components such as container platforms, message queues, logging services, and monitoring and alerting, keeping the pipeline from visibly collapsing during thousand-step training.
5. Results and Lessons Learned
In public technical descriptions, single-trajectory asynchronous optimization combined with context compression can deliver several-fold improvement in end-to-end training throughput for long-horizon coding RL and remain stable at thousand-step scale; on math reasoning and code repair benchmarks, it consistently outperforms group-based sampling and its common variants.
For teams that want to adopt a similar approach, four lessons can be drawn:
- First get the pipeline working with single trajectories, then gradually introduce value model strengthening, avoiding too many variables at once.
- Excluding observation data from advantage propagation is a key detail for long-horizon task stability.
- Frequent value model updates and parameter freezing are low-cost means of controlling variance.
- Algorithms and scheduling must be designed together; otherwise throughput gains will be consumed by long-tail workloads.
The value of single-trajectory asynchronous optimization lies not in any single technique, but in redesigning sampling, advantage estimation, context management, and system scheduling as a whole. For teams advancing long-horizon agent capabilities, this approach offers a reusable engineering path.
