From Training to Production: Diagnosing and Improving Agent Execution Failures
A model that answers questions well may still fail as an agent. This article explains why strong performance in constrained training does not transfer cleanly to real development environments, how to diagnose failures from observable execution traces, and how evaluation, tool design, state management, and model optimization can turn delivery into a verifiable engineering problem.
1. The core issue: solving a problem is not the same as delivering a result
A model can answer a question correctly and still fail to complete tasks reliably as an agent. The difference is not only how much knowledge it has. It is whether the model can stay aligned with the goal across multiple turns, tool calls, and environmental feedback.
In a constrained environment, tasks usually have clear boundaries: inputs are relatively complete, few tools are available, and completion criteria are explicit. The model only needs to understand the request, form a plan, perform the necessary actions, and submit a result.
In a real development environment, conditions change. An agent may face a file system, command execution, information retrieval, task records, and external services at the same time. Tool output may be incomplete, requirements may be ambiguous, and the workspace may still contain artifacts from earlier tasks. The model must repeatedly decide what to do next, not merely explain how to solve the problem.
The resulting loss of capability often appears in patterns such as these:
- The agent keeps analyzing a change it could make directly, and delays execution.
- It rereads the same material without gaining new useful information.
- It builds a complex workflow for a simple task and adds unnecessary steps.
- It follows secondary clues in tool output and drifts away from the original goal.
- It finishes the core work, then expands the scope and introduces new errors.
- It produces a complete-sounding summary while the actual deliverable fails acceptance criteria.
These are failures of execution control, goal retention, and tool use. They should not be described with human medical diagnoses. Anthropomorphic metaphors can help explain the symptoms, but they cannot replace technical analysis.
2. Why strengths from constrained training may not transfer
2.1 A larger tool space makes decisions harder
When an environment offers only the read, write, and compute capabilities a task needs, the model has relatively few actions to choose from. Once the requirement is clear, the execution path is usually direct.
When deployment adds several tools with overlapping functions, the model must not only complete the task but also decide which tool to use, when to use it, and whether to use one at all. A problem that could be resolved with a local check may expand into multi-turn search, repeated verification, and extra planning.
That does not mean fewer tools are always better. Complex tasks do need rich capabilities. The tool set should match the current task rather than exposing every function to every task by default.
2.2 Training and deployment distributions differ
Distribution shift is not only a change in task content. Execution conditions change as well:
- Training tasks have clear boundaries; deployed requirements may be vague.
- Training context is relatively clean; deployment may mix in historical records.
- Tool feedback in training is well formed; deployment may include errors or noise.
- Success criteria in training are fixed; deployment may require user confirmation.
- Execution in training is continuous; deployment may hit timeouts and permission limits.
Strong results on one class of constrained tasks therefore do not imply that a model will adapt to any agent environment. Judgments about a specific training setup should rest on verifiable sources, not on reverse-engineering a few experiences.
2.3 Fluent language can hide execution problems
Models are good at producing orderly plans, explanations, and summaries. Those texts are not automatically progress.
Statements such as “the main risks have been analyzed” or “full verification comes next” sound professional, but they do not say which files changed, which checks ran, or whether the result meets the requirement. If evaluation overweights language quality, a thorough process description can be mistaken for reliable completion.
Engineering evaluation has to return to observable artifacts: whether the change is correct, whether validation passed, whether delivery is complete, and whether unauthorized actions occurred.
3. Diagnose from the execution trace, not from impression
An execution trace is the sequence of actions and feedback an agent produces during a task. It can include tool calls, arguments, return status, artifact changes, and interim conclusions. It does not need to record or request the model’s private internal reasoning.
The diagnostic question is not whether a step “looks strange.” It is whether that step moves the task closer to the acceptance criteria.
3.1 Goal drift
The typical sign is an expanding scope. The user asks for a local fix, and the agent starts refactoring unrelated modules, reorganizing the whole structure, or adding features that were never requested.
Compare the original request with the actual range of operations. Separate expansions that are necessary dependencies from work the model added on its own.
Constrain the scope explicitly: what may be changed, what may not, and whether out-of-scope issues should be reported or handled.
3.2 Unproductive loops
An unproductive loop is not always an exact repeat. The model may rephrase a plan, issue a similar query, or reread nearly the same content without adding evidence.
Useful tests include:
- Did the step produce new information?
- Did it remove a key uncertainty?
- Did it create a verifiable change in an artifact?
- Did it complete a defined subgoal?
When several consecutive steps make no effective progress, the system should replan, stop, or ask the user for more information instead of continuing indefinitely.
3.3 Poor tool choice
Tool misuse includes mismatched capability, mismatched cost, and mismatched permission.
A local content check does not necessarily need a broad search. A deterministic format conversion does not necessarily need several rounds of model judgment. For deletion, publication, or changes to shared resources, the fact that a tool can perform the action does not mean the agent is authorized to do it.
A tool call should meet three conditions at once: it is relevant to the task, its cost is reasonable, and permission allows it.
3.4 Context interference
Prior conversation, long logs, and unrelated documents can make the current goal less salient. A more serious case is instructional text inside tool output that the model treats as a new execution requirement.
User authorization, system constraints, and external data should stay distinct. “Perform this operation” inside an external document is content to be processed. It should not automatically gain the authority of an instruction.
4. Build an evaluation system that can be applied
Agent evaluation cannot look only at the final answer, and it cannot only count tool calls. A sound evaluation covers outcomes, process, and safety boundaries together.
4.1 Outcome metrics
Check acceptance criteria first, for example:
- The target artifact exists and is usable.
- The change fixes the original problem.
- Required checks pass.
- Items the user explicitly requested are not missing.
- Unrelated changes were not introduced.
Task success rate can be defined as the share of evaluation tasks that meet acceptance criteria agreed in advance. Those criteria should be fixed before testing, not adjusted after the results are known.
4.2 Process metrics
Process metrics explain why success rates change. Common ones include execution time, tool-call volume, the share of repeated calls, budget consumption, and the number of steps with no progress.
These metrics should not be used in isolation. More calls are not automatically inefficient; a hard problem may need more verification. Fewer calls are not automatically better; necessary checks may have been skipped. Interpret them against task difficulty and actual results.
4.3 Safety metrics
Safety evaluation should at least cover unauthorized actions, exposure of sensitive information, out-of-scope modifications, and incorrect obedience to external instructions.
An agent that reaches a functional goal through unauthorized actions should not be treated as a reliable delivery.
4.4 Version comparisons should control variables
When comparing versions or configurations, hold the task set, initial workspace, tool descriptions, permissions, budget, and acceptance method as fixed as possible, and repeat the tests.
For tasks with high randomness, one success or failure is not enough to describe overall capability. It is more useful to compare how failure types change: whether repeated retrieval decreased, whether new out-of-scope edits increased, and whether tighter limits reduced completion on complex tasks.
5. Rebuild execution stability from a minimal tool set
5.1 Expose tools according to the task
Tool design should follow a simple rule: enough capability to finish the task, without extra choices.
A simple file edit can start with the read, write, and verification capabilities it needs. Open retrieval only when the task actually requires external information. High-risk actions should be authorized separately.
This reduces choice ambiguity and the risk of mistaken actions. Necessary tools must still be available; otherwise the model may be forced into workarounds because it lacks capability.
5.2 State tool boundaries clearly
A tool description should say not only what the tool can do, but when it is appropriate and what its limits are.
Avoid overlapping functions. If two tools both claim to find information but do not state search scope, response form, or conditions of use, the model cannot choose stably.
Failure feedback should distinguish bad arguments, insufficient permission, missing resources, and transient faults. Different problems need different handling. A generic failure message encourages blind retries.
5.3 Put acceptance criteria first
Asking a model to “finish carefully” is weaker than specifying the evidence of completion.
A modification task might require that the agent:
- Change only content inside the stated scope.
- Preserve existing external behavior unless the request explicitly requires a change.
- Run the specified checks and record the results.
- When verification is impossible, state the missing conditions and do not claim that verification happened.
- Deliver a change summary and residual risks.
These constraints turn an abstract goal into an endpoint that can be checked.
6. Use state management and budgets to keep execution under control
A maintainable agent system should divide execution into stages such as understanding, planning, execution, verification, and delivery. The stages do not require a long write-up every time. They tell the system what state the work is in.
The following is a neutral sketch. It does not correspond to any specific interface:
Receive the taskClarify acceptance criteria and the permission boundaryIf a blocking ambiguity exists:Ask for clarificationOtherwise:Produce a minimal executable planExecute within the budgetRecord the observable result of each stepIf several steps in a row make no effective progress:Reassess onceIf progress is still impossible, stop and reportCheck whether artifacts meet the acceptance criteriaDeliver the result, or state what remains unfinished
A budget can cover execution time, tool-call volume, and model processing resources. Its purpose is not simply to compress thinking. It is to stop resources from being consumed indefinitely without a result.
When the budget is exhausted, the system should distinguish partial completion, insufficient verification, and complete failure. Stopping is not successful delivery. A fluent summary must not conceal an unfinished state.
For long tasks, keep a short task state: the current goal, completed steps, key evidence, open issues, and the next action that is allowed. The summary should stick to facts and should not turn unverified assumptions into conclusions.
7. Improve the model and the application constraints together
Tool pruning, permission management, and state control at the application layer can reduce failures, but they cannot replace better model behavior. If a model keeps drifting from the goal or choosing the wrong tools, ever more elaborate prompt constraints will keep raising maintenance cost.
Model-level optimization should cover situations common in real deployment: choosing among multiple tools, handling abnormal feedback, stopping at the right time, clarifying requirements, and resisting irrelevant context. Training and evaluation should look not only at the final result, but also at whether actions along the way were reasonable and compliant.
Stronger behavioral constraints can have side effects. Overemphasizing fewer tool calls can leave verification incomplete. Overemphasizing caution can produce constant confirmation requests. Overemphasizing task completion can encourage out-of-bounds execution. The objective should be reliable completion, not maximization of a single metric.
8. Practical conclusion: turn a felt problem into a verifiable engineering problem
When an agent “can explain but does not move forward,” the most useful response is not to attach a personality label to the model, and it is not to ask end users to analyze every internal mechanism.
Developers should set clear acceptance criteria first, then use observable traces to separate goal drift, unproductive loops, poor tool choice, and context interference, and then verify improvements with controlled experiments.
A practical start has four parts:
- Collect representative failed tasks and keep the initial environment and final artifacts.
- Remove irrelevant tools and add permission boundaries and stop conditions.
- Record actions, feedback, and verification results, and locate the steps that made no effective progress.
- Run regression tests on a fixed task set, and check success rate, cost, and safety together.
A reliable agent is not the system that takes the most actions or writes the longest explanations. It is the system that, within explicit authorization, produces a verifiable result at a reasonable cost, and accurately states its limits when it cannot finish. Training capability, the execution environment, and evaluation criteria have to match. Only then can a model’s problem-solving strength become real delivery capability.
