MCP Dual-Cycle Reasoner
 
一种实现模型上下文协议(MCP)的服务器 双循环元认知推理框架 对于自主代理。该工具通过智能回路检测和经验获取,赋予代理更大的自我意识和可靠性。
描述
MCP双循环推理器是一种复杂的工具,旨在增强AI代理的自主性和可靠性。通过实施双循环元认知框架,它使智能体能够监控自己的认知过程,检测何时陷入重复循环,并从过去的经验中学习以做出更好的决策。
该框架由两个主要部分组成:
- 哨兵:监视代理的操作并检测异常,如操作重复、状态不变性和进度停滞。
- 仲裁人:管理过去经验的案例库,允许代理存储和检索以前遇到的问题的解决方案。
此服务器使用TypeScript构建,并利用高性能库进行统计分析、自然语言处理和语义相似性,实现了基于熵的异常检测、基于NLI的文本分析和智能案例管理等高级功能。
主要特点
- 📊 高级统计分析:基于熵的异常检测和时间序列分析。
- 🧠 增强的基于案例的推理:基于NLI的文本分析的语义相似性匹配。
- 🎯 多策略检测:统计、基于模式和混合循环检测。
- 📈 时间序列分析:趋势检测和周期性模式识别。
- 🔧 可配置检测:特定领域的阈值和进展指标。
- 🎨 智能案例管理:质量评分、重复数据删除和基于使用率的优化。
- 🚀 高性能库:内置
simple-statistics,natural,compromise,以及拥抱脸变形金刚。
技术栈
- 语言:TypeScript
- 框架:Node.js
- 服务器:用于SSE传输的FastMCP
- NLP与机器学习:
- @huggingface/transformers:用于基于NLI的语义分析 - natural:用于情感分析和标记化 - compromise:用于自然语言处理
- 统计:
- simple-statistics:用于统计计算 - ml-matrix:用于矩阵运算
- 开发工具:
- jest:用于测试 - eslint:用于棉绒 - prettier:用于代码格式化 - zod:用于模式验证
安装
要使项目在本地运行,请执行以下步骤:
- 克隆存储库:
git clone https://github.com/cyqlelabs/mcp-dual-cycle-reasoner.git
cd mcp-dual-cycle-reasoner- 安装依赖项:
npm install- 构建项目:
npm run build用法
运行服务器
您可以在两种模式下运行服务器:
- HTTP流(默认):
npm start服务器将在端口8080上启动。
- 标准输入输出:
npm start -- --stdio与Claude Desktop一起使用
将以下内容添加到您的Claude Desktop MCP配置中:
{
"mcpServers": {
"dual-cycle-reasoner": {
"command": "npx",
"args": ["@cyqlelabs/mcp-dual-cycle-reasoner"]
}
}
}对于stdio传输,添加 --stdio 旗到 args 阵列。
可用工具
堆芯监测工具
start_monitoring
初始化对主体认知过程的元认知监控。
输入架构:
{
goal: string; // Current goal being pursued
initial_beliefs?: string[]; // Initial beliefs about the task
}process_trace_update
主要监控功能——处理来自代理的认知跟踪更新。
输入架构:
{
last_action: string; // Latest action name
current_context?: string; // Current environment context
goal: string; // Current goal being pursued
window_size?: number; // Monitoring window size (default: 10)
}返回有效载荷:
返回一个JSON对象,指示是否需要干预以及有关任何检测到的循环的详细信息。
{
"intervention_required": true,
"loop_detected": {
"detected": true,
"type": "action_repetition",
"confidence": 0.85,
"details": "Loop detected via parameter_repetition: 57% anomaly score...",
"actions_involved": ["click_submit_button"]
}
}stop_monitoring
停止元认知监控,获取会话摘要。
输入架构: {}
回路检测工具
detect_loop
使用各种策略检测代理是否卡在循环中。
输入架构:
{
current_context?: string; // Current environment context
goal: string; // Current goal being pursued
detection_method?: "statistical" | "pattern" | "hybrid"; // Detection method (default: "hybrid")
}返回有效载荷:
返回a LoopDetectionResult 对象作为JSON字符串。
{
"detected": true,
"type": "action_repetition",
"confidence": 0.85,
"details": {
"dominant_method": "parameter_repetition",
"anomaly_score": 0.57,
"actions_involved_count": 1,
"recent_actions_count": 10,
"metrics": {
"semantic_repetition": 0.6,
"parameter_repetition": 0.8
}
},
"actions_involved": ["click_submit_button"]
}configure_detection
配置循环检测参数和特定于域的进度指示器。
输入架构:
{
progress_indicators?: string[]; // default: []
min_actions_for_detection?: number; // default: 5
alternating_threshold?: number; // default: 0.5
repetition_threshold?: number; // default: 0.4
progress_threshold_adjustment?: number; // default: 0.2
semantic_intents?: string[]; // default: []
}增强体验管理
store_experience
使用增强的元数据和质量评分存储案例,以便将来进行基于案例的推理。
输入架构:
{
problem_description: string;
solution: string;
outcome: boolean;
context?: string;
difficulty_level?: "low" | "medium" | "high";
}retrieve_similar_cases
使用高级语义匹配和过滤检索类似案例。
输入架构:
{
problem_description: string;
max_results?: number; // default: 5
context_filter?: string;
difficulty_filter?: "low" | "medium" | "high";
outcome_filter?: boolean;
min_similarity?: number; // default: 0.1
}返回有效载荷:
返回一个数组 Case 对象作为JSON字符串。
[
{
"id": "case-123",
"problem_description": "Form submission button not responding to clicks",
"solution": "Ensure all required fields are filled correctly.",
"outcome": true,
"context": "registration_form",
"difficulty_level": "medium",
"similarity_metrics": {
"combined_similarity": 0.92
}
}
]系统工具
get_monitoring_status
获取当前的监控状态和统计数据。
输入架构: {}
返回有效载荷:
返回一个包含当前监控状态的JSON字符串,包括 is_monitoring, current_goal, trace_length,以及 intervention_count.
{
"is_monitoring": true,
"current_goal": "Complete user registration process on website",
"trace_length": 15,
"intervention_count": 2,
"recent_actions": [
{ "type": "click_submit_button", "timestamp": 1678886400000 },
{ "type": "click_submit_button", "timestamp": 1678886401000 }
]
}reset_engine
重置双循环发动机状态。
输入架构: {}
示例使用场景
示例使用场景
以下是一个完整的示例,展示了如何使用双循环推理机来监控自主代理并随着时间的推移积累经验:
1.初始设置和配置
// Configure detection parameters for your domain
await configure_detection({
progress_indicators: ['page_loaded', 'form_submitted', 'data_extracted'],
min_actions_for_detection: 3,
alternating_threshold: 0.6,
repetition_threshold: 0.3,
semantic_intents: [
'navigating to page',
'clicking element',
'filling form field',
'submitting form',
'validating input',
'handling popup',
'extracting data',
'waiting for response',
],
});
// Start monitoring the agent's goal
await start_monitoring({
goal: 'Complete user registration process on website',
});2.监控代理操作
// Monitor each action the agent takes
await process_trace_update({
last_action: 'click_signup_button',
current_context: 'homepage',
goal: 'Complete user registration process on website',
});
// ... agent continues actions ...
// Agent gets stuck clicking submit repeatedly
await process_trace_update({
last_action: 'click_submit_button',
current_context: 'registration_form',
goal: 'Complete user registration process on website',
});
// Returns: {
// "intervention_required": true,
// "loop_detected": {
// "detected": true,
// "type": "action_repetition",
// "confidence": 0.85,
// "details": {
// "dominant_method": "parameter_repetition",
// "anomaly_score": 0.57,
// "actions_involved_count": 1,
// "recent_actions_count": 10,
// "metrics": {
// "semantic_repetition": 0.6,
// "parameter_repetition": 0.8
// }
// },
// "actions_involved": ["click_submit_button"]
// }
// }3.存储和检索体验
// Store a successful experience
await store_experience({
problem_description: 'Email validation error blocking form submission',
solution: 'Check email format and retry with valid email address',
outcome: true,
context: 'registration_form',
difficulty_level: 'medium',
});
// When a loop is detected, retrieve similar cases for recovery
const similarCases = await retrieve_similar_cases({
problem_description: 'Form submission button not responding to clicks',
max_results: 3,
context_filter: 'registration_form',
outcome_filter: true,
});了解环路检测
时中 process_trace_update 该工具检测到潜在的循环,并返回详细信息 loop_detected 对象。了解此对象的组件可以帮助您诊断和调试代理行为。
以下是对关键指标的快速指南 details 对象:
dominant_method:触发循环检测的主要方法(例如。,semantic_repetition,state_invariance).anomaly_score:总分(0-1)表示对代理最近的行为是循环的一部分的信心。这是多种检测方法的加权平均值。actions_involved_count:最近被确定为检测循环一部分的行动数量。recent_actions_count:所分析的最近行动总数。metrics:包含不同检测方法的原始分数的对象,例如:
- semantic_repetition:语义上彼此相似的最近操作的百分比。 - parameter_repetition:语义相似动作的参数之间的相似性百分比。 - exact_repetition:最近精确操作的百分比,逐个字符重复。 - cyclical_pattern:表示存在重复动作序列的分数(0-1)。 - oscillation_pattern:分数(0-1)表示存在振荡(来回)动作。 - alternating_pattern:表示存在交替动作模式的分数(0-1)。
贡献
欢迎投稿!请阅读贡献指南,并确保在提交拉取请求之前通过所有测试。
许可证
该项目根据MIT许可证获得许可。请参阅 许可证 文件以获取详细信息。
