# agent-loop-guardian-pro

> The free Agent Loop Guardian teaches your agent to recognize when it's repeating itself and break out.

agent-loop-guardian-pro is a paid AI agent skill on Agensi by Timoranjes, in DevOps & Cloud. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $5 (one-time purchase)
- Creator: [Timoranjes](https://www.agensi.io/creators/zicheng-liao)
- Category: [DevOps & Cloud](https://www.agensi.io/skills/devops-cloud)
- Version: 1.0
- Last updated: 2026-10-30
- Security: scan passed (2026-08-22); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/agent-loop-guardian-pro
- Tags: agent-reliability, loop-detection, observability, prometheus, monitoring, cost-control, dev-workflow, claude-code

## About this skill

### The free version makes your agent notice it's looping. The Pro version detects loops from OUTSIDE the agent, enforces token budgets, exports metrics to Grafana, and auto-remediates with a decision tree.

### Free vs Pro

The free guardian gives the agent in-context instincts to notice its own loops. **Pro enforces from outside**: a standalone watchdog CLI that reads live transcripts, per-project configurable thresholds, Prometheus metrics for Grafana, hard token/cost budgets with a kill switch, and an auto-remediation decision tree. Free asks the agent to self-police — Pro polices the agent.

### Upgrade Path

Free for interactive sessions; Pro for overnight batch runs, CI agents, or any workload where a loop burns real money while you sleep.

### The Problem
The free Agent Loop Guardian teaches your agent to recognize when it's repeating itself and break out. But the agent is the one with the problem — asking it to self-diagnose a loop is like asking a drunk driver to pull over. You need external detection (a watchdog that watches the transcript), enforceable budgets (hard token/cost caps that actually terminate runaway tasks), observability (metrics you can alert on), and a mechanical remediation process (not "hope the agent figures it out"). The Pro version turns loop protection from an in-context suggestion into a production-grade system.

### What You Get
- **Standalone watchdog CLI** — scans live agent transcripts and command logs for loop signatures from outside the agent, catching loops even when the agent's own reasoning misses them.
- **Configurable thresholds** — every detection rule is tunable per project via YAML config (edit count, tool call count, outcome similarity tolerance, backoff caps), instead of hard-coded counts.
- **Fuzzy similarity detection** — catches near-identical repeats (same command with changed counter or flag) via token-based Jaccard similarity, not just exact hashes.
- **Prometheus metrics export** — `loop_detections_total`, `loop_tokens_wasted_estimate`, `loop_duration_seconds`, `budget_remaining_tokens` in standard text format for Grafana dashboards.
- **Budget enforcement** — hard token and cost caps per task with a cost-aware kill switch that terminates work before a runaway loop exceeds its allowance.
- **Auto-remediation playbook** — structured decision tree (checkpoint restore → cache clear → dependency rebuild → handoff) that the agent or orchestrator runs mechanically.

### Why This Beats Prompting It Yourself
The free version asks the agent to notice it's looping. The agent has to be not-looping in order to notice it's looping — a contradiction. This Pro version runs an external watchdog that reads the transcript independently, so loops are caught even when the agent's reasoning is compromised. The budget enforcement is mechanical (hard kill switch), not advisory ("please stop"). The Prometheus metrics let you alert on loop rates across agent fleets, not just individual sessions.

### Example Session

**You:** "Run the watchdog on our overnight batch migration. It's processing 500 repos and I want to catch loops before they burn through our API budget."

**Agent:**

```bash
python3 scripts/loop_watchdog.py watch --log /var/log/batch-migration.log \
  --config config/loop-guardian.yaml --budget-tokens 500000 --budget-cost $50

```

```
WATCHDOG REPORT — batch-migration.log
Duration: 3h 12m | Repos processed: 387/500 | Loops detected: 2

LOOP #1 — Edit oscillation (repo: acme-api)
  Detected at: 2026-09-21 02:14:33
  Pattern: src/config.ts lines 45-62 edited 7 times in 4 minutes
  Similarity: 0.89 (fuzzy — line numbers shift each iteration)
  Action: Checkpoint restored to pre-loop state, task reassigned to fresh session
  Tokens saved: ~12,400 | Duration: 4m 12s

LOOP #2 — Tool call repetition (repo: widget-factory)
  Detected at: 2026-09-21 03:47:11
  Pattern: git diff → npm test → npm test → npm test (3 identical calls)
  Similarity: 0.95
  Action: Cache cleared, dependency rebuild triggered, task resumed
  Tokens saved: ~3,200 | Duration: 1m 45s

BUDGET STATUS
  Tokens used: 387,200 / 500,000 (77.4%)
  Cost used: $31.80 / $50.00 (63.6%)
  Projected completion: repo 471/500 (29 remaining)
  Budget risk: LOW — sufficient headroom

PROMETHEUS METRICS EXPORTED
  loop_detections_total 2
  loop_tokens_wasted_estimate 15600
  loop_duration_seconds 357
  budget_remaining_tokens 112800
  budget_remaining_cost 18.20
```

### Use Cases
- Monitoring overnight batch agent jobs (migrations, bulk refactors, CI pipelines with agent steps).
- Fleet-level observability: dashboard showing loop rates, token waste, and budget consumption across all agent sessions.
- CI/CD integration: watchdog as a step that fails the build if agent loops are detected.
- Cost control for API-billed agent workflows with hard budget caps.
- Post-incident analysis: review loop history to write prevention rules for future tasks.

### Known Limitations
The watchdog CLI reads transcript/log files — it requires structured logging from the agent (not all agents output parseable transcripts). Fuzzy similarity detection uses Jaccard similarity with a configurable threshold; very short commands may produce false positives. Prometheus metrics are in text format; Prometheus server setup is required for dashboards. Budget enforcement terminates the task abruptly — ensure critical writes are checkpointed before starting budgeted work.

## Requires

- Python

## Known limitations

Requires structured logging from agent. Fuzzy detection uses Jaccard similarity; short commands may false-positive. Budget enforcement terminates abruptly — checkpoint critical writes first.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the agent-loop-guardian-pro skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### What specific problems does agent-loop-guardian-pro solve for large-scale agent deployments?

It prevents runaway agent loops that waste tokens and time by monitoring execution patterns and enforcing cost-aware kill switches, saving platform engineers from unexpected API bills and hung processes.

### How does the Pro version differ from the standard agent-loop-guardian?

The Pro version adds a standalone watchdog CLI for external monitoring, configurable per-project thresholds, Prometheus/Grafana export for fleet-wide observability, and auto-remediation playbooks for CI/CD.

### Can I use this with agents that don't have built-in hook points for monitoring?

Yes, the included watchdog CLI operates independently by analyzing live transcript logs, making it compatible with popular tools like Claude Code, Cursor, and custom orchestration frameworks.

### What is the installation process for the standalone watchdog CLI?

Setup involves installing the CLI and configuring your `guardian-config.yaml` to define your token budgets and Prometheus endpoints for real-time metrics tracking.

### What exactly is included in the purchase of this skill?

Buyers receive the full CLI binary, integration middleware for major agent frameworks, pre-built Grafana dashboard templates, and access to all future v1.x updates.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
