智能体
dev.to ·
@Interro
如何阻止 AI Agent 无限循环
文章复盘 INC-001:goal 工具被全局暴露而非限定在拥有目标状态的节点,导致每个模型节点反复请求同一未完成目标,单次规划请求触发 105 次调用。建议为工具指定归属节点、设置最大轮次与单工具调用上限、检测无进展转换,并用小请求测试真实规划到执行路径。
AI推荐理由 以真实事故 INC-001 为例,说明 goal 工具全局暴露导致 105 次重复调用与 token 浪费,并给出工具归属节点、最大轮次、无进展检测等具体控制措施,对 Agent 开发者有直接参考价值。
60
正文
A simple planning request triggered 105 calls to the same goal tool. The system did not crash immediately. It kept spending tokens until the turn limit stopped it, without producing a useful answer.
This was INC-001: goal tools were exposed globally instead of being scoped to the node that owned goal state. Every model node could ask for the same incomplete goal, so the graph kept returning to the same decision.
Controls that matter
Give each tool an explicit owning node.
Add maximum turns and per-tool call limits.
Detect no-progress transitions.
Test the real plan-to-execute route with a small request.
A configuration value is not a guard unless the live loop reads and enforces it. The regression test should assert that a 4+4 request terminates and that planning nodes cannot call goal-state tools.
PreventAI can flag source patterns associated with this incident:
prevention-scanner scan . --format json
Enter fullscreen mode
Exit fullscreen mode
The scanner is heuristic. Pair it with graph, load, and termination tests.
Read the full INC-001 incident, then audit which node owns every tool in your agent.