learning-it by example

Back to the video

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

  1. 0:00 A loop with no brakes
  2. 0:32 What a guardrail is
  3. 1:04 Setup
  4. 1:23 The guard
  5. 1:48 The loop
  6. 2:09 A stand in that never stops
  7. 2:56 The real model
  8. 3:38 What this does not show
  9. 4:25 Mistakes to avoid
  10. 4:53 My take and next steps
  11. 5:14 Recap

Files

  • agent.py (50 lines)
  • guard.py (28 lines)
  • real.py (14 lines)
  • stuck.py (19 lines)

Download the code (zip)

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.