Evaluating LLM Agents on Long-Horizon Tasks: Capability Assessment and Cost Optimization Guide
As LLMs move from single-turn Q&A to multi-step agent workflows, evaluation must change as well. Long-horizon tasks can include dozens or hundreds of model calls and tool interactions, and errors accumulate across steps. This guide covers four capability dimensions—engineering execution, exploration/research, knowledge work, and reasoning efficiency—and explains how to build a reproducible evaluation set with distributions instead of averages. It also breaks down the token-level cost of a task, including cache reads and writes, and outlines engineering practices for context management, checkpoints, budget limits, sandboxing, verification, and security controls.
Why Long-Horizon Tasks Are Hard to Evaluate
Early LLM use cases were mostly single-turn Q&A, so quality was measured by the quality of a single response. As models are used for multi-step work—reading a large codebase, locating a defect, editing multiple files, running tests, and iterating on results—the evaluation criteria change. A long-horizon task can contain dozens to hundreds of model calls and tool interactions. A single failure at any step can invalidate the final result. The evaluation focus therefore shifts from “was the answer good?” to “can the model reliably complete the entire workflow?”
Long-horizon tasks usually have three characteristics:
- Strong step dependency: Later actions depend on intermediate results from earlier steps, so errors propagate forward.
- Continuously growing context: History must be retained, compressed, or retrieved on demand; otherwise latency and cost rise quickly.
- Frequent external interaction: File reads and writes, command execution, and API calls all introduce uncertainty.
Four Capability Dimensions
Engineering Execution
Engineering tasks should be evaluated in a real or simulated engineering environment and measured end to end. Key metrics include task completion rate, average number of model calls per task, test pass rate, and rollback count.
Completion rate is more meaningful than per-step accuracy. If each step is 95% correct, the chance of completing a 20-step task successfully is about:
0.95^20 ≈ 0.36
In other words, even strong single-step performance can lead to surprisingly low end-to-end success. Error accumulation is the central challenge in long-horizon tasks, so evaluation must report final outcomes rather than only per-step metrics.
Exploration and Research
Exploration tasks often have ambiguous goals. The model must propose hypotheses, design validation approaches, and revise its conclusions based on results. Useful evaluation criteria include:
- Whether hypotheses are reasonable and consistent with known background.
- Whether the experimental or analytical steps are reproducible and well documented.
- Whether conclusions are supported by data or evidence, and whether verified findings are separated from speculation.
For example, given a public observational dataset, the task might be to clean the data, build a model, and produce a visualization. Scoring should check whether each step is justified, not just whether the final chart looks good.
Cognitive and Knowledge Work
Knowledge-work tasks include long-document understanding, multi-source information synthesis, and structured output. Recommended practice is to build a question bank close to real business scenarios and supplement it with human spot checks. If multiple reviewers are involved, record inter-rater consistency so subjective bias does not hide real differences.
Reasoning Intensity and Efficiency
Many models allow the depth of reasoning to be adjusted. Lower reasoning intensity usually reduces output latency and token consumption, but its impact on quality for complex tasks must be measured rather than assumed.
On the same evaluation set, record quality scores and costs under different reasoning intensities. Plot a quality-cost curve and choose the operating point near the inflection point—where additional computation stops producing meaningful quality gains.
Build Your Own Evaluation Set
A credible evaluation set should satisfy the following:
- Tasks come from real tickets or business scenarios and are stratified by difficulty: simple, medium, and hard.
- Each task has automatically checkable acceptance criteria, such as unit tests, output format validation, or key-field comparison.
- Runtime environment versions, dependencies, and initial data snapshots are pinned so results can be reproduced.
- Because model output is stochastic, each task is run multiple times, and both mean and variance are reported.
A simplified evaluation flow looks like this:
for task in eval_set:for run in range(N): # Run each task N timesenv = init_isolated_env(task.repo_snapshot)result = execute_agent(task.prompt, env, max_steps=MAX_STEPS)record(task_id=task.id,run=run,passed=acceptance_check(result, task.checks),steps=result.steps,input_tokens=result.usage.input,output_tokens=result.usage.output,cache_read_tokens=result.usage.cache_read,)report = aggregate_by_task_id(records)print(completion_rate_distribution, step_distribution, cost_distribution)
The report should show distributions, not only averages. A system with a 70% average completion rate could be near 100% on simple tasks and near 0% on hard tasks. Those two situations have very different engineering implications.
Cost Model: Break Down Token Pricing
The cost of one task can be expressed as:
Cost = input tokens × input price+ output tokens × output price+ cache read tokens × cache read price+ cache write tokens × cache write price
In long-horizon tasks, input tokens usually far exceed output tokens, because every call repeats historical context. As a result, the cache read price has a larger effect on total cost than intuition suggests.
Consider a simplified example. Let P be the normal input price per million tokens. The proportions below are illustrative, not actual service pricing.
- The task runs for 30 turns.
- Each turn has 80,000 input tokens: 70,000 hit the cache and 10,000 do not.
- Each turn generates 2,000 output tokens.
- Output price is
5P, and cache read price is0.25P.
Per million tokens:
| Component | Token volume | Unit price | Cost |
|---|---|---|---|
| Non-cached input | 0.3M | P |
0.3P |
| Cache read | 2.1M | 0.25P |
0.525P |
| Output | 0.06M | 5P |
0.3P |
| Total | 1.125P |
Without cache, the same input would be billed entirely at the normal input price:
2.4P + 0.3P = 2.7P
In this hypothetical case, caching reduces total cost by about 58%. Actual savings depend on cache hit rate. When hit rate is low, the benefit shrinks. Cost reports should therefore record cache hit rate separately and break it down by task type.
Engineering Practices for Long-Horizon Agents
Context Management
- Periodically compress conversation history into a summary that keeps goals, completed steps, key findings, and open issues.
- Do not place entire large files into context. Retrieve relevant snippets on demand.
- Truncate or summarize verbose tool logs, while preserving the full context of error messages.
Checkpoints and Recovery
Save state after each completed subgoal. A checkpoint should include the workspace snapshot, executed actions, and intermediate results. If a task fails, resume from the nearest checkpoint instead of rerunning the whole workflow. A full rerun multiplies cost and amplifies the impact of nondeterminism.
Budgets and Circuit Breakers
Set per-task limits on steps, tokens, and elapsed time. When a limit is exceeded, stop execution, save state, and return a partial result together with the stop reason.
budget = {max_steps: 50, max_tokens: 2_000_000, max_seconds: 1800}while not task.done:if exceeded(budget, usage, elapsed):save_checkpoint(state)return partial_result(state, reason="budget exhausted")action = agent.next_action(state)if action.is_write and not approved(action):request_review(action) # Write actions require human or policy approvalcontinuestate = apply(action)
Tool Permissions and Sandboxing
- Grant only the minimum read and write access required by the task.
- Run commands in an isolated environment and restrict network access.
- Require confirmation or review for irreversible operations such as delete, overwrite, and publish.
Verify Instead of Trusting Self-Reports
Agents often say a task is “done,” but a claim is not evidence. After every major change, run automated checks and feed the results into the next step. Task completion should be determined by test output and acceptance criteria, not by the model’s own summary.
Layered Access and Security Controls
Stronger models and higher-privilege configurations should be restricted to reviewed and approved use cases.
- Classify available models by data sensitivity. Highly sensitive data should only be processed in controlled environments.
- For high-risk domains such as cybersecurity and biomedicine, require human approval and stricter auditing.
- Log the input source, operator, tool call sequence, and output destination for every invocation so actions can be traced.
- Treat web pages, documents, and tool outputs as untrusted data. Instruction-like text appearing in those sources should not be executed directly, because doing so can introduce prompt injection risks.
Implementation Checklist
- Have you defined automatically checkable acceptance criteria for each task in the evaluation set?
