@cyqlelabs/mcp-dual-cycle-reasoner
Version:
MCP server implementing dual-cycle metacognitive reasoning framework for autonomous agents
86 lines (85 loc) • 2.82 kB
TypeScript
import { CognitiveTrace, LoopDetectionResult, Case, SentinelConfig } from './types.js';
/**
* The Dual-Cycle Engine implements the metacognitive framework described in the DUAL-CYCLE document.
* It consists of two interconnected cycles:
* - Cognitive Cycle (The "Doer"): Direct interaction with the environment
* - Metacognitive Cycle (The "Thinker"): Monitors and controls the cognitive cycle
*/
export declare class DualCycleEngine {
private sentinel;
private adjudicator;
private currentTrace;
private isMonitoring;
private interventionCount;
private accumulatedActions;
constructor(config?: Partial<SentinelConfig>);
/**
* Initialize the semantic analyzer if not already done
*/
ensureSemanticAnalyzerReady(): Promise<void>;
/**
* Initialize a new cognitive trace for monitoring
*/
private initializeTrace;
/**
* Start metacognitive monitoring of an agent's cognitive trace
*/
startMonitoring(initialGoal: string, initialBeliefs?: string[]): Promise<void>;
/**
* Stop metacognitive monitoring
*/
stopMonitoring(): void;
/**
* Process a new cognitive trace update with a single action (called by the cognitive cycle)
*/
processTraceUpdate(lastAction: string, currentContext?: string, goal?: string, windowSize?: number): Promise<{
intervention_required: boolean;
loop_detected?: LoopDetectionResult;
explanation?: string;
}>;
/**
* Get current trace for standalone loop detection
*/
getCurrentTrace(): CognitiveTrace;
/**
* Get enriched trace with accumulated actions for internal use
*/
private getEnrichedTrace;
/**
* Get enriched trace with accumulated actions (public method for standalone tools)
*/
getEnrichedCurrentTrace(): CognitiveTrace & {
recent_actions: string[];
};
/**
* METACOGNITIVE CYCLE - Phase 1: MONITOR
* Uses the Sentinel to detect problematic patterns
*/
private monitorForLoops;
/**
* Generate a human-readable explanation of the intervention
*/
private generateInterventionExplanation;
/**
* Get current monitoring status and statistics
*/
getMonitoringStatus(): {
is_monitoring: boolean;
intervention_count: number;
current_goal: string;
trace_length: number;
};
/**
* Reset the engine state (useful for testing or new sessions)
*/
reset(): void;
/**
* Get similar cases for analysis
*/
getSimilarCases(problemDescription: string, maxResults?: number, filters?: {
context_filter?: string;
difficulty_filter?: 'low' | 'medium' | 'high';
outcome_filter?: boolean;
min_similarity?: number;
}): Promise<Case[]>;
}