agentguard

A local Python library that adds runtime limits and tracing to AI coding agents. It can monitor model calls and stop repeated actions, excessive spending, retries, or long-running tasks.

In plain words
What is it for?
Use it to set cost, repetition, timeout, rate, and retry limits, while recording activity from supported OpenAI calls.
Why use it?
It helps prevent an agent from getting stuck in a loop, retrying a failing tool, exceeding a budget, or running longer than allowed.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/bmdhodl/agent47/agentguard
Any agent
npx skills add bmdhodl/agent47 --skill agentguard
Clone the repo
git clone --depth 1 https://github.com/bmdhodl/agent47

Made for: Claude Code, Codex.

Per session 38 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 922 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00038 $0.00922
Opus 5 $0.00019 $0.00461
Sonnet 5 $0.00008 $0.00184
Haiku 4.5 $0.00004 $0.00092

Measured 2d ago against content hash c2a75bd6797d, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

agentguard scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/agentguard/SKILL.md · 124 lines

How it starts

The opening of the file, as written. The whole thing — 124 lines — stays where its author put it; the contents beside it link to each section on GitHub.

AgentGuard

Runtime guardrails for coding agents. Stops loops, budget overruns, retry storms, and timeouts mid-run. Zero dependencies. Local-first.

Install

pip install agentguard47

Verify the install:

agentguard doctor

Quick Start (4 lines)

from agentguard import Tracer, BudgetGuard, patch_openai

budget = BudgetGuard(max_cost_usd=5.00, warn_at_pct=0.8)
tracer = Tracer(service="support-agent")
patch_openai(tracer, budget_guard=budget)
# OpenAI chat completions are now tracked. At $4 you get a warning. At $5 the agent stops.

Guards

Guard What it stops Example
BudgetGuard Dollar/token/call overruns BudgetGuard(max_cost_usd=5.00)
LoopGuard Exact repeated tool calls LoopGuard(max_repeats=3)
FuzzyLoopGuard Similar calls, A-B-A-B patterns FuzzyLoopGuard(max_tool_repeats=5)
TimeoutGuard Wall-clock time limits TimeoutGuard(max_seconds=300)
RateLimitGuard Calls-per-minute throttling RateLimitGuard(max_calls_per_minute=60)
RetryGuard Retry storms on flaky tools RetryGuard(max_retries=3)

Guards raise exceptions (BudgetExceeded, LoopDetected, TimeoutExceeded, RetryLimitExceeded) to kill the agent immediately.

One-Liner Init with Defaults

import agentguard

agentguard.init(local_only=True)
# Reads .agentguard.json if present, sets up tracer + budget guard with sensible defaults

Or drop a .agentguard.json in your repo root:

{
  "profile": "coding-agent",
  "service": "my-agent",
  "trace_file": ".agentguard/traces.jsonl",
  "budget_usd": 5.0
}

Tracing

from agentguard import Tracer, JsonlFileSink, BudgetGuard

tracer = Tracer(
    sink=JsonlFileSink("traces.jsonl"),
    guards=[BudgetGuard(max_cost_usd=5.00)],
)

with tracer.trace("agent.run") as span:
    span.event("reasoning", data={"thought": "search docs"})
    span.cost.add("gpt-4o", input_tokens=1200, output_tokens=450)

Read the full file on GitHub · 124 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 124 lines · 38 tokens per session scan A c2a75bd6797d

Subscribe to this mod's changes

agentguard is a skill published in the GitHub repository bmdhodl/agent47 (4 stars, last pushed 3d ago), licensed MIT. It adds 38 tokens to every session and 922 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.