DevHubTools Robot Mascot
DevHubTools
Back to AI Agent Engineering
AI Agent EngineeringDifficulty: Intermediate 4 min read

Agent Guardrails: Step Limits, Timeouts, Cost Caps and Human Approval

Add the four limits every agent needs before it touches real systems: a step budget, per-call timeouts, a token/cost cap, and a human approval gate for risky tools.

By Avnish Yadav

Prerequisites: Lesson: Build a Tool-Calling AI Agent Loop in TypeScript
Published · Updated

An agent loop keeps going until the model says it's done. That's the point, and also the risk: a confused model can call the same tool fifty times, wait forever on a slow API, run up a large bill, or take an action you didn't want. In this lesson you'll add four guardrails to the loop from the previous lesson.

You'll need: the agent loop from Build a Tool-Calling AI Agent Loop in TypeScript.

STEP 1 OF 8
STEP 01

The four limits

Guardrail Stops Typical setting
Step budget endless loops a small fixed number of model turns
Timeouts a hung tool or model call seconds per call, plus a total deadline
Token/cost cap runaway spending a token budget per run
Approval gate unwanted side effects a human confirms risky tools

Pick the numbers from your own use case and logs; there's no universal right value.