learning-it by example

Back to the video

Tool Errors: Retries, Fallbacks and Made-Up Answers

My AI tool failed, and the model made up the answer. Here is how to retry and fall back inside the tool.

Video #25 ยท AI agents and MCP

Steps in the video

  1. 0:00 A tool that fails
  2. 0:26 What goes wrong
  3. 0:57 Setup
  4. 1:14 The retry function
  5. 1:39 The tool
  6. 2:04 Four cases
  7. 2:41 Retries multiply
  8. 3:15 The real model
  9. 3:58 What this does not show
  10. 4:28 Mistakes to avoid
  11. 4:51 My take and next steps
  12. 5:17 Recap

Files

  • demo.py (18 lines)
  • layers.py (21 lines)
  • real.py (37 lines)
  • retry.py (27 lines)
  • service.py (18 lines)
  • tools.py (15 lines)

Download the code (zip)

Tested with

Python 3.12.15 | ollama==0.6.3

What this does not show

One small local model, one question and one tool, one run; another model may retry or say it does not know. The weather service and its data are made up and fail on purpose. No circuit breaker, process-wide retry budget or time limit is built. Only calls that are safe to repeat should be retried.

Sources

Learning IT by Example.