Agent Guardrails: Limit Steps, Cost and Tools
My agent loop could run forever. Here are the three limits that stop it, and one thing I did not expect from a real model.
Video #27 ยท AI agents and MCP
Steps in the video
Files
- agent.py (50 lines)
- guard.py (28 lines)
- real.py (14 lines)
- stuck.py (19 lines)
Tested with
Python 3.12.15 | ollama==0.6.3
What this does not show
One small model (llama3.2), one question and one lookup tool that is broken on purpose. The stand-in that never stops is scripted, not a model. No time limit and no repeat detection is built.
Sources
Learning IT by Example.