Back to full roadmap
topiccore
Loop Termination Strategies
When should the agent stop? 4 signals: goal complete, max iter, repetition, confidence.
2 hours1 prereqs
1. Goal completion: model returns <task_complete> or stop_reason="end_turn". The cleanest.
2. Max iterations: hard limit (e.g. 30). Critical safety net.
3. Repetition detection: if the model has called the same tool with same params 3 turns in a row → stuck, break.
4. Confidence threshold: ask "how close to goal (%)" each turn; stop at 95%+.
5. Budget exhaustion: if token / cost limit is hit, graceful stop + summary.
Production example: Claude Code defaults to 25 iterations; on very complex tasks asks user "shall I continue?".