Single-Trajectory Asynchronous Optimization: A Practical Guide for Long-Horizon Agentic RL
This article explains why long-horizon agentic reinforcement learning is hard to train and how single-trajectory asynchronous optimization addresses the problem. It covers the limits of group-based sampling, the core idea of generating one immediately trainable rollout per task, and four key mechanisms: dual-sided importance sampling (DIS), value model reinforcement, stability constraints that freeze attention and optimize only expert projection layers, and GAE advantage propagation that skips observation tokens. It also outlines system-side scheduling, load balancing, and throughput considerations, followed by practical deployment recommendations.
1. The Starting Problem: Why Long-Horizon Agentic RL Stalls
As reinforcement learning moves from single-turn question answering to long-horizon agentic tasks—multi-turn tool calls, repository-level code changes, and long chains of mathematical and logical reasoning—the pressure on the training side no longer comes from model size. It comes from trajectory length and sampling structure. A single complete agent trajectory may contain dozens of tool calls and observation回填 steps, and the total token count easily crosses the six-figure mark. At this point, the mainstream group-based sampling strategy—generating multiple trajectories in parallel for the same input and then estimating gradients with within-group relative advantage—runs into three simultaneous squeezes:
- Linearly amplified sampling cost: group size multiplied by trajectory length directly determines the compute and memory footprint of the rollout stage.
- Sample staleness: a group cannot start training until every sample is fully generated, so the slowest trajectory dictates the “freshness” of the entire batch.
- Coupled variance and bias in advantage estimation: the within-group baseline depends on other samples in the same group, and estimation quality degrades quickly once the group is incomplete.
The core judgment behind single-trajectory asynchronous optimization is this: instead of spending the budget on multiple parallel trajectories for the same task, let each task produce only one trajectory and let it enter the training queue the moment it finishes. This both compresses sampling overhead and eliminates the structural waste of “waiting for the slowest sample.”
2. Method Core: Replacing Group Sampling with Single-Rollout Sampling
Single-trajectory asynchronous optimization can be defined as: each input task generates only one rollout that is immediately usable for training, with an asynchronous pipeline replacing the synchronous group-sampling barrier. The benefits are bidirectional.
- System side: rollout and training are decoupled; the generation side keeps supplying and the training side keeps consuming, so long-tail tasks no longer block the whole batch.
- Algorithm side: the latency from data generation to consumption drops significantly, the degree of off-policyness decreases, and generalization becomes more stable.
The cost is equally clear: the within-group baseline is gone, so advantage estimation must find another anchor. This requires introducing an explicit value model and keeping the distribution shift caused by asynchrony within a controllable range.
3. Four Key Mechanisms and Their Design Motivation
3.1 Dual-Sided Importance Sampling (DIS)
Under an asynchronous architecture, a version gap exists between the sampling policy and the current policy. One-sided correction typically handles only the “numerator” or the “denominator,” and residual bias still accumulates. Dual-sided importance sampling corrects both the sampling side and the target side at the same time, and pairs this with clipping for numerical safety to avoid weight explosion. Illustration:
# Pseudocode: dual-sided importance sampling weights (with clipping)ratio_sample = current_logp - sampler_logp # target policy / sampling policyratio_target = current_logp - target_logp # target policy / reference policyw = torch.exp(ratio_sample) * torch.exp(-ratio_target)w = w.clamp(min=1e-3, max=1e3) # prevent uncontrolled weight varianceloss = -(w * advantage * current_logp).mean()
In practice, it is advisable to log the quantiles of the weight distribution and the clipping trigger rate as core indicators of asynchronous health.
3.2 Value Model Reinforcement
Single-trajectory mode loses within-group comparison, so the value function becomes the only variance suppressor. Common practices include: increasing the value model update frequency (the value model updates twice for every policy update) so the baseline keeps up with policy drift faster; and expanding the value model’s pretraining data scale to improve value quality during cold start.
3.3 Stability Constraint: Freeze Attention, Optimize Only Expert Projection Layers
Value model training is extremely sensitive to hyperparameters. One validated stabilization technique is to fix the attention module parameters and optimize only the projection layers in the mixture-of-experts structure. After the number of trainable parameters drops by an order of magnitude, training fluctuation converges noticeably, and optimizer state memory usage is also reduced.
3.4 Advantage Propagation for Multi-Turn Trajectories: GAE That Skips Observation Tokens
In agent trajectories, the observation content returned by tools is not a decision generated by the model, so computing token-level advantage over it injects a large amount of meaningless signal. The approach is to propagate advantage only between the action segments generated by the model, skipping observation segments entirely:
# Build action mask: 1 = model-generated, 0 = environment-filledaction_mask = build_action_mask(trace)adv = compute_gae(rewards, values, action_mask) # recurse only over action tokens
Combined with a context compression mechanism, overly long histories are folded into a manageable summary representation, so trajectories on the order of a hundred thousand tokens can still enter the end-to-end training loop.
4. System Side: Scheduling, Load Balancing, and Throughput
Algorithmic gains must be carried by the system. In an asynchronous pipeline, the joint scheduling of the generation side and the training side determines actual throughput: the routing layer needs to estimate latency by task length and tool type and perform dynamic sharding to avoid long-tail tasks piling up on the same worker node; the training side improves effective compute utilization with dynamic batch assembly (batching by token budget rather than sample count). Publicly reported practice shows that on long-horizon code-oriented RL tasks, co-optimizing the algorithm and scheduling can deliver several-fold end-to-end throughput gains. This magnitude typically comes from three effects stacking: reduced sampling redundancy, elimination of waiting bubbles, and higher batch assembly efficiency.
For infrastructure selection, the common approach is to put trajectory caching and weight synchronization on a high-throughput message channel, archive checkpoints and long-cycle samples to object storage, and run the elastic generation cluster on a container platform, with logging services and monitoring/alerting to observe key curves such as rollout latency, weight version gap, and clipping rate. In such training and inference scenarios, Baidu AI Cloud is typically also implemented by combining the general capability categories above.
5. Results and Deployment Recommendations
Public comparative data shows that single-trajectory asynchronous optimization consistently outperforms group-based sampling and its common variants on mathematical reasoning and agentic coding benchmarks, and can train stably for thousands of steps without obvious collapse. For deployment, follow four recommendations: first validate the weight clipping threshold on small-scale tasks; treat the value model update ratio as a tunable knob; write unit tests for the observation token mask; and use “data freshness” rather than “sample count” as the primary metric for pipeline capacity planning.
