Task Completion Evaluation for AI Agents: Metrics, Frameworks, and Practices
This article explains why dialogue quality alone is insufficient for evaluating large models in real engineering environments. It breaks down the five stages of an agent execution loop, proposes task-oriented evaluation dimensions such as end-to-end completion rate and tool-call accuracy, and shows how to build a repeatable evaluation framework with objective verification. It also covers test-task design, common failure modes, and practical guidance for model selection and deployment.
1. Good Answers Are Not the Same as Completed Tasks
When evaluating large models, many teams still use conversation quality as the primary criterion, looking at whether answers are well organized and clearly expressed. This kind of evaluation is useful for writing, question answering, and summarization tasks, but it does not reflect how a model performs in a real engineering environment.
Consider a common development request: refactor a login module, add unit tests, run the tests, and fix any errors. This task contains four interdependent actions: understanding the project structure, modifying code, executing verification, and continuing to revise based on feedback. If the model outputs a block of code and stops, the task has actually completed only the first step.
Task-oriented evaluation should therefore focus on whether the work gets done. It can be divided into three questions:
- Does the final artifact meet the acceptance criteria, such as whether tests pass and whether the functionality meets requirements?
- Is the execution process stable, or does it contain ineffective loops, unintended changes to unrelated files, or missing critical steps?
- Is the cost of completing the task acceptable, including the number of calls, elapsed time, and resource consumption?
Only by considering these three questions together can evaluation results guide practical model selection.
2. The Five Stages of an Agent Execution Loop
A typical development agent usually includes the following stages, each of which can become a failure point.
1. Task decomposition: Convert a natural-language request into executable steps. If the decomposition is too coarse, the model may skip critical details; if it is too fine, it may add unnecessary calls.
2. Context acquisition: Read the directory structure, locate relevant files, and understand existing interfaces and dependencies. This stage determines whether the model works from real code rather than inventing function signatures.
3. Modification and operation: Edit files, invoke command-line tools, and modify configuration. Whether tool-call parameters are correctly formatted and whether the scope of operations is controlled both affect the result.
4. Verification: Run tests, inspect build artifacts, and read output logs. Without a verification stage, it is difficult to judge whether the result is reliable.
5. Diagnosis and repair: Locate the cause based on error information, make changes, and verify again. This loop usually determines whether the agent can complete a task independently.
These five stages form a closed loop. During evaluation, records should be kept for each stage so that bottlenecks can be identified.
3. Core Evaluation Dimensions
The table below lists metrics recommended for inclusion in an evaluation system and how to measure them.
| Dimension | What It Measures | Measurement Method |
|---|---|---|
| End-to-end completion rate | Whether the task ultimately meets acceptance criteria | Run predefined automated checks and calculate the pass rate |
| Tool-call accuracy | Whether call timing, parameter format, and call count are reasonable | Perform structural validation on call logs and count invalid or repeated calls |
| Long-horizon consistency | Whether constraints set earlier are followed in long tasks | Embed constraints in tasks and check whether the final artifact violates them |
| Self-correction ability | Whether the agent can revise based on error information after failure | Measure the proportion of successful repairs after the first failure and the average number of repair rounds |
| Delivery quality | Code standards, interface quality, and documentation completeness | Combine static checks, screenshot comparison, and manual spot checks |
| Cost and efficiency | Time and resource consumption for completing the task | Record call count, input/output length, and total elapsed time per task |
Note that completion rate is the most direct metric, but using it alone can easily hide problems. For example, a model may make tests pass by modifying test cases. This result appears successful in the completion rate, but the actual quality may be poor. Acceptance criteria therefore need to be strict enough, and the agent’s permission to modify test files should be restricted.
4. Building an Evaluation Framework
The core of an evaluation framework is a repeatable execution loop plus objective verification functions. The following schematic code illustrates the basic structure.
def run_task(task, model, tools, max_steps=30):"""Run a single task and return the execution trace and verification result."""history = [{"role": "user", "content": task.prompt}]trace = []for step in range(max_steps):reply = model.generate(history, tools=tools.schema())trace.append(reply)if reply.tool_call is None:break # The model did not request a tool call, so this round is considered finishedresult = tools.execute(reply.tool_call, workspace=task.workspace)history.append({"role": "assistant", "content": reply.text,"tool_call": reply.tool_call})history.append({"role": "tool", "content": result.output})passed = verify(task.workspace, task.checks)return {"trace": trace, "passed": passed, "steps": len(trace)}def verify(workspace, checks):"""Each check returns a Boolean value; the task succeeds only if all checks pass."""results = {name: check(workspace) for name, check in checks.items()}return all(results.values())
This code has several design points:
- Step limit: Prevent the model from entering ineffective loops. The limit should be set according to task complexity and noted in the report.
- Full trace: Save the output and tool calls at each step for later analysis of failure causes.
- Independent verification: Verification functions should not rely on the model’s self-report. It is not enough for the model to say “fixed”; objective results such as test exit codes and file content comparisons are what count.
- Multiple checks: Split acceptance criteria into multiple independent checks so that failed conditions can be identified precisely.
In real engineering, tools.execute should expose only necessary operations, such as reading and writing files within the working directory and running specified test commands. Both the write scope and the command allowlist need to be defined in advance.
5. Designing a Test Task Set
The quality of the task set directly determines whether evaluation conclusions are reliable. It is recommended to organize tasks as follows.
Layered coverage: Divide tasks into several levels by complexity, such as small single-file changes, multi-file refactoring, defect fixes with tests, and generating a front-end page from a requirements description. Each level should contain a certain number of tasks so that conclusions do not come from only one type of scenario.
Explicit acceptance criteria: For each task, clearly define the input, expected artifact, and checking method. For example, “add mobile phone number format validation, return an error code for invalid input, and pass existing tests plus three new cases” is more suitable for automated verification than “improve the login feature.”
Repeated runs: Agent outputs are stochastic. The same task should be run multiple times, and success rates and variance should be measured rather than relying on a single result. When conditions allow, fix sampling parameters and record the model version and runtime environment.
Isolated environment: Use a clean working copy for each run to prevent modifications from a previous run from affecting the next result.
Holdout samples: When adjusting prompts or tool definitions, use tasks that were not involved in tuning for final evaluation to prevent overfitting the evaluation results.
6. Common Failure Modes and Mitigations
The following failure types are common during evaluation and can be addressed with pre-designed countermeasures.
Premature termination: The model stops immediately after providing code without running verification. The mitigation is to enforce a verification step at the framework level rather than relying only on prompt instructions.
Ineffective loops: The model repeatedly reads the same file or executes the same command. Recent call sequences can be recorded to detect repeated patterns, interrupt the loop, and prompt a different approach, while retaining the step limit as a fallback.
Modifying acceptance conditions: To make tests pass, the model may delete assertions or modify test files. Test files should be made read-only, or an independent test copy should be used during verification.
Context overflow: When a project is large, inserting all files at once can exceed the context length and push out critical information. A more reasonable approach is retrieval on demand: first read the directory and key interfaces, then gradually expand specific files.
Functionally correct but poorly delivered: A front-end page may run, but the layout is broken and interactions are incomplete. Screenshot comparison, component structure checks, and manual spot checks can be added to include visual quality in scoring.
Ambiguous error attribution: After a failure, it may be unclear whether the problem lies in planning, tool invocation, or repair. The solution is to tag each step in the trace with a stage label and analyze failures by stage.
7. Model Selection and Deployment Guidance
Define tasks before selecting models. Teams should first identify high-frequency tasks in their actual business and then compare models using a unified task set. Rankings that are detached from specific scenarios have limited value for model selection.
Compare fairly. Different models should use the same tasks, the same toolchain, the same verification criteria, and the same step limit. If a model requires an additional prompt template, record it separately and explain its impact on results.
Balance cost and capability. Smaller models often have advantages in inference cost and response latency, making them suitable for scenarios with clear task boundaries and frequent calls. Complex cross-module refactoring or problems requiring deeper reasoning may require more capable models. Model selection should consider both completion rate and per-task cost.
Minimize permissions. An agent’s file write scope should be limited to the working directory. Operations such as deleting files, changing permissions, and deploying to production should require human confirmation, and complete operation logs should be retained for auditing.
Do not omit human review. Automated verification can catch most obvious errors, but it cannot fully replace code review. Code involving security, funds, or user privacy especially requires line-by-line human inspection.
Evaluate continuously. Model version updates, tool interface changes, and business requirement changes can all affect agent performance. It is recommended to include the evaluation task set in the continuous integration process and run regression tests regularly to detect capability degradation in time.
In summary, whether a large model can “do the work” depends on whether it can complete multi-step tasks in a real environment and prove the result through objective verification. Building task sets, execution frameworks, and verification mechanisms is more effective than relying on subjective impressions when making stable and reliable technical decisions.
