Long-Horizon Agent RL: Training Efficiency and Task Cost
Long-horizon coding agents succeed or fail on sequences of decisions, not single-shot generation. This article explains what those agents must do, how to read limited-resource RL results, why training is expensive, and how to design throughput, rewards, data, evaluation, and a cost–performance frontier without overstating one benchmark.
Long-horizon agents are not just “better code generators”
Typical code generation is one input and one output: a user describes a need, the model returns code, and a person runs and fixes it. A long-horizon agent must own more of the workflow: understand the task, inspect the environment, locate issues, edit files, run verification, explain failures, and continue from new evidence.
The hard part is not whether a single reply is fluent, but whether a chain of decisions converges on a correct result. A programming task may span modules, dependency setup, and the runtime. Even if early steps are right, the agent can still fail by misreading logs, skipping regression tests, or repeating useless actions.
Capability therefore has at least three layers:
- Local operations: each file edit, tool call, and interpretation of results.
- Global progress: holding the goal, managing intermediate state, and changing path from feedback.
- Stopping: when to keep exploring, submit, or admit information is insufficient.
Reinforcement learning can use full-task feedback to improve these sequential choices. Longer tasks make training more sensitive to cost, scheduling, and reward quality.
How to read “high performance on limited resources”
The source material describes a long-horizon agent RL experiment: full-parameter RL from a large existing model, reported as 64 high-end accelerators and under five days of training. On a terminal-task benchmark, single-attempt success reached 46.2%, with more than a 30× difference in per-task cost versus a high-inference-budget setup.
Those numbers matter, but they do not mean every team can reproduce the same outcome at the same spend.
Training time is not total project cost. Data prep, environments, reward checks, trial filtering, and evaluation debugging often happen before the reported RL run. Pretraining of the base model is also outside that window.
Accelerator count is not a full compute description. Memory, interconnect, precision, architecture, sequence length, and inference throughput all change efficiency. Card count and days do not yield another lab’s budget.
Cost gaps depend on accounting. Per-task cost used public list prices, not self-hosted total cost of ownership. Inference budget, output length, and tool-call policy also change the comparison.
Evaluation harnesses can move scores. If the base model’s numbers come from a public report and the trained model is scored in-house, prompts, task versions, environments, timeouts, and success criteria must match.
For practitioners, the useful question is not reciting one score: under a fixed resource constraint, can training and system design make the agent complete more tasks with fewer wasted actions?
Why long-horizon RL gets expensive
A training trajectory may include many model inferences, tool runs, and environment signals. Cost can be written as:
Trajectory cost = model inference + tool execution + environment occupancy + result verification.
Inference produces actions; tools cover files, programs, and tests; occupancy is isolated instances, storage, and compute; verification checks true completion.
Expense shows up in several ways.
Delayed feedback. Short tasks can be judged quickly. Long tasks may yield a reliable outcome only after final tests. Many earlier steps can look reasonable without credit assignment.
Highly variable trajectory length. Some tasks finish fast; others stall on dependencies, environment debugging, or repeated edits. Waiting for the slowest trajectory wastes capacity.
Mixed failure modes. Failures may come from the policy, environment faults, broken verifiers, or resource limits. Treating all of them as negative reward teaches noise and can suppress useful exploration.
Growing state. Logs, file snippets, and history fill context. Unfiltered context raises inference cost and hides the evidence that matters.
Lowering cost is not only faster hardware. Trajectory organization, environment management, and feedback design matter.
Design the training system around effective trajectory throughput
A practical metric is how many complete, learnable trajectories finish per unit time—not GPU utilization alone.
The pipeline splits into task dispatch, model sampling, tool execution, verification, and parameter updates. Inference needs accelerators; tools may need CPUs, storage, or external services. Decoupling reduces wait; whether to go asynchronous depends on the RL algorithm and implementation cost.
Four engineering priorities:
- Task queues and resource caps. Each task needs time, output-length, and tool-call budgets so a few runaway traces cannot monopolize the cluster. Budgets should match difficulty; do not truncate healthy tasks just to save money.
- Sampler version control. With async sampling, traces may come from older weights. Record the policy version and keep stale data out of update batches, in a way that fits the algorithm.
- Isolated environments. Parallel tasks must not share mutable workdirs or sensitive credentials. Cross-task file changes corrupt reward.
- Recoverable state. Long jobs need logs and checkpoints. Restore is not always a full rerun; for process state, randomness, or external deps, check that restore does not change evaluation conditions.
Rewards: verifiable first, fine-grained second
Rewards define what is optimized. For coding agents, pass/fail on verification is natural, but outcome-only signal can be sparse.
Separate outcome and process signals.
Outcome: target tests pass, existing behavior holds, required artifacts exist. Process: futile repeated calls, constraint violations, wasted resources.
Do not conflate them. Few tool calls are not always a good policy; some tasks need exploration. Few file edits are not always a correct fix; cross-module bugs may need many sites.
A conservative pattern: keep verifiable task success as the core, add resource and violation penalties carefully, and audit samples so the extras do not induce bad behavior.
Guard against reward hacking: deleting tests, weakening asserts, or editing the verifier. Keep critical checks outside the agent’s writable surface, and compare the submission with independent tests when needed.
Training data is tasks plus environment contracts
A task is trainable only if execution is stable and success is repeatable.
A complete record should include: description, initial environment, allowed actions, termination, verification, and failure taxonomy. Without that, even a “realistic” task may not yield a reliable signal.
Data prep:
- Separate train and eval. Leakage is not only identical text; watch duplicate problems, similar code structure, and near-identical fix paths.
- Cover difficulty and failure types. Easy short tasks teach local patches, not multi-stage dependency work.
- Keep failure traces. They show whether the miss is understanding, planning, execution, or verification.
- Label environment faults. Missing resources, install failures, or broken harnesses should not be treated as model skill.
Evaluation should answer both “how often it works” and “what it costs”
Single-attempt success is the share of tasks completed once, under a stated task set, budget, and verifier. It is not production delivery rate, and it cannot be compared without timeouts, prompts, and tool permissions.
Unify task version, initial environment, prompt template, inference budget, tool rights, timeouts, and scoring. If you repeat trials, report aggregation and variance, not only the best run.
Cost should be split:
- Average cost per attempt: one full run.
- Average cost per successful task: economic efficiency of usable outcomes.
- Time to completion: whether wait times fit the business.
- Human takeover rate: how closed the automation loop is.
Within the same accounting window, average cost per success is total execution cost divided by successful tasks. Production budgets should add retries, human review, ops, and idle capacity.
Cheap but frequently failing systems can cost more than a higher per-run, more reliable one.
Choose on a performance–cost frontier, not a single champion
Performance and cost trade off. Larger inference budgets may raise success or only add redundant thinking and dead actions. One goal of RL is to use budget better, not to run forever.
A configuration dominates another if it is cheaper at no worse success, or more successful at no higher cost. Undominated points form the frontier.
Measure several configs on success, average cost, and latency, then pick from business needs: bulk low-risk work may favor throughput and cost; critical changes may favor reliability, full verification, and human review.
That is closer to enterprise choice than a leaderboard rank, and it shows whether RL gains are skill or just a bigger execution budget.
From small validation to production
Do not start with large-scale weight updates. First close a repeatable eval loop.
- Classify errors of the baseline: understanding, planning, tools, or verification.
- Harden isolation, logging, and success criteria so the signal is trustworthy.
- Validate sampling, reward, and updates on a limited task set and budget; require gains beyond noise.
- Score training gains together with inference cost, and test transfer to held-out tasks.
- In production, use graded permissions, confirmation of sensitive actions, and human takeover while expanding automation.
Long-horizon economics are not one model size, training duration, or benchmark score. Durable advantage is reliable verification, fewer wasted actions, higher effective trajectory throughput, and costs that can be audited under a single definition. Connecting those pieces is how limited compute becomes stable task delivery.
