Scaling LLM Post-Training and Long-Horizon Agents: Engineering Practices
As LLM capability gains increasingly come from post-training, the main challenge is turning additional compute into reliable improvement. This article covers the engineering bottlenecks of large-scale post-training, including reinforcement learning frameworks, long-context inference, parallelism strategies, sandbox infrastructure, and environment quality checks. It also explains how to evaluate long-horizon agents with independent verification, outlines capability levels for coding tasks, and offers practical deployment recommendations and known limitations.
1. Background: Post-Training Compute Is Becoming the Main Driver of Capability Growth
Over the past two years, the focus of LLM capability improvement has gradually shifted from pre-training scale to the post-training stage. Pre-training establishes the model’s knowledge base. Post-training determines how the model follows instructions and how it makes decisions in multi-step tasks. When post-training compute grows many times over, the real challenge is no longer whether more compute can be invested, but whether the additional compute can reliably translate into capability gains.
In general-purpose settings, reinforcement learning signals often come from tasks in different domains. Programming, office automation, financial analysis, and 3D content generation each have their own data distributions and evaluation standards. If the training pipeline optimizes only for a single domain, capabilities in other domains may degrade. Large-scale joint training therefore needs to address three problems at once: data scheduling, reward design, and quality control.
2. Engineering Bottlenecks in Scaled Post-Training
2.1 Reinforcement Learning Framework
Reinforcement learning training relies on a loop of three stages: sampling, scoring, and parameter updates. Sampling requires a large amount of model inference. Scoring may depend on execution results from a real environment. Updates depend on gradient computation. If the throughput of the three stages does not match, computing devices sit idle while waiting. A common approach is to decouple sampling from training, pass trajectory data through asynchronous queues, and apply dynamic batching to samples of different lengths.
2.2 Long-Context Inference
As context grows longer, sampling costs rise noticeably. A single long-horizon task may involve dozens of tool calls, and each round requires rereading the historical information. Common techniques include key-value cache reuse, prefix sharing, and chunked prefill. These techniques aim to reduce repeated computation so that the sampling cost of long trajectories stays within an acceptable range.
2.3 Training Efficiency and Parallelism Strategies
Data parallelism, tensor parallelism, and pipeline parallelism need to be combined based on the model architecture and sequence length. Longer sequences consume more memory for activations, so they usually require recomputation or sequence parallelism. When choosing a parallelism strategy, base the decision on measured throughput and memory usage rather than on theoretical peak performance alone.
2.4 Sandbox and Environment Infrastructure
During training, agents need to execute code, read and write files, and call external interfaces. Each execution should run in an isolated environment to avoid affecting the host system. A sandbox generally needs resource quotas, timeout control, snapshot rollback, and network allowlists. As the number of environments grows, container orchestration and scheduling systems are also needed to manage the creation and destruction of environments in a unified way.
2.5 Environment Quality Checks
If a training task contains errors, for example when test cases do not match the problem description, the model will learn incorrect behavior. A shared quality check mechanism is therefore needed. It should automatically validate task descriptions, test scripts, and reference solutions, and include periodic manual spot checks.
3. Evaluating Long-Horizon Agent Capabilities
Evaluating a long-horizon agent requires attention to three levels: whether each single tool call is correct, whether the multi-step plan is reasonable, and whether the final result satisfies the constraints. A reliable evaluation system should follow these principles:
- Real environments: Tasks run in terminals or containers that closely resemble production, rather than in a purely text-based simulation.
- Resource limits: Execution time, memory, and the number of commands are capped so that evaluation results reflect practical usability.
- Independent judgment: Each task has its own judging script, and the result is a reproducible pass or fail.
- Stratified reporting: Success rates are reported separately by task difficulty, task domain, and number of steps, so that averages do not hide structural weaknesses.
The following simplified evaluation framework illustrates the judging logic. It does not represent the implementation of any specific product.
from dataclasses import dataclassfrom typing import Callableimport subprocess@dataclassclass TaskResult:task_id: strpassed: boolsteps: intdef run_task(task_id: str, setup_cmd: list[str],agent_step: Callable[[int], bool],verify: Callable[[], bool],max_steps: int = 30, timeout_s: int = 600) -> TaskResult:# Initialize the isolated environment. The command is a fixed list supplied by the caller, so external input is never concatenated.subprocess.run(setup_cmd, check=True, timeout=timeout_s)steps = 0for i in range(max_steps):steps = i + 1if agent_step(i): # The agent takes one step and returns whether it declares the task complete.breakpassed = verify() # Judge the result with an independent script instead of trusting the model's self-report.return TaskResult(task_id, passed, steps)def summarize(results: list[TaskResult]) -> dict:total = len(results)if total == 0:return {"success_rate": 0.0, "avg_steps": 0.0}ok = sum(r.passed for r in results)avg_steps = sum(r.steps for r in results) / totalreturn {"success_rate": ok / total, "avg_steps": avg_steps}
The key point of this code is that verify is independent of the agent’s self-report. A model saying “the task is complete” is not evidence of success. A task counts as passed only when the independent script confirms the result is correct. This reduces bias from the model’s self-assessment and makes results easier to reproduce and audit.
4. Capability Levels for Programming Tasks
Programming capability can be divided into three levels based on task scale.
- Local repair: Locate and fix defects in an existing codebase. The key abilities are understanding the surrounding context, understanding call relationships, and writing minimal changes. The main metrics are the repair rate and whether the change introduces new regression errors.
- Feature development: Add new modules or interfaces based on requirements. The key abilities are breaking down requirements, keeping the code style consistent with the existing code, and adding tests at the same time.
- Building from scratch: Generate a complete project skeleton, including directory structure, dependency declarations, build scripts, and documentation. The key abilities are long-horizon planning and keeping the architecture consistent across multiple rounds of iteration.
In engineering practice, agents should be given explicit acceptance criteria, such as a passing build, passing tests, and passing static checks. A model’s claim that the work is done is not enough to count as a deliverable. When a task requires specialized tools, define the tool list, the input and output formats, and the fallback strategy for failures.
5. Engineering Essentials for Visual and Interactive Content Generation
The visual quality of games and websites usually depends on three factors.
- Design specifications: Define colors, fonts, spacing, and animation durations before asking the model to generate the implementation. The more specific the specification, the more stable the output.
- Asset pipeline: Images, models, and audio files need consistent naming rules and version management. Without them, replacing and rolling back assets becomes difficult.
- Rendering verification: Use screenshot comparison or headless browser rendering to check for layout misalignment, asset loading failures, and performance regressions. Visual judgment is subjective, so verification should be converted into quantifiable metrics wherever possible.
6. Practical Recommendations
- Split work into verifiable subtasks: Each subtask has a clear input, output, and passing condition, which makes it easier to locate the point of failure.
- Limit permissions: Give the agent only the minimum permissions needed to complete the task. Operations such as deleting files, publishing releases, or changing configurations should require manual confirmation.
- Save complete trajectories: Record the command, output, and reasoning basis for each step to support auditing and review.
- Build a regression test set: After changing the model version or modifying prompts, run a fixed task set to compare success rates and execution time. This prevents capability regressions from going unnoticed.
- Estimate the cost per task: Long context and multiple rounds of calls amplify token consumption. Estimate the compute and cost of a single task before launch, then decide the concurrency level.
When deploying such systems on Baidu AI Cloud, teams can use a container platform to host the runtime environments, object storage to keep trajectory data, a log service to centralize audit records, and monitoring with alerts to identify abnormal tasks quickly. These are general categories of cloud infrastructure. The specific configuration should be determined by the actual workload and compliance requirements.
7. Limitations and Considerations
- Evaluation scores cannot fully represent real-world scenarios, because the distribution of evaluation tasks may differ from production.
- Errors in long-horizon tasks accumulate over time. A deviation in an early step can invalidate all subsequent steps.
- Evaluation sets may overlap with training data. Update the tasks regularly and keep a private test set that is not publicly released.
- Visual and experience-based metrics depend on human standards. Design the scoring rules in advance to reduce variation caused by subjective judgment.
