Why Long-Running AI Agent Tasks Diverge With the Same Model

    This article explains why long-running AI agent tasks produce diverging results even when the model, inference parameters, and prompts stay unchanged. It separates the inference core from the execution system, shows how per-step error rates compound across dozens of steps, and identifies three additional sources of degradation: context bloat, lost intermediate state, and oversized tool outputs. Five execution-system modules are then described in detail: context assembly, tool routing, state persistence, failure recovery, and final delivery. The article closes with a checklist and a layered evaluation approach for diagnosing whether divergence comes from the model or the runtime.

    Many people have run into the same puzzle: the model has not been swapped, the inference parameters have not been touched, and the input prompt is identical. The only change is that the same logic now runs in a different execution environment. Short question-and-answer exchanges look nearly identical, but once a task stretches to a dozen steps or several dozen, the output starts to diverge noticeably.

    To explain this, you need to separate two layers: the model and the execution system. The model is the inference core; it reads context and decides the next action. The execution system is the runtime around that core: it decomposes the goal, dispatches tools, organizes and writes back results, maintains state, handles exceptions, and delivers the final artifact. The shorter the task, the less visible the execution system’s value; the longer the task, the more irreplaceable it becomes.

    1. Separate the Layers: What the Inference Core and the Execution System Each Own

    Treating the two as one thing easily leads to overly crude conclusions such as “the model is weak” or “the model is strong.” A more accurate way to judge is this: with the same model and the same parameters, if results diverge, the difference most likely sits in the layer outside the core.

    The inference core has a relatively narrow job: receive the current context and output what to do next. It does not remember what step three did, and it does not judge whether the content a tool returned is trustworthy. The execution system carries the runtime responsibilities. Its main loop can be described with the following pseudocode:

    1. state = init_state(goal)
    2. while not state.done and state.step < MAX_STEPS:
    3. context = build_context(goal, state) # context assembly
    4. action = model.decide(context) # inference core
    5. result = dispatch(action, state) # tool surface and routing
    6. state = update(state, action, result) # state maintenance
    7. if result.failed:
    8. state = recover(state, result) # failure recovery
    9. final = deliver(state) # delivery target

    In this loop, only one line belongs to the model. Everything else belongs to the execution system, and the stability of long-running results is determined mainly by those other lines.

    2. Why Errors Get Amplified: The Multiplication Effect and Three Extra Losses

    A single-step task tests one judgment. A long task tests the product of dozens of judgments. Consider an example used only to show the direction: if the success probability of a single step is 95%, the probability that all twenty steps still succeed is roughly 0.95 to the 20th power, a little over thirty percent. This is not the measured success rate of any product, but it reveals a structural fact: the gap in long-running flows does not appear suddenly, it is amplified step by step. So the engineering goal is not to make each step “smarter,” but to lower the per-step failure rate and stop failures from propagating downstream.

    Beyond multiplication, long tasks are also dragged down by three kinds of loss:

    • Context bloat: as history piles up, the constraints stated at the beginning get pushed to the edges, and the model’s adherence to early requirements drops.
    • Lost intermediate state: step ten has no idea what step three produced, so it fills the gap by guessing, and errors enter here.
    • Oversized tool returns: large blocks of irrelevant content occupy the window and push the information actually needed out of the visible range.

    The model cannot solve any of these three on its own; the execution system has to handle them at the design level.

    3. Five Modules the Execution System Needs

    3.1 Context Assembly: Show the Model Only the Relevant Slice at Each Step

    The core principle is retrieval on demand rather than carrying everything along. Long-term information can be externalized into files or structured records, with only the fragment relevant to the current action injected at each step, and early constraints restated at fixed positions so they are not drowned out by history. A common engineering practice is layering: system-level constraints stay resident, task-level goals stay resident, step-level evidence is retrieved on demand, and history is kept as a compressed summary.

    3.2 Tool Surface: The Selection Mechanism Matters More Than the Number of Tools

    The more tools there are, the higher the chance of picking the wrong one. Workable strategies include: group and route tools by task domain, choosing the group first and the specific tool second; maintain clear notes on when each tool applies and when it does not; validate parameters against a schema and block obviously wrong inputs before the call; truncate and structurally extract return values so only key fields are written back into the context.

    3.3 State Maintenance: Reachable Across Steps and Across Applications

    State should be explicit and serializable, with fields such as the goal, completed steps, artifact paths, and open questions. Across applications or sessions, intermediate results can be carried by external storage (general cloud categories such as object storage, message queues, and logging services) and linked with stable reference identifiers, instead of relying on the implicit memory of the conversation history. Once state is broken, the model can only guess.

    3.4 Failure Recovery: Drifting Off Track Is Normal, Local Re-Execution Is the Point

    Long tasks inevitably drift. The difference is whether you can re-run in place afterward, whether you can redo only the step that went wrong, and whether a traceable record is left behind. A practical suggestion is to record an input summary, the action, the return, and the verdict for each step, and support resuming from a specified step; use a limited number of backoff retries for retryable errors, switch to an alternative path or a degraded plan for non-retryable ones, and set caps on steps and budget to prevent infinite loops.

    3.5 Delivery Target: It Decides Whether the Task Counts as Done

    Where the result finally lands directly affects whether the task is considered complete. Content left inside a conversation thread is hard to keep editing and iterating on; landing it as a file that can still be modified, with change notes and validation information attached, is much closer to a real deliverable. This step is the easiest to overlook, yet it is often the direct basis on which users judge success or failure.

    4. Implementation Advice and How to Validate

    When building long-running agents in cloud environments such as Baidu AI Cloud, you can treat the five modules above as a checklist and self-check them one by one: is context injected on demand, are tools grouped and routed, is state externally recoverable, does failure support local re-execution, and does the artifact land in an editable file. For validation, layered evaluation is recommended: single-step accuracy to locate the core’s capability, end-to-end completion rate to measure the execution system, plus “recovery success rate” and “average re-run steps” to observe robustness. If the end-to-end completion rate differs significantly under the same model and parameters, investigate the execution system first rather than swapping the model.