Scaling Post-Training and Engineering Practices for Long-Horizon AI Agents
This article explains how large language model evaluation is shifting from single-turn answer accuracy to multi-step tasks completed in real environments. It covers the role of post-training compute, the infrastructure challenges of reinforcement learning at scale, how to read coding agent evaluation results, the trade-off between speed tiers and cost, and the runtime infrastructure that long-running agents need, with practical recommendations for teams.
1. From Single-Turn Q&A to Long-Horizon Tasks
Large model evaluation has focused mainly on accuracy in single-turn question answering. As applications mature, enterprises care more about whether models can complete multi-step tasks in real environments. Examples include reading a code repository, running tests, modifying files, retrieving materials, and generating a report. Such tasks often require dozens or even hundreds of tool calls, and an error at any step can invalidate the results that follow. The capability goal therefore shifts from “getting the answer right” to “completing tasks consistently, producing verifiable results, and recovering from errors.”
This shift has two direct effects. First, the focus of training extends from pre-training to post-training. Post-training uses instruction tuning, preference optimization, and reinforcement learning to teach models to make decisions within specific task structures. Second, evaluation must move from static question banks to executing tasks in controlled environments, with the final outcome determining whether a task passes.
2. The Basic Logic of Post-Training Compute Scaling
Post-training shapes a general foundation model for target scenarios. As the compute invested in post-training grows, performance on code generation, tool use, and multi-step planning generally keeps improving. However, the gains diminish over time, and results depend heavily on data quality and reward signal design.
From an engineering perspective, this process has three interrelated elements:
- Task coverage: The more domains a training environment covers, the more room the model has to generalize. However, the cost of building data and verifying results for each domain also rises.
- Reward verifiability: Reinforcement learning depends on reward signals that can be judged automatically. Whether code passes unit tests, or whether a spreadsheet calculation matches a reference value, are scenarios well suited to large-scale training. Subjective tasks require an additional scoring model or human annotation, which costs more.
- Training stability: When training across multiple domains at once, reward scales and output length distributions can differ widely. If these differences are not handled well, one domain may overfit, or domains may compete with each other for capacity.
3. Systemic Challenges of Scaling Reinforcement Learning
When reinforcement learning extends to hundreds of downstream domains, the bottleneck usually lies in infrastructure rather than the algorithm. The following four areas are common difficulties.
3.1 Training Framework and Long-Context Inference
Agent trajectories are much longer than ordinary conversations. A complete trajectory may contain large volumes of tool output, intermediate states, and error messages. As a result, GPU memory use and latency during inference become the main limits on training throughput. Common approaches include chunked prefill, KV cache reuse, and asynchronous sampling of long trajectories, so that sampling and parameter updates run in parallel as much as possible.
3.2 Sandboxes and Execution Environments
Each reinforcement learning sample may require executing code or accessing a file system. Execution environments must be isolated from each other and quick to reset. They must also limit CPU, memory, and network usage, so that a single sample cannot overwhelm the cluster. Environment startup speed directly affects sampling efficiency. For this reason, teams often build images in advance and reuse environment snapshots.
3.3 Scheduling
The runtime of a single task can differ by several orders of magnitude across task types. The scheduler needs to support priorities, timeout reclamation, and failure retries. It must also keep the sample ratio for each domain aligned with the training mix. If resources are allocated on a first-come, first-served basis only, long-running tasks can hold slots for extended periods, and short tasks receive feedback too late.
3.4 Environment Quality Checks
Training environments can also contain errors. Examples include incorrect test cases, leaked reference answers, and reward functions with loopholes that the model can exploit. A systematic quality check usually includes random sampling for manual review, adversarial testing of reward functions, monitoring for abnormally high scores on a given environment, and validating that each task is solvable using a reference solution before training.
The following sketch shows how to validate that an environment is solvable:
def validate_environment(env, reference_actions, max_steps=50):"""Validate an environment with a reference action sequence. A full score means the task is solvable. Otherwise, check the environment itself."""env.reset()for step, action in enumerate(reference_actions):if step >= max_steps:return False_, reward, done = env.step(action)if done:return reward == 1.0return False
4. Reading Coding Agent Evaluation Results
The central question in coding agent evaluation is whether a task was completed under real constraints. When reading evaluation results, focus on the following three dimensions.
- Environmental realism: Check whether the terminal, file system, dependency versions, and network restrictions are close to a real production environment. Resource-constrained settings can reveal weaknesses in a model’s budget awareness and resource management.
- Task-specific testing: Each task should have its own acceptance test, rather than a comparison based only on text similarity. Passing the test is the basic standard for completion.
- Result stability: Pay attention to variance across repeated runs of the same task. A single high score does not prove stable capability, especially in scenarios involving random sampling.
Two other common issues also need attention.
The first is uneven performance. A model may perform well on one type of task but drop noticeably on related types. For this reason, evaluation reports should break results down by task type instead of giving a single overall score.
The second is verbosity. Agents sometimes assemble a correct result through many unnecessary operations. This consumes more tokens, time, and compute. When comparing models, record the number of completed steps, tool calls, and total runtime alongside accuracy.
Finally, when comparing scores from two models, confirm that the evaluation version, runtime framework, timeout settings, and sampling parameters are identical. Otherwise, the score gap may come from experimental conditions rather than model capability.
5. Trade-offs Between Speed and Cost
Inference services commonly offer a standard tier and a high-speed tier. The two tiers typically trade output speed against unit price. The following considerations can guide the choice.
- Interactive scenarios, such as developers editing code in real time, are sensitive to time to first token and output speed. These scenarios suit the high-speed tier.
- Offline batch scenarios, such as overnight long-horizon jobs, are not sensitive to latency. The standard tier is usually more economical for these.
- Cache hit rate significantly affects input cost. When system prompts, tool definitions, and similar content repeat across requests, caching can substantially reduce costs. Keeping the prompt prefix stable is therefore a common way to lower costs.
The example below shows how to calculate blended input cost. The unit prices are illustrative values and do not reflect any specific service’s pricing.
def blended_input_cost(price_hit, price_miss, hit_rate, tokens_m):"""Calculate blended input cost. tokens_m is the number of input tokens, in millions."""return tokens_m * (hit_rate * price_hit + (1 - hit_rate) * price_miss)# Assume the cache-hit unit price is one-tenth of the cache-miss unit price, the hit rate is 70%, and the input volume is 2 million tokensprint(blended_input_cost(price_hit=0.1, price_miss=1.0, hit_rate=0.7, tokens_m=2)) # Output: 0.74
6. Runtime Infrastructure for Long-Running Agents
Keeping a long-running agent stable requires more than a good model. It also needs a runtime framework, sometimes called a harness. Common components include the following.
- State persistence: Task progress, intermediate outputs, and context summaries must be written to durable storage. After a process restart, the task can resume from its last checkpoint.
- Budget and timeout controls: Set a maximum number of steps, a time limit, and a cost ceiling for each task. When a limit is exceeded, terminate the task and record the reason.
- Permission isolation: The agent can access only the resources it is authorized to use. Write, delete, and publish operations should be recorded in audit logs, and they should require human confirmation at critical points.
- Observability: Record the input, output, and errors of every tool call, so that teams can trace behavior and diagnose problems afterward.
- Multi-agent collaboration: A coordinator splits the task, multiple executors process the parts in parallel, and a verification step aggregates the results. The interfaces between the coordinator and the executors should stay clear and simple.
These capabilities are typically built on a combination of general cloud infrastructure, such as object storage, message queues, logging services, and monitoring and alerting.
7. Practical Recommendations
- Define acceptance criteria for the task before choosing a model and deployment approach.
- Build a small evaluation set from your team’s real tasks, and report results broken down by task type.
- Record accuracy, step count, runtime, and cost together during evaluation. Avoid relying on a single metric.
- Set hard limits for agents, and require human confirmation before high-risk operations such as deletion, publishing, or payments.
- Include environment validation in your workflow. Check regularly for errors in the evaluation tasks themselves to prevent distorted results.
