AgentForge

Anomaly Detection

Automatically detect unusual agent behavior — loops, cost spikes, and unexpected patterns.

AnomalyDetector

import { AnomalyDetector } from '@ahzan-agentforge/core';

const detector = new AnomalyDetector({
  // Configuration
});

AnomalyConfig

interface AnomalyConfig {
  // Detection thresholds and rules
}

Anomaly Types

type AnomalyType = string;  // e.g., 'loop_detection', 'cost_spike', 'unusual_tool_pattern'

type AnomalySeverity = 'low' | 'medium' | 'high' | 'critical';

Anomaly

interface Anomaly {
  type: AnomalyType;
  severity: AnomalySeverity;
  message: string;
  context?: Record<string, unknown>;
}

Usage with Agents

const agent = defineAgent({
  name: 'monitored-agent',
  description: 'Agent with anomaly detection',
  tools: [myTool],
  llm,
  systemPrompt: '...',
  anomalyDetection: {
    // Enable and configure
  },
});

const result = await agent.run({ task: 'Do something' });

if (result.anomalies?.length) {
  for (const anomaly of result.anomalies) {
    console.warn(`[${anomaly.severity}] ${anomaly.type}: ${anomaly.message}`);
  }
}

Built-in Detectors

  • Loop Detection — agent calls the same tool with the same input 3+ times
  • Cost Spike — step cost significantly higher than average
  • Unusual Patterns — unexpected tool call sequences

Next Steps