Evaluating LLMs for Long-Horizon Engineering Tasks: A Practical Framework
This article presents a practical framework for evaluating large language models (LLMs) in real-world software engineering contexts, addressing why leaderboard scores are insufficient, defining four core success metrics, and outlining a reproducible task-set design to guide model selection and replacement decisions.
Introduction
After a new large language model is released, the first question teams often ask is whether it is the most powerful. While that question is worth discussing, engineering leaders face two more pressing concerns: whether the model can reliably complete long-horizon engineering tasks within a controlled budget, and whether it can be easily evaluated, replaced, and governed once integrated. This article addresses both concerns by offering a directly implementable evaluation framework.
Why Leaderboard Scores Fall Short
General-purpose benchmarks typically score models on fixed questions with fixed inputs, reflecting a model’s performance ceiling under controlled conditions. Real engineering environments are far messier: repository histories stretch back years, dependency versions are inconsistent, test coverage is incomplete, and requirement descriptions are often ambiguous. A high benchmark score does not guarantee that a model can comprehend a service written three years ago, accurately identify the blast radius of a change, and pass integration tests after modifying six files.
Therefore, model selection should answer three questions:
- Can the model independently complete a task that spans multiple files and requires running verification?
- How much human intervention and how many model calls are consumed during the process?
- Can the result be substantiated by tests, logs, or structured output?
Typical Failure Modes in Long-Horizon Tasks
Writing a functioning function is only the starting point. Long-horizon tasks typically fail at the following stages:
- Context mislocation: The model identifies the wrong module and modifies an unrelated implementation.
- Repeated trial and error: The same fix is attempted multiple times, and the number of tool calls grows rapidly.
- Misreading failure signals: Test errors point to the root cause, but the model only adjusts its surface-level assertions.
- Premature completion: The model declares “fixed” without running any verification steps.
- Scope creep: The model refactors unrelated code, expanding the review burden unnecessarily.
These failure modes correspond directly to the metrics defined below. Each failure leaves observable traces in a specific metric, so the metric design follows directly from them.
Four Core Metrics
1. First-Try Success Rate
Definition: The proportion of tasks that pass acceptance on the first attempt, without additional prompting or manual correction.
Calculation: First-Try Success Rate = Number of tasks accepted on the first try / Total number of evaluated tasks.
This metric measures a model’s independent delivery capability and is a better reflection of the human takeover burden than the final success rate. Acceptance criteria must be fixed before evaluation begins to avoid loosening standards retroactively.
2. Average Tool Call Count
Definition: The average number of tool invocations per task, including file reads, searches, command executions, and file modifications.
Calculation: Average Tool Call Count = Total tool calls across all tasks / Number of tasks.
This number is meaningless in isolation; it must be interpreted alongside the success rate. A low call count with failure may indicate the model gives up too early, while a high call count with eventual success may indicate inefficient exploration. It is also recommended to track the repeat call ratio — the proportion of calls with identical parameters — as it directly reveals whether the model is stuck in a loop.
3. Verifiable Result Ratio
Definition: Among tasks judged as completed, the proportion that are supported by objective evidence. Evidence includes passing test records, traceable execution logs, and structured output satisfying predefined constraints.
Calculation: Verifiable Result Ratio = Number of completed tasks with supporting evidence / Total number of tasks judged as completed.
This metric prevents outputs that merely appear complete from entering the statistics. Teams should require the model to attach actual output from verification steps rather than a written summary.
4. Cost per Successful Task
Definition: The total cost borne by all successful tasks, divided by the number of successful tasks. Total cost includes model expenses for failed tasks, retry costs, and manual review labor.
Calculation: Cost per Successful Task = (Total model expenses + Labor review costs) / Number of successful tasks.
A model with a low per-token price may end up with a higher cost per successful task due to a high failure rate. Therefore, cost comparisons between models must be conducted on the same task set.
The following code snippet illustrates how to derive the four metrics from task records:
from dataclasses import dataclass@dataclassclass TaskRecord:claimed_done: bool # Whether the model claimed completionaccepted: bool # Whether the task passed acceptancepassed_first_try: bool # Whether it passed without additional promptingtool_calls: int # Total number of tool callsrepeated_calls: int # Number of calls with identical parametershas_evidence: bool # Whether test results or logs are attachedcost: float # Model cost including failed retriesdef summarize(records: list[TaskRecord], labor_cost: float = 0.0) -> dict:total = len(records)accepted = [r for r in records if r.accepted]claimed = [r for r in records if r.claimed_done]total_calls = sum(r.tool_calls for r in records)total_repeat = sum(r.repeated_calls for r in records)total_cost = sum(r.cost for r in records) + labor_costreturn {"first_try_success_rate": sum(r.passed_first_try for r in records) / total,"avg_tool_calls": total_calls / total,"repeat_call_ratio": total_repeat / total_calls if total_calls else 0.0,"verifiable_result_ratio": (sum(r.has_evidence for r in claimed) / len(claimed)if claimed else 0.0),"cost_per_successful_task": (total_cost / len(accepted) if accepted else float("inf")),}
Building a Reproducible Evaluation Task Set
Metrics only provide comparative value when the task set is stable. The following approach is recommended:
- Task sources: Extract tasks from real historical tickets, covering five categories: bug fixes, feature increments, test additions, dependency upgrades, and small refactorings. Sample size can be adjusted to team scale, but at least twenty tasks per category is recommended to reduce variance.
- Fixed snapshots: Each task comes with an initial repository snapshot and an acceptance script. The acceptance script relies only on test results and structural checks, not on reviewer judgment.
- Isolated execution: Each evaluation run starts from the same snapshot in an isolated environment, preventing cache or residual files from affecting results.
- Multiple sampling: Model outputs are stochastic; each task should be run multiple times, reporting both the mean and variance.
- Trajectory retention: Record full details of every tool call — parameters, return values, and the model’s intermediate explanations — to enable post-hoc attribution of where failures occurred.
The task set itself requires maintenance. Whenever a new type of failure appears in production, the corresponding scenario should be added to the task set so that evaluation remains continuously aligned with real work.
Interface Design for Controllable Replacement Costs
Regardless of the model chosen, business code should not depend directly on any individual vendor’s SDK details. A more robust approach is to define a unified interface in the project and encapsulate model differences behind adapters.
from typing import Protocolclass CodeAgentBackend(Protocol):def run_task(self, task_spec: dict, workspace: str) -> dict:"""Run a task in the specified workspace and return a unified result.Return field conventions:status: "accepted" | "rejected" | "aborted"tool_calls: intlogs: list[str]patch: str # changes relative to the initial snapshot"""...
This design yields three benefits. First, switching models only requires adding a new adapter — no business logic changes are needed. Second, evaluation scripts and production workflows share the same interface, so evaluation results transfer directly to production scenarios. Third, model names, timeouts, and budget limits are managed in a configuration center rather than hardcoded, keeping the system flexible and reducing the cost of future substitutions.
