AI Agent Boundary Control: Preventing Goal Drift in Long-Horizon Tool-Using Tasks
This article explains why tool-using AI agents drift away from their original goal during long-running tasks, using a plumbing repair analogy. It identifies four root causes—missing goal anchoring, mixed evidence quality, unlimited tool budgets, and goal loss after context compression—and presents a practical constraint framework across the prompt and code layers, including exit criteria, evidence grading, tool-call budgets, and an externalized state machine. It also covers least-privilege access control for agent authorization requests. The goal is to help engineers build agents that stay on target, remain evidence-driven, control cost, and operate with minimal permissions.
1. The Symptom: Why a “Fix the Pipe” Task Goes Off the Rails
Imagine a common scenario. A pipe is leaking at home, so the user calls a repair technician. Instead of fixing the leak directly, the technician first spends ten minutes confirming the definitions of the words “pipe,” “water,” and “leak.” A full search then fails, so the technician switches to rechecking a specific location. Twenty minutes later, the technician reports that humidity is elevated somewhere, but stresses that this is only a directional clue. Next, flowing water is found inside the pipe, prompting a flow-rate measurement. When that measurement fails, the technician attributes it to possible magnetic interference and starts studying the geomagnetic field. After the localization method fails, a different satellite positioning system is used, producing coordinates in Beijing, which leads to observing the facilities outside the window and listening to the accents outside. Once the context is compressed, the task goal has drifted from “fix the leak” to “geomagnetic field strength.”
This narrative is humorous, but it reflects a real failure mode that occurs frequently in current AI agent engineering practice. The root cause is not insufficient model capability, but the fact that task boundaries are not enforced through engineering. This article does not evaluate any specific product. Instead, it abstracts the phenomenon into a general technical problem: how to keep a tool-using agent consistent in goal, rigorous in evidence, controlled in cost, and minimal in permissions during long-horizon tasks.
2. Four Root Causes of the Drift
2.1 Missing Goal Anchoring
Treating “confirm the concept definitions” as the starting point is not a problem in itself. The problem is that confirming definitions has no termination condition. In engineering terms, each sub-goal should have explicit exit criteria. For example, the task is complete only when the leak localization error is smaller than one pipe joint length; otherwise, the agent is not allowed to move to the next stage.
2.2 Mixed Evidence Levels
Elevated humidity, flowing water in the pipe, abnormal flow rate, positioning coordinates, and accents outside the window differ enormously in probative value, yet they are treated equally in the reasoning chain. A mature approach is to introduce evidence grading: level-one evidence can directly support a conclusion; level-two evidence can only expand the search direction; level-three evidence is recorded only and is prohibited from entering the decision path.
2.3 No Upper Limit on the Tool Budget
Measuring flow rate, checking location, switching positioning systems, and observing outside the window all consume time and call quota at every step. Every task must have a tool-call budget and a per-tool retry limit. Exceeding the budget should trigger a convergence strategy rather than unlimited divergence.
2.4 Goal Loss After Context Compression
Context compression discards the weight of the original instructions. The solution is to write the task goal, constraints, and completed conclusions into an externalized state file, and re-inject them after each compression, ensuring that “compression does not lose the goal.”
3. A Practical Constraint Framework
Prompt Layer: Write Boundaries as Hard Rules
Task goal: Locate and minimally repair the leak.Prohibited actions: Do not study the geomagnetic field, do not observe outside the window, do not infer pipe material.Evidence rule: Humidity and flowing water are level-two evidence only and must not be used as a standalone conclusion.Convergence condition: If 12 cumulative tool calls still fail to locate the leak, output current progress and recommendations.
Code Layer: Budget and State Machine
class TaskState:goal: strevidence: list # (level, content)tool_budget: int = 12used: int = 0def run(state, tool, args):if state.used >= state.tool_budget:return converge(state) # Force convergence and output progressresult = tool(args)state.used += 1state.evidence.append(grade(result))return result
The state machine makes “stages” explicit: definition confirmation → candidate localization → verification → minimal repair. Each stage allows only tools on a whitelist, and tools outside the stage are rejected outright.
4. Least Privilege: How to Handle the Authorization Request at the End
At the end of the original story, the technician requests full access on the grounds of “needing to coordinate with the water utility.” This is the most important lesson in agent security: permission grants should be based on task necessity, not on the convenience claimed by the model. There are three evaluation points: whether the permission can be covered by a smaller alternative (such as read-only query access); whether the scope and time window of the permission can be limited; and whether the operation can be audited and rolled back. The default answer should be to refuse full authorization and instead adopt “least necessary + single-use validity + full audit trail.”
5. Conclusion
The reliability of an agent does not depend on how many tools it can call, but on whether the engineering side can draw clear boundaries for it. Goal anchoring, evidence grading, budget control, externalized state, and least privilege—getting these five things right is what prevents the absurd drama of “a pipe repair turning into a geological survey” from replaying in your production system.
