Lesson 1240 of 1570
Giving Your AI Agent a Clear Stopping Condition (or Watch It Loop Forever)
Without a 'done when X' rule, agents loop until they hit the token limit. Always set the exit.
Lesson map
What this lesson covers
Learning path
The main moves in order
- 1The big idea
- 2stopping condition
- 3loop
- 4budget
Concept cluster
Terms to connect while reading
Section 1
The big idea
An agent without a stopping condition is just an expensive infinite loop. Decide upfront: how many steps, what counts as 'done', and what happens if it can't finish.
Some examples
- You set max_steps=10 in a research agent so it can't keep googling forever.
- Claude is told 'stop when the file passes the test suite' and it knows when to quit.
- An agent has a token budget of 50k and gracefully summarizes what it found when it runs out.
- ChatGPT given 'stop when you see a 200 response' exits as soon as the API call succeeds.
Try it!
Add a max_steps and a 'done when' condition to any agent loop you've written. Test that both actually trigger.
Key terms in this lesson
End-of-lesson quiz
Check what stuck
15 questions · Score saves to your progress.
Tutor
Curious about “Giving Your AI Agent a Clear Stopping Condition (or Watch It Loop Forever)”?
Ask anything about this lesson. I’ll answer using just what you’re reading — short, friendly, grounded.
Progress saved locally in this browser. Sign in to sync across devices.
Related lessons
Keep going
Builders · 40 min
AI Agent: Plan Prom Without the Stress, Part 2
An AI agent that handles outfit, group, dinner, and afterparty in one go.
Builders · 7 min
Building an Agent That Watches Its Own Token Bill
Add a budget so the agent stops before it spends $50.
Builders · 7 min
When agents get stuck in loops (and how to stop them)
Runaway loops eat your wallet — set hard limits before you press run.
