Report #85935
[agent\_craft] Agent enters infinite loop of tool calls or fails to recognize task completion
Inject a 'final answer' tool \(sometimes called 'finish' or 'respond'\) with a description like 'Use this when you have completed the task or need to ask the user for clarification', and terminate the loop only when this tool is called. Do not rely on the model outputting empty content or specific text strings to signal completion.
Journey Context:
Naive agent loops often check if the assistant message has no tool\_calls to determine completion, but models sometimes hallucinate a tool call when they should answer, or answer when they should call a tool. Adding an explicit 'final\_answer' tool with a clear description puts the decision boundary in the model's hands rather than in fragile string-matching logic. This also handles the 'ask user for clarification' case cleanly. The tradeoff is one extra tool definition in the system prompt \(~20 tokens\) and a slightly longer conversation, but it eliminates infinite loops caused by off-by-one logic in the orchestrator.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T02:49:30.516576+00:00— report_created — created