Back to blog

Train AI Agents on 2M Tokens for Free

Based on research by Changhai Zhou, Kieran Liu, Yuhua Zhou, Qian Qiao, Jun Gao

AI agents are drowning in data. As these systems accumulate observations, tool outputs, and prior decisions over long trajectories, the context windows required for inference are rapidly approaching million-token lengths. Yet, the training methods used to refine these models have stubbornly remained stuck at 256K tokens or below, relying on the risky assumption that models can generalize to longer contexts they were never actually trained on. This gap between what agents experience and how they are taught is a critical bottleneck for building reliable, long-horizon AI.

Researchers have introduced LongStraw, an execution stack designed to bridge this divide by enabling reinforcement learning post-training on contexts exceeding two million tokens, all while operating under a fixed GPU budget. The system works by evaluating the shared prompt without requiring automatic differentiation, retaining only the specific model state needed for subsequent tokens. It then replays short response branches individually, effectively shrinking the live training graph to save memory at the cost of additional replay time. This approach allows for efficient training on massive inputs without requiring exponential increases in hardware resources.

The results are striking. On just eight H20 GPUs, the system successfully processed grouped scoring and backward passes for Qwen3.6-27B at 2.1 million positions, with memory usage increasing by a mere 0.21 GB when scaling group sizes. A stress test pushed this further to 4.46 million positions. On a larger cluster of 32 H20 GPUs, the team validated the full execution path for a 2.1 million-token prompt across all 78 layers of the GLM-5.2 model. While the current implementation focuses on establishing execution capacity rather than complete training correctness, it proves that long-context reinforcement learning is no longer a theoretical impossibility.

This development marks a pivotal shift in how we train AI for complex, real-world tasks. By decoupling the memory demands of long-context training from the sheer scale of the input, LongStraw makes it feasible to teach models the nuances of extended reasoning and tool use. As the industry moves toward agents that operate over hours or days of interaction, this ability to train on million-token contexts under practical hardware constraints will be essential for closing the gap between inference capabilities and post-training rigor.

Source: arXiv:2607.14952

This post was generated by staik AI based on the academic publication above.