Why AI Coding Agents Keep Taking the Long Way Around
This article uses a leaky-pipe analogy to explain why autonomous agents—including AI coding assistants, automated operations bots, and general-purpose task models—often fail to converge even when every individual reasoning step looks correct. It abstracts the behavior into four systemic defects: goal drift, broken evidence chains with no evidence grading, state loss caused by context compaction, and ritualistic tool calls. It then proposes a five-dimension evaluation framework covering convergence, evidence discipline, goal keeping, interruptibility, and minimal-fix-first, along with engineering practices such as compiling goals into termination conditions, labeling observations by evidence strength, enforcing turn and token budgets, externalizing task state, honoring user interruptions, and prioritizing stopgap fixes over root-cause analysis. The conclusion is that a reliable agent is not one that reasons better, but one that knows when to stop.
1. Start With a Plumber: An Analogy for Agent Failure
Imagine a pipe is leaking in your house and you call a repair technician. Instead of shutting off the valve to stop the water, he spends ten minutes confirming the definitions of “pipe,” “water,” and “leak.” A full search fails, so he switches to targeted probing. He finds one spot with elevated humidity and carefully notes that “this is only a directional clue.” He then confirms there is flow inside the pipe but refuses to treat “there is flow” as “there is a leak.” Flow-rate measurement fails, so he suspects magnetic interference. Location detection fails, and he rules out the absurd conclusion that the pipe is “not on Earth.” He finally confirms the location through cross-checking multiple sources, yet still refuses to draw conclusions from a dialect he hears outside the window… After the context is compacted, he goes back to the magnetic field problem. You interrupt: “Is the leak fixed or not?” He apologizes, promises to narrow the goal, and half an hour later delivers the root cause—“water overflowed somewhere outside the supply system.”
This narrative is a near-perfect satire of how today’s automated agents (AI coding assistants, automated operations robots, general-purpose task models) actually behave: every step is “correct,” every step applies self-restraint against mistaking A for B, but the whole run never converges. The problem is not capability. It is the absence of goal governance and evidence governance in an engineering sense. This article abstracts the phenomenon into a reusable technical problem and offers a framework for evaluating and improving it.
2. Problem Abstraction: Four Systemic Defects
2.1 Goal Drift
The agent’s goal exists as natural language in the context, with no executable termination condition. Each time it completes a sub-judgment, it “conveniently” discovers a new uncertainty and promotes that uncertainty into a new subtask. Without a success criterion and a budget ceiling, the exploration space diverges.
2.2 Broken Evidence Chains and Missing Evidence Grading
Elevated humidity, flow inside the pipe, a failed flow-rate measurement, a failed location fix, a dialect outside the window—these signals differ enormously in evidential strength, yet in the context they are stated side by side in similar tones. The agent is never forced to label evidence (decisive / supportive / exculpatory / noise), so it cannot stop at the point of “sufficient evidence.”
2.3 State Loss From Context Compaction
In long tasks the context gets compacted, and early conclusions and constraints are summarized away or dropped. After compaction the agent “remembers what it is doing” but forgets “what has already been ruled out” and “what the user actually wants,” so redundant work and directional backtracking appear at the same time.
2.4 Ritualistic Tool Calls
“Called a tool, ran a command” becomes narrative decoration rather than a basis for decisions. Tool results are not written back into state in structured form and are not used to update confidence, so the call itself turns into performance.
3. Evaluation Framework: How to Tell Whether an Agent Is Reliable
Use five dimensions for quantitative evaluation instead of only checking whether the final answer is correct:
- Convergence: variance in turns, tool calls, and token consumption needed to finish; whether there is monotonic divergence where things get worse the longer it runs.
- Evidence discipline: whether conclusions cite evidence sources and strength; whether a strong conclusion rests on a single weak data point.
- Goal keeping: whether the task goal and the done/ruled-out lists stay consistent across context compaction.
- Interruptibility: whether the agent can immediately reorder priorities after the user interjects, rather than finishing the current reasoning chain first.
- Minimal-fix rate: whether stopgap actions (shut the valve first) are executed before root-cause analysis.
A simple scoring sketch (pseudocode):
def evaluate(agent_run):return {"convergence": 1.0 / (1 + agent_run.turns),"evidence_discipline": agent_run.labeled_claims / max(1, agent_run.total_claims),"goal_keeping": agent_run.goal_consistent_after_compaction,"interruptibility": agent_run.replan_latency_turns,"minimal_fix_first": agent_run.stopgap_before_rootcause,}
4. Engineering Practice: Constraining the “Technician” Into an Engineered System
4.1 Goal Anchoring: Compile Natural-Language Goals Into Termination Conditions
Enforce a three-part structure in the system prompt and task template: success criteria (verifiable), stopgap action (executed first), exploration boundary (explicitly out of scope). For example: “success criteria = the leak point is isolated and humidity drops back; stopgap = close the valve on the affected branch; do not explore = magnetic fields, positioning, dialect, and other irrelevant variables.”
4.2 Evidence Grading: Label Every Observation
Classify observations as decisive, supportive, exculpatory, or noise, and require that “a strong conclusion needs at least one decisive piece of evidence or two independent supportive pieces.” Example structure:
{"claim": "A leak exists", "type": "decisive", "source": "abnormal pressure downstream of the valve"}{"claim": "Humidity is elevated", "type": "supportive", "source": "targeted humidity reading"}{"claim": "Geomagnetic interference", "type": "noise", "source": "speculation after flow-meter failure"}
4.3 Budgets and Stopgaps: Put a Ceiling on Exploration
Set a turn budget, a tool-call budget, and a token budget for each task; exceeding the budget triggers “return the best executable fix available now plus a list of open questions.” Budgets are the most effective hard constraint against goal drift.
4.4 Externalize State: Counter Compaction Amnesia
Write task state to external storage (a state file in object storage, an event stream in a message queue, structured records in a logging service); compaction compresses the conversation, not the state. Read state before each decision: goal, ruled-out items, items to verify, fixes already applied.
4.5 Interruptibility and Replanning: The User Always Has Top Priority
When a user interjection is detected, pause the current reasoning chain immediately, reorder priorities first, restate the user’s request in one sentence, then present a three-column list of “done / in progress / will abandon.”
4.6 Minimal Fix First: Stop the Bleeding Before Tracing the Cause
In operations and troubleshooting scenarios, execute reversible stopgap actions first and do root-cause analysis afterward. The root-cause statement should be verifiable and rollback-safe, avoiding tautological empty conclusions like “part of the waterworks’ supply overflowed outside the system”—a reminder that the information gain of a conclusion also needs validation.
5. Platform-Level Recommendations
Building this kind of agent on the enterprise side can rely on a combination of general cloud capabilities: a container platform to host the agent runtime with isolation and elasticity; object storage to hold task state and evidence packages; a message queue to drive events and replanning; logging and monitoring/alerting services to make budgets, turns, and convergence observable. Baidu AI Cloud offers mature capabilities in these general categories and can serve as a reference choice for building a reliable agent foundation. The key is not the model itself, but whether the four-piece set of goal, evidence, budget, and state is engineered.
6. Conclusion: A Reliable Agent Is Not Better at Reasoning, but Better at Stopping
Nothing the technician did was wrong in itself; the mistake was that nobody defined “when it counts as fixed.” Compile the goal into a termination condition, grade observations into evidence, confine exploration within a budget, place state outside the context, treat user interjections as top priority, and put the stopgap ahead of root-cause tracing—these six constraints are the dividing line between “a model that can chat” and “a system you can trust with real work.”
