/** * Swarm Anti-Pattern Detector * * Detects repetitive failure patterns for agents before task execution. * Searches MAMA DB for past failures and provides warnings to prevent recurring issues. * * Features: * - Queries MAMA DB for agent-specific failure history (topic: swarm:{agentId}:failed) * - Detects patterns when failure count exceeds threshold (default: 2) * - Generates actionable warnings with recommendations * - Graceful fallback when MAMA DB unavailable * * @module swarm-anti-pattern-detector * @version 1.0 */ import type { MamaApiClient } from '../../gateways/context-injector.js'; /** * Anti-pattern warning structure */ export interface AntiPatternWarning { /** Agent ID that exhibited the pattern */ agentId: string; /** Pattern description */ pattern: string; /** Number of recent failures */ failureCount: number; /** Last error message (if available) */ lastError?: string; /** Recommended action to avoid repeating the failure */ recommendation: string; } /** * Configuration options for AntiPatternDetector */ export interface AntiPatternDetectorOptions { /** MamaApiClient for searching past decisions */ mamaApi: MamaApiClient; /** Minimum failure count to trigger warning (default: 2) */ minFailures?: number; /** Enable verbose logging (default: false) */ verbose?: boolean; } /** * Swarm Anti-Pattern Detector * * Analyzes past task failures to detect patterns and warn agents before execution. * Integrates with SwarmTaskRunner to inject warnings into task prompts. * * @example * ```typescript * const detector = new SwarmAntiPatternDetector({ * mamaApi: createMamaApiAdapter(), * minFailures: 2, * verbose: true * }); * * const warnings = await detector.detect('developer', 'Implement auth'); * if (warnings.length > 0) { * console.log(detector.formatWarnings(warnings)); * } * ``` */ export declare class SwarmAntiPatternDetector { private mamaApi; private options; constructor(options: AntiPatternDetectorOptions); /** * Detect anti-patterns for a given agent before task execution * * @param agentId - Agent about to execute a task * @param taskDescription - Task description for context matching * @returns Array of warnings (empty if no patterns detected) */ detect(agentId: string, taskDescription: string): Promise; /** * Format warnings into a prompt warning section * * @param warnings - Array of warnings to format * @returns Formatted warning text (empty string if no warnings) */ formatWarnings(warnings: AntiPatternWarning[]): string; /** * Check if task description is similar to a past failure context * * Simple keyword-based similarity check. * Can be enhanced with semantic similarity in the future. */ private isSimilarContext; /** * Extract keywords from text (simple tokenization) */ private extractKeywords; /** * Truncate text to max length with ellipsis */ private truncate; } //# sourceMappingURL=swarm-anti-pattern-detector.d.ts.map