v0.1.0 ยท Available on npm

Runtime Loop Detection
for AI Agents

Multi-agent systems loop indefinitely, burning tokens before anyone notices. agent-watchdog intervenes at runtime โ€” the same way a circuit breaker works in distributed systems.

Get Started Free โ†’ View on GitHub
$ npm install agent-watchdog
55% Default similarity threshold
<1ms Detection overhead per cycle
0 Tokens wasted after intervention
3 Detection signals

Multi-agent AI fails
in ways you can't see

Existing observability tools show you what happened after the fact. By then, you've already burned tokens and hit your budget ceiling.

โŸณ

Argument Loops

Two agents debate the same point in different words, indefinitely, with no exit condition.

๐Ÿ’ธ

Token Runaway

An uncapped loop burns through your entire API budget before anyone notices the graph is stuck.

โธ

Silent Deadlocks

Agents wait on each other's output and never produce a result. The graph stalls silently.

๐Ÿ“‹

Post-hoc Logs Only

LangSmith and AgentOps are powerful, but they tell you what went wrong โ€” not in time to stop it.

Four-layer runtime protection

agent-watchdog runs inside your LangGraph conditional edges โ€” no external calls, no latency budget, no data leaving your environment.

01

Message Window Sampling

Collects the last Nร—2 messages from the graph state on every cycle. Window size is configurable.

02

Jaccard Similarity Scoring

Computes average pairwise word-set overlap between the recent window and the previous window. Catches semantic repetition even when exact wording differs.

03

Threshold Evaluation

If the similarity score exceeds your configured threshold (default 55%), the watchdog signals loop_detected. If the cycle count exceeds your limit, it signals limit_reached.

04

Runtime Intervention

The router returns END before the next agent fires. Zero additional tokens consumed. An intervention report is generated for your logging pipeline.

Everything you need to ship
safe multi-agent pipelines

๐Ÿ”
CRITICAL

Loop Detection

Detects argumentative cycles using Jaccard word-set similarity across sliding message windows.

Similarity threshold ยท configurable
๐Ÿ”ข
HIGH

Iteration Limits

Hard cap on graph cycles. If the graph exceeds maxIterations, the watchdog halts regardless of similarity.

Default cap ยท 10 iterations
โš™๏ธ
CONFIG

Configurable Thresholds

Tune similarity threshold, window size, and iteration cap independently per graph or per edge.

3 tunable parameters
๐Ÿ“ก
SAFE

Intervention Callbacks

Wire onIntervene to your own logger, alerting system, or monitoring pipeline. Fully optional.

Zero deps ยท stdout fallback
๐Ÿ“„
SAFE

Intervention Reports

Human-readable diagnosis on every intervention: trigger, iteration count, similarity score, last exchanges, and recommended action.

Structured ยท machine-readable
๐Ÿ”’
SAFE

Zero External Calls

All detection runs in-process. No data leaves your environment, no API keys required for watchdog itself.

Offline ยท air-gapped friendly

Three steps to a safer graph

1

Install

Add agent-watchdog to your project. Requires @langchain/langgraph as a peer dependency.

bash
npm install agent-watchdog
2

Configure

Create a watchdog instance with your thresholds. All parameters are optional โ€” defaults work out of the box.

typescript
import { AgentWatchdog, createWatchdogRouter } from "agent-watchdog";
import { END } from "@langchain/langgraph";

const watchdog = new AgentWatchdog({
  maxIterations: 10,
  similarityThreshold: 0.55,
  windowSize: 4,
});
3

Drop into your graph

Replace any conditional edge with the watchdog router. It halts to END automatically on detection.

typescript
const router = createWatchdogRouter(watchdog, "agent_a", (report) => {
  myLogger.warn(report);
});

graph.addConditionalEdges("agent_b", router, {
  agent_a: "agent_a",
  [END]: END,
});

Intervention report

When agent-watchdog detects a loop, it halts the graph and surfaces a structured report โ€” no guesswork, no post-hoc analysis.

agent-watchdog ยท intervention report
============================================================
  AGENT WATCHDOG โ€” INTERVENTION REPORT
============================================================
  Trigger    : loop_detected
  Iterations : 8
  Similarity : 71%  (threshold: 55%)
  Messages   : 9

  Last exchange:
    [Optimist]  While AI accelerates scientific discovery, we must ensure equit...
    [Pessimist] The acceleration you describe comes at the cost of concentrating...
    [Optimist]  Equitable access is precisely why open-source AI development mat...
    [Pessimist] Open-source development doesn't solve the compute access problem...

  Diagnosis  : agents are recycling the same arguments.
  Action     : graph halted. No further tokens consumed.
============================================================

What's coming next

Planned

Deadlock Detection

Detect mutual wait patterns where agents block on each other and no output is produced.

Planned

Token Budget Monitoring

Early-warning callbacks when cumulative token usage approaches configurable budget limits.

Planned

Pluggable Similarity Backends

Swap in embeddings or TF-IDF for richer semantic loop detection beyond word-set Jaccard.

Planned

CrewAI & AutoGen Adapters

Bring agent-watchdog's protection to other multi-agent frameworks beyond LangGraph.

Start free. Scale when you need to.

The core loop detection library is and always will be open source. Pro tiers add managed monitoring, alerting, and team dashboards.

Free
$0/month

Open source. Self-hosted. Forever.

Get Started โ†’
  • โœ“ Loop detection (Jaccard similarity)
  • โœ“ Iteration limit enforcement
  • โœ“ Configurable thresholds
  • โœ“ Intervention callbacks
  • โœ“ Human-readable reports
  • โœ“ MIT license
  • โ€“ Managed monitoring
  • โ€“ Team dashboard
Personal
$15/month

For solo developers running agents in production.

Get Started โ†’
  • โœ“ Everything in Free
  • โœ“ Up to 50K actions/month
  • โœ“ Managed alert webhooks
  • โœ“ 30-day audit log
  • โœ“ Email support
  • โ€“ Team seats
  • โ€“ SLA guarantee
Pro
$499/month

For production teams with reliability SLAs.

Get Started โ†’
  • โœ“ Everything in Starter
  • โœ“ Unlimited actions
  • โœ“ Unlimited team seats
  • โœ“ 1-year audit log
  • โœ“ Pluggable similarity backends
  • โœ“ 99.9% uptime SLA
  • โœ“ Dedicated Slack support
Enterprise
Custom

SSO, on-prem deployment, and custom integrations.

Contact Us โ†’
  • โœ“ Everything in Pro
  • โœ“ On-premise deployment
  • โœ“ SSO / SAML
  • โœ“ Custom SLA
  • โœ“ Dedicated onboarding
  • โœ“ Custom similarity backends
  • โœ“ CrewAI / AutoGen adapters

Stop your agents from looping.

Drop agent-watchdog into any LangGraph graph in under 5 minutes.