Lesson 1160 of 1455
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.
Builders · Agentic AI · ~4 min read
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
Practice this safely
Try this with a school, hobby, or family example where the stakes are low. Use the AI output as a draft you can question, not as the final answer.
- 1Ask AI to explain stopping condition in plain language, then underline anything that sounds uncertain or too broad.
- 2Give it one detail from "Giving Your AI Agent a Clear Stopping Condition (or Watch It Loop Forever)" and ask for two possible next steps plus one reason each step might be wrong.
- 3Check loop against a trusted source, teacher, adult, expert, or original document before you use it.
End-of-lesson quiz
Check what stuck
8 questions · Score saves to your progress.
Lesson help
Questions are best handled with a grown-up here.
For this age range, Tendril keeps freeform AI chat paused until parent/guardian consent and child-safe moderation are fully verified. Use the quiz, notes, and related lessons below, or ask a parent, guardian, teacher, or librarian to work through the question with you.
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.
