Why the Same AI Agent Sometimes Succeeds and Sometimes Fails: A Practical Guide to Task Stability

    A successful agent run is not the same as reliable delivery. This article explains why repeated runs of the same agent can swing between success and failure, how to separate pass rates from consistency, and how execution design, controlled retries, repeatable evaluation, and observability turn occasional success into dependable results.

    1. One success does not mean stable delivery

    In agent applications, there is a clear gap between a successful demo and production reliability. A task may finish cleanly the first time, modify the wrong file the second time, fall into useless retries the third time, and succeed again the fourth. For developers, this kind of variation is harder to diagnose than consistent failure: the system appears capable of solving the problem, yet it cannot deliver that result consistently.

    The source material describes an evaluation of 100 difficult terminal tasks. The same set was run four times. One agent execution framework had an average single-run pass rate of 50.25%, while only 39% of tasks succeeded in all four runs.

    These two numbers do not measure the same thing:

    • Average single-run pass rate reflects the overall level of success across individual executions.
    • Share of tasks that succeed in all four runs reflects consistency under repetition.
    • Share of tasks that succeed at least once reflects how many tasks the system can cover across multiple attempts.
    • Share of fluctuating tasks reflects how many tasks produce both successes and failures.

    Using the statistics in the source material, 100 tasks were executed 400 times. A 50.25% average pass rate corresponds to 201 successes. Thirty-nine tasks succeeded in all four runs and account for 156 of those successes, while the remaining 61 tasks account for 45 successes. This shows that, beyond the stably successful tasks, some executions mix success and failure.

    These two aggregate figures alone cannot support the claim that “more than one-third of tasks fluctuate.” The remaining 45 successes may be concentrated in a small number of tasks or spread across many more. Per-task results are required to determine the actual proportion.

    This leads to the first principle of agent evaluation: aggregate scores can indicate a problem, but they cannot replace analysis of the execution distribution and failure traces. The figures above are only a case supplied by the source material and should not be generalized directly to other models, frameworks, or business environments.

    2. Why agent results fluctuate

    An agent is not a model that merely generates one answer. It is a system that continually interacts with an environment. It typically needs to understand the goal, inspect the environment, make a plan, call tools, read feedback, change state, and then decide the next action.

    A failure may therefore come from the model, the execution framework, the environment state, or the verification logic.

    2.1 Decision paths are uncertain

    The same task often has several valid routes. The agent may inspect directories first or read configuration first. It may make a local change or prefer to refactor related logic.

    These routes can all look reasonable at the first step, but their later risks differ. One route may quickly obtain critical evidence, while another may depend on an unverified assumption. A small early decision can produce a large difference in outcome after many rounds of interaction.

    Reducing randomness in generation usually reduces some variation, but it cannot make the whole system fully deterministic. External feedback, context composition, tool-result ordering, and the runtime environment can still change later decisions.

    2.2 Long chains accumulate chances to fail

    Complex tasks often contain multiple necessary steps. If each step has some probability of failure, the reliability of the whole chain declines.

    Under the simplified assumption that steps are independent and any single failure causes the task to fail, task success probability can be expressed as:

    Task success probability = the product of the success probabilities of all necessary steps.

    Real agent tasks usually do not satisfy a strict independence assumption. One misjudgment can affect several later steps, and some failures can be recovered. The expression is therefore not a formula for predicting actual performance. It illustrates a basic fact: the longer the chain, the more explicit verification and failure recovery it needs.

    Reducing unnecessary exploration, confirming critical constraints early, and splitting large tasks into verifiable stages is often more valuable engineering work than simply adding more reasoning text.

    2.3 A successful tool call is not task completion

    A successful tool response usually means only that the operation completed according to the tool’s own rules.

    For example:

    • A successful file write does not mean the content is correct.
    • A finished program run does not mean the output meets business requirements.
    • One check passing does not mean every other critical constraint is satisfied.
    • An accepted external request does not mean the target state has finally taken effect.

    If an agent treats an intermediate success as final completion, it may stop too early. A stable system must distinguish operation results, state changes, and acceptance results rather than treating them as the same thing.

    2.4 Environmental changes amplify differences along the same path

    The same task description does not mean the same execution conditions. Leftover files, dependency changes, resource contention, permission differences, time-dependent logic, and external service state can all affect the result.

    During repeated runs in particular, temporary files, caches, or background processes left by the previous run can change the starting point of the next one. Observed fluctuation may then come not from model decisions, but from an evaluation environment that was not reset correctly.

    2.5 Context management can lose information

    Long tasks accumulate logs, file contents, and tool output. If the system retains too much low-value information while compressing away critical constraints, the agent may forget which approaches already failed, which files must not be changed, and which results have not been verified.

    An effective state summary should include at least:

    • The current goal and acceptance criteria.
    • Confirmed facts and their sources of evidence.
    • Completed operations and their results.
    • Unresolved issues.
    • Approaches that were tried and failed.
    • The next action and its stopping condition.

    The summary should also distinguish “observed facts” from “temporary assumptions,” so that unverified inferences are not treated as facts in later execution.

    3. Treat the execution framework as a reliability system

    The model proposes decisions; the execution framework turns those decisions into controlled actions. Stability work should start at system boundaries, not only with prompt adjustments.

    3.1 Define completion conditions explicitly

    “Solve the problem” is too broad to serve as a reliable acceptance standard. Before a task starts, the goal should be converted into observable conditions, such as:

    • The target file has been generated and its format meets the requirement.
    • Changes stay within the allowed scope.
    • All required checks pass.
    • Existing critical behavior has not been broken.
    • The final output is consistent with actual execution evidence.
    • No high-risk operation remains in an unconfirmed state.

    Completion conditions should preferably be independent of the agent’s self-assessment. The agent may believe the task is finished, but the system still needs to accept it based on external evidence.

    3.2 Use an act–observe–verify loop

    After every critical action, three questions should be explicit:

    1. What was actually executed?
    2. What changed in the environment?
    3. Does the change match expectations?

    After editing a file, for example, read the relevant content again and inspect the difference. After starting a long-running task, confirm its state rather than relying only on the startup message. Before submitting a result, inspect the final artifact rather than relying on an earlier plan description.

    Verification does not need to cover every minor action. A more practical approach is risk-based layering: low-risk reads can use lightweight checks, core changes need stage verification, and irreversible operations need stricter control.

    3.3 Create checkpoints, but define recovery boundaries

    Checkpoints can preserve verified file state, stage results, and necessary task context, so a later failure does not require a complete restart.

    A checkpoint cannot automatically undo every side effect. External notifications, payments, and remote resource changes usually cannot be rolled back merely by restoring local files. The system should therefore distinguish:

    • Local state that can be restored.
    • External state that can be repaired through compensating actions.
    • Operations that cannot be safely undone.

    For irreversible actions, necessary conditions should be verified before execution, and an auditable result should be recorded afterward.

    4. Retries must be controlled, not repeated endlessly

    Retries help with transient faults, but they do not automatically repair a wrong strategy. Repeating an action that fails consistently usually only increases cost.

    4.1 Classify the failure before deciding whether to retry

    Different failure types need different handling:

    • Transient faults: a brief connection failure or temporary resource unavailability may justify a limited retry.
    • Input errors: invalid parameters or a missing target should be corrected rather than repeated.
    • Missing preconditions: missing permissions, dependencies, or required files should be supplied, or the task should stop.
    • Logic errors: an artifact that does not meet the goal requires the plan to be reanalyzed.
    • Uncertain state: a request timed out but may already have taken effect, so state should be queried first.

    Uncertain state is especially dangerous. Blind retries can cause duplicate submissions, duplicate writes, or duplicate resource creation.

    4.2 Design idempotency controls for operations with side effects

    Idempotency means that repeating the same operation does not create additional unintended results.

    Depending on the business, an implementation may use a unique operation identifier, a pre-execution state check, duplicate-request detection, or an explicit completion record. It should not be assumed that every external operation is naturally idempotent. Without such a guarantee, state verification or human confirmation is required.

    4.3 Set limits on attempts, time, and cost together

    A retry policy needs stopping conditions. Beyond the retry count for a single action, the system should also limit total task duration, total tool calls, and resource consumption.

    When a budget is reached, the system should report completed work, failure evidence, the current environment state, and suggestions for how execution could continue. It should neither pretend the task succeeded nor keep looping without new evidence.

    5. How to build credible repeated-run evaluation

    5.1 Fix the task starting point

    Every evaluation round should use consistent initial files, dependency conditions, permission scope, and resource limits, and it should clean up residual state from the previous round.

    For tasks that depend on external systems, factors that cannot be fixed should also be recorded. Uncontrolled environmental differences should not all be attributed to the model.

    5.2 Preserve per-task, per-round results

    Recording only an overall average hides differences among tasks. Each task should retain multiple rounds of results, along with failure categories, execution cost, and the critical path.

    With a fixed number of repetitions, tasks can be divided into:

    • Stably successful tasks: every round succeeds.
    • Fluctuating tasks: some rounds succeed and some fail.
    • Persistently failing tasks: every round fails.

    These three groups need different optimization strategies. Fluctuating tasks are suited to analysis of path deviation, missing verification, and insufficient recovery. Persistently failing tasks more often require examination of capability boundaries, tool fit, and whether the task is solvable.

    The repetition count must be reported together with the result. “Successful in all four runs” and “successful in all ten runs” are not evidence of stability at the same strength.

    5.3 Measure both effectiveness and cost

    At a minimum, report:

    • Average single-run pass rate.
    • Share of tasks that pass every run at a fixed repetition count.
    • Share of fluctuating tasks.
    • Share of tasks that succeed at least once.
    • Time and resource consumption of successful executions.
    • Distribution of failure types.

    “At least one success” may rise as the number of attempts increases, but that does not mean a single execution is more reliable. If success depends on a large number of retries, the actual delivery cost may be unacceptable.

    5.4 Use controlled comparisons to validate improvements

    After adding checkpoints, changing context summaries, or introducing verification steps, compare results on the same tasks and under similar conditions. Change only one key factor at a time whenever possible.

    Also check whether an improvement creates a new cost. Does a higher pass rate come with a significant increase in time? Does the verification mechanism incorrectly reject correct results? Does recovery logic introduce new state contamination?

    When the evaluation budget allows, confidence intervals and paired per-task comparisons can help avoid mistaking chance variation in a limited sample for a stable gain.

    6. Use observability to find the real cause of failure

    The final output is usually not enough to explain why an agent failed. A reliable system needs to preserve key decisions, tool inputs and outputs, state changes, verification conclusions, and retry reasons.

    When analyzing a failure trace, look for the earliest deviation that affects later results, not only the last error. The final exception may simply be the consequence of an earlier incorrect assumption.

    A practical attribution framework is:

    • Understanding deviation: the goal or a constraint was misread.
    • Planning deviation: the route is unreasonable or omits a precondition.
    • Execution deviation: the operation target or a parameter is wrong.
    • Observation deviation: tool feedback was interpreted incorrectly.
    • Missing verification: an incorrect result was not discovered in time.
    • Recovery failure: after the problem is found, execution cannot continue safely.
    • Environment failure: external conditions do not meet the task requirements.

    Logs should also redact sensitive information and follow a minimum-necessary recording principle, so troubleshooting does not expose credentials, personal information, or business data.

    7. Where stability optimization should start

    For an agent that can already complete a task occasionally, a practical improvement order is:

    1. Define acceptance criteria so that “an operation was executed” is not mistaken for “the task is complete.”
    2. Fix the runtime environment and remove residual state and dependency drift.
    3. Add verification at critical points so deviations are found early.
    4. Improve state summaries so goals, evidence, and unfinished items remain visible.
    5. Introduce checkpoints, failure classification, and controlled retries.
    6. Optimize planning and tool interaction for high-frequency failure patterns.
    7. Use repeated-run evaluation to confirm the gain and continue watching cost.

    This order does not fit every scenario, but it follows a common principle: first make problems visible and execution controllable, then consider more complex capability improvements.

    Conclusion

    When the same agent sometimes succeeds and sometimes fails, the outcome is the combined result of capability, execution path, and environment. One success shows that the system found at least one viable path. It does not prove that the system can choose that path consistently, nor that the result meets business acceptance criteria.

    Turning occasional success into reliable delivery requires clear goals, controlled execution, state management, independent verification, safe recovery, and repeated evaluation together. The core of agent engineering is not only making a system “able to do the work,” but making it able to prove that it “did the work correctly,” and, when it does not, leaving enough evidence, limiting the damage, and exiting reliably.