{"slug": "agentguard-zero-dependency-loop-and-spend-guardrails-for-ai-agents", "title": "AgentGuard – Zero-dependency loop and spend guardrails for AI agents", "summary": "A developer publishing as nemor1-bit released AgentGuard, a zero-dependency Python library that adds runtime guardrails to AI agents, installable via pip from its GitHub repository. AgentGuard enforces per-action spend caps (max_spend, e.g. $50), session totals (max_total_spend, e.g. $500), consecutive tool-loop limits (max_consecutive_repeats=4), a 300-second idempotency window against duplicate retries, human-approval gates for actions such as send_email and charge_card, and verify-after-act checks via verify_fn. The project also offers a $750 paid setup service and an enterprise waitlist for Redis-backed idempotency, SOC2 compliance logs and RBAC for 10,000+ agents.", "body_md": "**The zero-dependency runtime seatbelt, loop killer, and human-approval gate for AI Agents.**\n\n[https://nemor1-bit.github.io/agentguard/](https://nemor1-bit.github.io/agentguard/)\n\nAgentGuard protects production AI agents from the quiet failures that dollar caps alone miss—stopping consecutive tool loops, duplicate retries on timeouts, unverified side effects, and unapproved irreversible actions.\n\n```\npip install git+https://github.com/nemor1-bit/agentguard.git\npython\nfrom agentguard import AgentGuard\n\nguard = AgentGuard(\n    max_spend=50,                       # Max \\$50 per action\n    max_total_spend=500,                # Max \\$500 across the session\n    max_consecutive_repeats=4,          # Kill stuck loops repeating the same tool\n    idempotency_window=300,             # Block duplicate retries within 5 minutes\n    require_approval_for=[\"send_email\", \"charge_card\"],\n    approval_callback=lambda action, cost: input(f\"Approve {action}? (y/n): \") == \"y\",\n    webhook_url=\"https://slack.com\"\n)\n\n# Protect any tool with human approval + verify-after-act\n@guard.protect(\n    cost_fn=lambda user_id, amount: amount,\n    verify_fn=lambda result, user_id, amount: result.get(\"paid\") is True\n)\ndef charge_card(user_id, amount):\n    return {\"paid\": True, \"tx_id\": \"tx_991\"}\n\ncharge_card(\"usr_42\", 25)  # Pauses for human approval -> executes -> verifies effect\ncharge_card(\"usr_42\", 25)  # 🛑 Blocked automatically (duplicate action within 300s)\n```\n\n- \n**Aggregate Dollar-Velocity Caps (`max_spend_per_minute`):** Stops rapid spend bleed (e.g., ten $2 calls in 60 seconds) even when every single action is under`max_spend` .\n- \n**Strict Tool Allowlisting (`allowed_tools`):** Eliminates keyword whack-a-mole by blocking any tool not explicitly allowlisted.\n- \n**Dry-Run / Shadow Preview Mode (`dry_run=True`):** Simulates full agent workflows through every policy check and outputs a projected spend receipt (`get_dry_run_summary()` ) before committing real side effects.\n- \n**Consecutive Tool-Loop Detection (`max_consecutive_repeats`):** Halts runs when an agent calls the same tool repeatedly—even if arguments change slightly or calls are spaced out.\n- \n**Human-in-the-Loop Approval Gate (`require_approval_for`):** Pauses execution on irreversible actions (` send` ,`pay` ,`delete` ) until a human approves via callback or webhook.\n- \n**Duplicate-Action Prevention (Idempotency):** Automatically hashes`(action, args, kwargs)` to block double-charges and duplicate emails after API timeouts.\n- \n**Verify-After-Act (`verify_fn`):** Runs a lightweight post-execution check to catch silent failures when an agent reports success without the real-world effect occurring.\n- \n**Two-Phase Variable Cost Accounting:** Supports dynamic pre-flight`cost_fn` estimation plus`record_actual_cost()` post-call reconciliation.\n- \n**OpenAI Tool Validation & Alerts:** Native`guard_openai_tool_call()` , keyword kill-switches, timestamped audit logs, and Slack/Discord alerts.\n- \nNeed distributed Redis idempotency, SOC2 compliance logs, and RBAC for 10,000+ agents? [Join the Enterprise Waitlist](https://nemor1-bit.github.io/agentguard/) .\n- \nNeed hands-on help wiring AgentGuard into your production OpenAI or LangChain agents? [Book a Priority Setup & Custom Guardrails session ($750)](https://buy.stripe.com/00wbJ2ceT7yd9hA5oh3F600) .", "url": "https://wpnews.pro/news/agentguard-zero-dependency-loop-and-spend-guardrails-for-ai-agents", "canonical_source": "https://github.com/nemor1-bit/agentguard", "published_at": "2026-12-01 02:49:30+00:00", "updated_at": "2026-12-01 03:14:58.110577+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "ai-safety", "developer-tools"], "entities": ["AgentGuard", "nemor1-bit", "OpenAI", "LangChain", "GitHub", "Slack", "Discord"], "also_reported_by": [], "takeaway": "AgentGuard wraps agent tools with a @guard.protect decorator that enforces per-action and per-session spend caps, kills loops after max_consecutive_repeats identical tool calls, blocks duplicate (action, args, kwargs) retries within a 300-second idempotency window, and pauses irreversible actions fo", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/agentguard-zero-dependency-loop-and-spend-guardrails-for-ai-agents", "markdown": "https://wpnews.pro/news/agentguard-zero-dependency-loop-and-spend-guardrails-for-ai-agents.md", "text": "https://wpnews.pro/news/agentguard-zero-dependency-loop-and-spend-guardrails-for-ai-agents.txt", "jsonld": "https://wpnews.pro/news/agentguard-zero-dependency-loop-and-spend-guardrails-for-ai-agents.jsonld"}}