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
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)
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.