AgentGuard
AgentGuard is a zero-dependency Python library that provides hard budget caps, loop detection, and local tracing for AI agents. It solves the problem of runaway agents that burn money or get stuck in loops by raising exceptions in-process to stop bad runs mid-flight. It is for developers building and shipping AI agents who want to prevent surprise costs and ensure reliability.
✨ Key features
- Hard budget caps with BudgetGuard and BudgetExceeded exception
- Loop detection including fuzzy loops and retry storms
- Local JSONL traces by default, no network required
- Zero runtime dependencies, Python 3.9+
- Provider patches for OpenAI and Anthropic
- Optional framework hooks for LangChain, LangGraph, CrewAI
🎯 Use cases
- Prevent cost overruns in OpenAI or Anthropic agent calls
- Stop agents stuck in repetitive tool-calling loops
- Cap spending on x402/USDC micropayments per call or endpoint
- Enforce timeouts and rate limits on agent runs
- Trace agent decisions locally for debugging and audits
📦 Installation
🧰 Requirements: Python 3.9+; no API keys required for local use; optional extras for integrations.
pip install agentguard47
Optional extras:
pip install "agentguard47[langchain]" # optional extras as needed
🚀 Usage
from agentguard import BudgetGuard, LoopGuard, Tracer, patch_openai
budget = BudgetGuard(max_cost_usd=5.00, warn_at_pct=0.8)
loop = LoopGuard(max_repeats=3)
tracer = Tracer(service="my-agent", guards=[loop])
patch_openai(tracer, budget_guard=budget)
# every OpenAI call is now traced + budget-enforced
⚠️ Good to know
The base install is local and free, but the optional [crewai] extra pulls chromadb which has known vulnerabilities with no fixed release; also, the SDK does not execute remote kill signals by itself.
❓ FAQ
Does AgentGuard require an API key?
No, the local proof path requires no API key. You only need to configure a sink like HttpSink if you want hosted features.
How does AgentGuard stop a runaway agent?
It raises exceptions like BudgetExceeded or LoopDetected inside your process, which stops the run mid-flight.
Does AgentGuard send data over the network?
No, by default it writes local JSONL traces. Network egress only occurs if you configure an HttpSink or OpenTelemetry exporter.
What is the security concern with the [crewai] extra?
The [crewai] extra pulls chromadb, which has a known pre-authentication RCE vulnerability (PYSEC-2026-311) with no fixed release. You are only exposed if you run a ChromaDB server reachable by untrusted callers.
📊 Repository
🤖 Overview, features, install steps and FAQ were generated from the project's README on Sep 4, 2026. Always check the original source before running commands.