Post-Training Reinforcement Learning: How RL Drives Code and Agent Capabilities in Large Models

    As pretraining returns diminish, the AI industry is shifting focus to post-training reinforcement learning (RL), which is being systematically applied across hundreds of domains to directly build task capability—especially in code generation and long-horizon agent execution. This article covers the infrastructure overhaul required for large-scale RL training, how to evaluate code and agent performance, the evolution of inference serving (including speed-optimized models and context caching pricing), the rise of hosted agent services, and practical guidance for developers to maximize capability while controlling cost.

    1. A New Engine for Capability Leaps: From the Pretraining Race to Post-Training Depth

    Over the past two years, flagship large language model evolution has followed two clear trajectories: parameter counts have crossed the trillion mark and context windows have extended to millions of tokens, while the share of post-training compute in total training investment has risen steadily. As marginal gains from pretraining diminish, competitive focus has shifted decisively to the post-training stage. The most pivotal shift is that reinforcement learning (RL) is no longer just an auxiliary tool for “aligning with human preferences”—it is being systematically extended across hundreds of downstream domains, becoming a core engine for directly forging task capability.

    The underlying logic of this path can be stated simply: any task for which verifiable reward signals can be constructed can be improved continuously through RL. Code is one of the highest-yielding directions because it naturally provides objective, auto-judgable feedback—whether code compiles, passes tests, or completes the task. Financial research, 3D content creation, and long-horizon task execution can similarly define rewards through final environment states, tool-call results, or output verification, all feeding into the training loop. Public industry data shows that next-generation models now approach the strongest closed-source models on real-terminal coding benchmarks, with top-tier gaps narrowing to roughly one percentage point—supporting the effectiveness of “post-training RL plus real-environment feedback.”

    Alongside the push for greater post-training compute comes a paradigm shift: rather than single-domain RL, training now spans massive joint optimization across hundreds of downstream domains. This places entirely new demands on infrastructure—the subject of the next section.

    2. Infrastructure for Large-Scale RL: A Systemic Overhaul

    Scaling RL to hundreds of domains is less an algorithmic challenge than an engineering one. A complete RL iteration involves four stages—sampling, evaluation, reward computation, and parameter update—and a bottleneck in any one stage stalls the entire pipeline. Industry efforts concentrate on six areas:

    1. Asynchronous and decoupled RL training frameworks. Rollout (sampling) and parameter updates are split into independent clusters connected by an asynchronous pipeline, preventing long-tail generation delays from dragging down compute utilization. Dedicated data pipelines handle experience transport, deduplication, and priority sampling.

    2. Long-context inference optimization. Million-token contexts impose quadratic attention costs and enormous KV-cache overhead. Common approaches include prefix-cache reuse, sparse attention, paged memory management, and context parallelism, keeping models from hitting the “memory wall” on ultra-long task trajectories.

    3. Training efficiency engineering. Mixed precision, tensor parallelism, pipeline parallelism, and activation recomputation are combined to push effective throughput per unit of compute to the limit—when jointly training across hundreds of domains, even single-digit percentage efficiency gains translate into substantial cost savings.

    4. Sandbox infrastructure. Code execution, terminal operations, and browser interactions must run in isolated environments that both prevent dangerous generated instructions from damaging host systems and support rapid creation, snapshotting, and destruction to handle massive concurrent sampling. Containerization and micro-VMs are common solutions.

    5. Unified scheduling systems. Thousands of concurrent rollouts, heterogeneous task types, and variable execution times require a scheduling layer that handles resource allocation, preemption, and fault tolerance—essentially embedding a “distributed operating system” inside the training platform.

    6. Environment quality audit platforms. The ceiling of RL is set by reward-signal quality. If task environments are flawed—rewards gameable, test cases leaked, environment states contaminated—the model learns to “game the system” rather than acquire genuine capability. Continuous quality audits, decontamination, and versioned environment management are therefore essential.

    The overarching philosophy is to reframe “training a stronger model” as “operating a factory that continuously produces high-quality training signals.”

    3. Evaluating Code and Long-Horizon Agent Capabilities

    Evaluation is key to understanding where model capabilities actually end. Two categories deserve special attention:

    1. Real-terminal environment benchmarks. These place models in resource-constrained real terminals and require them to perform environment setup, bug fixing, cross-file refactoring, and other complex tasks, each with dedicated verification to prevent “looks-done-but-isn’t” failures. Unlike traditional single-turn code-completion benchmarks, they test the full capability chain of a coding agent: task understanding, step planning, tool invocation, and self-correction based on feedback.

    2. Long-horizon code benchmarks. Covering multiple engineering domains, these emphasize multi-step execution, tool use, and end-to-end problem solving. New-generation models typically show gains of several percentage points on these tasks—a seemingly modest lift, but long-horizon completion is exponentially sensitive to per-step success: raising per-step accuracy from 95% to 97% lifts ten-step overall success from roughly 60% to roughly 74%.

    Three takeaways for developers reading benchmark tables: first, watch for data contamination—if test items leak into training corpora, scores become unreliable; second, note the gap between benchmark sandboxes and real production environments—passing in a sandbox does not guarantee usability in production; third, variance across multiple runs is non-trivial, especially for agent tasks, so important conclusions should be based on averaged results over multiple samples.

    4. Inference Serving Evolution: Speed-Optimized Models, Cache Pricing, and the True Cost of Long-Horizon Tasks

    Post-training capability gains ultimately reach users through inference serving, and serving-side engineering is evolving in parallel.

    1. Speed-optimized models at the same capability level. Providers widely offer versions that maintain the same intelligence while delivering 2–3× faster output, backed by speculative decoding, quantized inference, KV-cache optimization, and batch scheduling. The trade-off is roughly double the per-token price versus the standard tier—trading cost for latency, suited to interactive use; large offline batch jobs still favor the standard version.

    2. Context-cache pricing. Major APIs typically split input pricing into “cache-hit” and “cache-miss” tiers, with hit prices as low as one-tenth of miss prices. This mirrors the actual cost structure: when prefix KV caches can be reused, compute drops sharply. For users, this means prompts should be “cache-friendly”—place stable system prompts, tool definitions, and long documents at the front and variable content at the back to noticeably reduce bills.

    3. Why long-horizon agent tasks “burn through” budgets. This is the shared experience of many developers running agent tasks for the first time: credits vanish in minutes. The root cause is the agent execution pattern: every step re-feeds the full history (system prompt + tool definitions + all prior tool results) into the model. A task running dozens of steps can accumulate hundreds or thousands of times the input tokens of a single-turn conversation; retries and reflection after tool failures amplify consumption further. Without guardrails, exhausting a prepaid balance in ten minutes is not an exaggeration.

    5. Hosted Agents: Infrastructure-as-a-Service for Agent Capabilities

    A notable trend is that model and cloud providers are beginning to offer the “harness” supporting long-running agents as cloud infrastructure directly—hosted agent services that typically include:

    • 24/7 long-horizon task execution environments that do not terminate when a session ends;
    • Sandboxed code-execution and tool-invocation environments;
    • Multi-agent collaboration frameworks allowing tasks to be divided and reunited across roles;
    • Task-state persistence, checkpoint recovery, and audit logging.

    For enterprises without the ability to build their own agent infrastructure, hosted services dramatically lower the barrier to deploying long-horizon agents. For teams needing deep customization, self-built harnesses remain the norm, with core components including task planners, tool gateways, context compressors, and observability alerting. Platforms such as Baidu AI Cloud have integrated large-model serving, agent orchestration, and compute scheduling into a one-stop offering, letting developers choose between hosted and self-built approaches as needed.

    6. Developer Practices: Leverage Capability, Control Cost

    Based on the analysis above, three actionable recommendations:

    1. Choose models with real tasks, not just benchmarks. Build 3–5 end-to-end evaluation tasks close to your own business, fix the datasets and scoring criteria, and compare candidate models side by side—this is more reliable than any public leaderboard.

    2. Design cache-friendly contexts. Put stable content first and dynamic content last; summarize and compress long tool results; reuse session prefixes across multi-turn tasks.

    3. Budget circuit breakers and state persistence. Long-horizon tasks must enforce cost caps and step limits. When triggered, save intermediate state and emit diagnostics rather than letting a loop burn money. Below is illustrative pseudocode:

    1. # Long-horizon agent execution loop with budget circuit breaker (pseudocode)
    2. MAX_COST, MAX_STEPS = 50.0, 200 # Budget and step limits
    3. cost = 0
    4. for step in range(MAX_STEPS):
    5. resp = llm.call(
    6. messages=history,
    7. tools=toolkit,
    8. prefix_cache=True, # Reuse stable prefix to improve cache hit rate
    9. )
    10. cost += resp.usage.cost
    11. if cost > MAX_COST:
    12. save_state(history) # Persist intermediate state for later resumption
    13. raise BudgetExceeded(cost)
    14. if resp.is_finished:
    15. break
    16. history = compact(history, resp) # Compress context to curb token growth

    7. Conclusion

    The essence of this capability leap is a three-part engineering triumph: post-training compute, real-environment feedback, and infrastructure overhaul. Code and long-horizon agents are the two directions with the clearest returns, while speed-optimized inference, context caching, and hosted agent services are translating lab-grade capability into developer-affordable, controllable productivity. For technical teams, the real question is no longer “is the model strong enough?” but “do I understand its cost structure, evaluation scope, and engineering boundaries?”—the deeper that understanding, the more effectively every compute dollar can be put to work.