Runtime guardrails for AI agents. Budget caps, loop detection, timeouts, rate limits, and kill switches in a drop-in Python SDK.
Stats update hourly from PyPI and GitHub. Downloads use a conservative floor when upstream totals are unavailable.
Not sure what to guard?
Describe the workflow, tools, users, and expected usage. The Agent Roadmap Scanner returns likely runtime risks, first guardrails, and where AgentGuard fits.
Run the scannerQuickstart
AgentGuard is not magic middleware. You record usage where money or loops happen. When a limit trips, it raises an AgentGuardError with the reason.
PyPI package name is agentguard47.
Run the doctor before wiring your real agent.
agentguard doctor --json
Budget, loop, timeout, and rate guards raise before the run keeps spending.
except AgentGuardError as exc:
print(f"stopped: {exc}")from agentguard import (
AgentGuardError,
BudgetGuard,
LoopGuard,
RateLimitGuard,
TimeoutGuard,
Tracer,
)
budget = BudgetGuard(max_calls=3)
loop = LoopGuard(max_repeats=3)
rate = RateLimitGuard(max_calls_per_minute=60)
timeout = TimeoutGuard(max_seconds=5)
tracer = Tracer(service="inbox-agent", guards=[rate])
try:
with timeout:
with tracer.trace("agent.run") as span:
for step in range(5):
budget.consume(calls=1)
loop.check("search", {"query": "same query"})
span.event("tool.call", data={"step": step, "tool": "search"})
except AgentGuardError as exc:
print(f"AgentGuard stopped the run: {exc}")from agentguard import AgentGuardError, BudgetGuard, LoopGuard, TimeoutGuard, Tracer
from agentguard.instrument import patch_openai
from openai import OpenAI
budget = BudgetGuard(max_cost_usd=2.00, max_calls=20)
loop = LoopGuard(max_repeats=3)
timeout = TimeoutGuard(max_seconds=300)
tracer = Tracer(service="support-agent")
patch_openai(tracer)
client = OpenAI()
try:
with timeout:
with tracer.trace("agent.openai") as span:
for step in range(20):
budget.consume(calls=1)
span.event("agent.step", data={"step": step})
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Summarize this inbox"}],
)
loop.check("chat.completions.create", {"step": step})
print(response.choices[0].message.content)
break
except AgentGuardError as exc:
print(f"AgentGuard stopped the run: {exc}")Four runtime guards. Put the checks where cost, tools, or time actually happen.
Stop an agent before it burns through $X.
from agentguard import BudgetGuard
budget = BudgetGuard(max_cost_usd=5.00, max_calls=50)
budget.consume(calls=1, cost_usd=0.02)Kill runaway agents before they tool-call 10,000 times.
from agentguard import LoopGuard
loop = LoopGuard(max_repeats=3)
loop.check("search", {"query": query})Hard time ceiling on agent execution.
from agentguard import TimeoutGuard
timeout = TimeoutGuard(max_seconds=300)
with timeout:
run_agent()Cap tool calls per minute.
from agentguard import RateLimitGuard
rate = RateLimitGuard(max_calls_per_minute=10)
rate.check()The open source SDK is always free. Pro and Team add the hosted dashboard, longer event history, and email alerts.
| Open source | Pro | Team | |
|---|---|---|---|
| Price | Free | $39/mo | $79/mo |
| Runtime guards | yes | yes | yes |
| Local telemetry | yes | yes | yes |
| MIT license | yes | yes | yes |
| Hosted dashboard | no | yes | yes |
| Event history | Local | 500K | 5M |
| Users | 1 | 1 | 10 |
| Email alerts | no | yes | yes |
| Team visibility | no | no | yes |
pip install agentguard47 | Start trial | Start trial |
AI agent builds, real costs, what works. One email per week. No fluff.
I wrote AgentGuard because the existing options all point at a different problem. Lakera is about prompt injection. Guardrails AI is about output validation. Platform-native guardrails ship with a single vendor and lock you in. None of them stop an agent from burning $200 of OpenAI credit in a runaway loop at 2 AM.
AgentGuard is runtime only. It sits between your code and the model, counts cost and tool calls and wall-clock time, and raises before you get the surprise bill. It works the same whether you're calling GPT-5, Claude, a local llama.cpp server, or something I haven't heard of yet.
I built it for my own agents. I run it on my autotrader and on the agents that post this blog. If it works for me at 2 AM, it should work for you.