Thuta Learning
ProjectsAIbeginner

Stop Conditions and Retries

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Understand stop conditions and retries — no need to be intimidated by it
  • Get hands-on practice testing it yourself
  • Learn to sidestep permission issues, secrets, and guesswork without breaking a sweat

A good agent isn't one that just keeps going. It's one that knows when to stop, and when it's worth retrying just once.

Let's think about this for a second

Set three stop conditions. Success — the output matches the expected shape. Safe failure — a missing file, something not allowed, or genuine uncertainty. Limit — max steps or timeout reached. Only retry when the error is transient. Calling a missing-file lookup five more times gets you nowhere. When you retry, change the argument — retrying with the exact same call just turns into a loop.

Let's connect this to everyday life

Study Helper's rules — stop once it's found the file and pulled out 3 facts. If a file's missing, call list_notes one more time; if it still can't find it, stop. On a tool timeout, retry once. Once 5 steps are used up, say "not done yet — a human needs to take over." Show the user progress along the way — a spinner that just sits there frozen kills trust.

Let's try it out together

javascript
const MAX_STEPS = 5;

function shouldStop({ steps, done, missing, unsure }) {
  if (done) return "success";
  if (missing || unsure) return "safe-failure";
  if (steps >= MAX_STEPS) return "limit";
  return "continue";
}
You should see
You'll be able to explain three stop rules for an agent.

5-minute try

Write a stop table for your own agent. For each of success / missing file / unsure / timeout / max steps, note exactly what it should say.

A quick word of caution

Never connect an agent with no limits to the internet. It can rack up costs and fire off requests you never expected.

Easy traps

  • Staying silent about an error
  • Calling the exact same tool over and over with no end in sight

Now try it yourself

Write a stop table for your own agent. For each of success / missing file / unsure / timeout / max steps, note exactly what it should say.

You'll know it worked when: You'll be able to explain three stop rules for an agent.

Stop Conditions and Retries | Thuta Learning