Observed since 20 Oct, 22:06 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Detect loops and wasted calls in AI agents
Stop your agents from silently burning API credits.
AgentGuard is a lightweight runtime guard that detects loops, tracks repeated calls, and shows how many tokens your agent is wasting — in real time.
pip install agentguard-kit
LLM agents don't fail loudly.
They do this instead:
search("python error")
→ read_file("log.txt")
→ search("python error")
→ read_file("log.txt")
→ search("python error")
No crash. No exception. Just silent repetition… and a growing API bill.
Wrap your tools. Run your agent. Let AgentGuard track what's actually happening.
from agentguard import Guard
from agentguard.decorators import track
g = Guard()
g.start()
@track
def search(query):
return f"results for {query}"
for step in ["a", "b", "a", "b"]:
search(step)
print(g.report())
Example output:
AgentGuard Report
Verdict: BAD (Loop Detected)
Reason: Repeating step pattern detected
Severity: High
Confidence: 0.90
---
Total Calls: 4
Wasted Calls: 2
Waste Ratio: 50%
---
Signals:
- Loop Detected: Yes
- High Waste: No
---
Token Usage:
Total Tokens: 200
Wasted Tokens: 100
Token Waste: 50%
---
Suggestions:
- Possible infinite loop detected — verify stopping conditions
- Check repeated tool inputs
- Add guard conditions.
AgentGuard detects repeated and looping behavior based on execution patterns.
However, not all repetition is a bug.
Valid cases include:
AgentGuard does NOT assume intent.
It highlights high-level inefficiency signals — you decide whether to act.
AgentGuard works in two modes:
Automatic (no setup):
search("hello")
Uses a deterministic estimate:
tokens ≈ len(payload) // 4
Explicit (recommended):
search("hello", tokens=120)
Uses real token usage from your LLM provider.
Example 1 — Autopilot Loop (no tokens passed):
from agentguard import Guard
from agentguard.decorators import track
g = Guard()
g.start()
@track
def fallback_search(query):
return f"retrying {query}"
for _ in range(3):
fallback_search("python error")
print(g.report())
Example 2 — OpenAI Integration (real tokens):
from agentguard import Guard
from agentguard.decorators import track
from openai import OpenAI
client = OpenAI()
g = Guard()
g.start()
@track
def ask_llm(prompt, tokens=None):
return prompt
def call_llm(prompt):
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": prompt}]
)
total_tokens = response.usage.total_tokens
return ask_llm(prompt, tokens=total_tokens)
call_llm("Explain python loops")
call_llm("Explain python loops")
call_llm("Explain python loops")
print(g.report())
Because your agent might be:
AgentGuard makes that failure visible.
pip install agentguard-kit
g = Guard()
g.start()
@track
def tool(x):
return x
tool("a")
tool("a")
print(g.decision())
print(g.suggest())
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.2.0 | 9 Aug 2026 | 0 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 22:06 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:f0d7834e264a2165cb888b7e2568a2d4eb5635648eb6e0143186502236437ed6