Sequential Thinking Multi-Agent System

by FradSer
Verified

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Integrations

  • Supports configuration through environment variables, allowing secure storage of API keys for external services like DeepSeek and Exa.

  • Enables robust data validation for thought steps in the sequential thinking process, ensuring input integrity before processing by the agent team.

  • Leverages the Python AI/ML ecosystem for implementing the Multi-Agent System architecture, supporting advanced sequential thinking capabilities.

顺序思维多智能体系统(MAS)

English |简体中文

该项目使用基于Agno框架构建并通过MCP提供服务的**多智能体系统 (MAS)**实现了先进的顺序思维过程。它代表了从简单的状态跟踪方法到利用协调的专用智能体进行更深入的分析和问题分解的重大进展。

概述

该服务器提供了一个先进的顺序sequentialthinking工具,旨在解决复杂的问题。与前代产品不同,此版本采用了真正的多智能体系统 (MAS) 架构,其中:

  • 协调代理coordinate模式下的Team对象)管理工作流程。
  • 专门的代理(规划者、研究员、分析师、评论家、综合者)根据其定义的角色和专业知识处理特定的子任务。
  • 代理团队会主动处理、分析和综合传入的想法,而不仅仅是记录下来。
  • 该系统支持复杂的思维模式,包括修改先前的步骤和分支以探索替代路径。
  • Exa等外部工具的集成(通过研究人员代理)允许动态信息收集。
  • 强大的Pydantic验证可确保思考步骤的数据完整性。
  • 详细日志记录跟踪该过程,包括代理交互(由协调员处理)。

目标是通过利用专业角色协同工作的力量,实现比单个代理或简单状态跟踪更高的分析质量和更细致的思考过程。

与原始版本(TypeScript)的主要区别

这个 Python/Agno 实现标志着与原始 TypeScript 版本的根本转变:

特征/方面Python/Agno 版本(当前)TypeScript 版本(原始)
建筑学多代理系统(MAS) ;由一组代理主动处理。单一类状态跟踪器;简单记录/存储。
智力分布式代理逻辑;嵌入专门的代理和协调器。仅限外部法学硕士;无内部情报。
加工主动分析与综合;代理根据想法采取行动被动记录;仅仅记录想法。
框架Agno (MAS) + FastMCP (服务器) ;使用专用 MAS 库。仅限 MCP SDK
协调明确的团队协调逻辑Team处于coordinate模式)。;没有协调概念。
验证Pydantic Schema Validation ;强大的数据验证。基本类型检查;可靠性较低。
外部工具集成(通过研究员的 Exa) ;可以执行研究任务。没有任何
日志记录结构化 Python 日志记录(文件 + 控制台) ;可配置。使用 Chalk 进行控制台记录;基本。
语言与生态系统Python ;利用 Python AI/ML 生态系统。TypeScript/Node.js

本质上,该系统从一个被动的思维记录器演变为一个由人工智能代理协作团队驱动的主动思维处理器

工作原理(坐标模式)

  1. **启动:**外部 LLM 使用sequential-thinking-starter提示来定义问题并启动流程。
  2. 工具调用: LLM 使用第一个(或后续)想法调用sequentialthinking工具,根据ThoughtData模型进行构建。
  3. **验证和日志记录:**该工具接收调用,使用 Pydantic 验证输入,记录传入的想法,并通过AppContext更新历史记录/分支状态。
  4. **协调器调用:**核心思想内容(带有有关修订/分支的上下文)被传递给SequentialThinkingTeamarun方法。
  5. 协调员分析与委派: Team (充当协调员)分析输入的想法,将其分解为子任务,并将这些子任务委派给最相关的专业代理(例如,分析任务的分析师、信息需求的研究人员)。
  6. **专家执行:**委托代理使用其指令、模型和工具(如ThinkingToolsExaTools )执行其特定的子任务。
  7. **答复收集:**专家将结果返回给协调员。
  8. **综合与指导:**协调员将专家的回复综合成一份统一且连贯的论文。其中可能包含基于专家(尤其是评论员和分析员)的发现而提出的修改或分支建议。此外,协调员还会为法学硕士(LLM)学生提供下一步思路的指导。
  9. **返回值:**该工具返回一个 JSON 字符串,其中包含协调器的合成响应、状态和更新的上下文(分支、历史长度)。
  10. **迭代:**调用 LLM 使用协调员的响应和指导来制定下一个sequentialthinking工具调用,可能会根据建议触发修订或分支。

代币消耗警告

⚠️高令牌使用率:由于采用多代理系统架构,此工具比单代理替代方案或之前的 TypeScript 版本消耗更多令牌。每次sequentialthinking调用都会调用:* 协调器代理( Team本身)。* 多个专家代理(可能是规划器、研究员、分析器、评论器、合成器,具体取决于协调器的授权)。

与单智能体或状态跟踪方法相比,这种并行处理可以显著提高令牌使用率(每个思考步骤可能提高 3-6 倍或更多)。请根据实际情况制定预算和计划。此工具优先考虑**分析深度和质量,**而非令牌效率。

先决条件

  • Python 3.10+
  • 访问兼容的 LLM API(已针对agno配置)。系统现在支持:
    • **Groq:**需要GROQ_API_KEY
    • **DeepSeek:**需要DEEPSEEK_API_KEY
    • **OpenRouter:**需要OPENROUTER_API_KEY
    • 使用LLM_PROVIDER环境变量(默认为deepseek )配置所需的提供程序。
  • Exa API 密钥(如果使用研究员代理的功能)
    • EXA_API_KEY环境变量。
  • uv包管理器(推荐)或pip

MCP 服务器配置(客户端)

此服务器以标准可执行脚本的形式运行,并通过 stdio 进行通信,这与 MCP 的预期一致。具体配置方法取决于您具体的 MCP 客户端实现。有关详细信息,请参阅您的客户端文档。

env部分应包含您选择的LLM_PROVIDER的 API 密钥。

{ "mcpServers": { "mas-sequential-thinking": { "command": "uvx", "args": [ "mcp-server-mas-sequential-thinking" ], "env": { "LLM_PROVIDER": "deepseek", // Or "groq", "openrouter" // "GROQ_API_KEY": "your_groq_api_key", // Only if LLM_PROVIDER="groq" "DEEPSEEK_API_KEY": "your_deepseek_api_key", // Default provider // "OPENROUTER_API_KEY": "your_openrouter_api_key", // Only if LLM_PROVIDER="openrouter" "DEEPSEEK_BASE_URL": "your_base_url_if_needed", // Optional: If using a custom endpoint for DeepSeek "EXA_API_KEY": "your_exa_api_key" // Only if using Exa } } } }

安装和设置

  1. 克隆存储库:
    git clone git@github.com:FradSer/mcp-server-mas-sequential-thinking.git cd mcp-server-mas-sequential-thinking
  2. **设置环境变量:**在根目录中创建.env文件或导出变量:
    # --- LLM Configuration --- # Select the LLM provider: "deepseek" (default), "groq", or "openrouter" LLM_PROVIDER="deepseek" # Provide the API key for the chosen provider: # GROQ_API_KEY="your_groq_api_key" DEEPSEEK_API_KEY="your_deepseek_api_key" # OPENROUTER_API_KEY="your_openrouter_api_key" # Optional: Base URL override (e.g., for custom DeepSeek endpoints) DEEPSEEK_BASE_URL="your_base_url_if_needed" # Optional: Specify different models for Team Coordinator and Specialist Agents # Defaults are set within the code based on the provider if these are not set. # Example for Groq: # GROQ_TEAM_MODEL_ID="llama3-70b-8192" # GROQ_AGENT_MODEL_ID="llama3-8b-8192" # Example for DeepSeek: # DEEPSEEK_TEAM_MODEL_ID="deepseek-chat" # Note: `deepseek-reasoner` is not recommended as it doesn't support function calling # DEEPSEEK_AGENT_MODEL_ID="deepseek-chat" # Recommended for specialists # Example for OpenRouter: # OPENROUTER_TEAM_MODEL_ID="deepseek/deepseek-r1" # OPENROUTER_AGENT_MODEL_ID="deepseek/deepseek-chat-v3-0324" # --- External Tools --- # Required ONLY if the Researcher agent is used and needs Exa EXA_API_KEY="your_exa_api_key"
    选型注意事项:
    • TEAM_MODEL_ID由协调器(即Team对象本身)使用。此角色需要强大的推理、综合和委托能力。在这种情况下,使用更强大的模型(例如deepseek-r1claude-3-opusgpt-4-turbo )通常会更有利,即使它们速度更慢或成本更高。
    • AGENT_MODEL_ID由专业代理(规划师、研究员等)使用。这些代理负责处理更专注的子任务。您可以根据专家通常处理的任务的复杂性以及您的预算/性能要求,为他们选择速度更快或更经济高效的模型(例如deepseek-v3claude-3-sonnetllama3-70b )。
    • main.py中提供的默认设置(例如,使用 DeepSeek 时,代理使用的deepseek-reasoner )仅供参考。建议您进行实验,找到适合您具体用例的最佳平衡点。
  3. 安装依赖项:
    • 使用uv (推荐):
      # Install uv if you don't have it: # curl -LsSf [https://astral.sh/uv/install.sh](https://astral.sh/uv/install.sh) | sh # source $HOME/.cargo/env # Or restart your shell uv pip install -r requirements.txt # Or if a pyproject.toml exists with dependencies: # uv pip install .
    • 使用pip
      pip install -r requirements.txt # Or if a pyproject.toml exists with dependencies: # pip install .

用法

运行服务器脚本(假设主脚本名为main.py或根据您的文件结构命名为类似名称):

python your_main_script_name.py

服务器将启动并通过 stdio 监听请求,使sequentialthinking工具可供兼容的 MCP 客户端(如某些 LLM 或测试框架)使用。

sequentialthinking工具参数

该工具需要与ThoughtData Pydantic 模型匹配的参数:

# Simplified representation { "thought": str, # Content of the current thought/step "thoughtNumber": int, # Sequence number (>=1) "totalThoughts": int, # Estimated total steps (>=1, suggest >=5) "nextThoughtNeeded": bool, # Is another step required after this? "isRevision": bool = False, # Is this revising a previous thought? "revisesThought": Optional[int] = None, # If isRevision, which thought number? "branchFromThought": Optional[int] = None, # If branching, from which thought? "branchId": Optional[str] = None, # Unique ID for the branch "needsMoreThoughts": bool = False # Signal if estimate is too low before last step }

与工具交互(概念示例)

LLM 将与该工具进行迭代交互:

  1. **LLM:**使用sequential-thinking-starter提示来解决问题。
  2. **LLM:**使用thoughtNumber: 1调用sequentialthinking工具,初步thought (例如,“计划分析......”), totalThoughts估计, nextThoughtNeeded: True
  3. 服务器: MAS 处理想法 -> 协调员综合响应并提供指导(例如,“分析计划完成。建议接下来研究 X。尚不建议修改。”)。
  4. **LLM:**接收包含coordinatorResponse JSON 响应。
  5. **LLM:**根据coordinatorResponse制定下一个想法(例如,“使用 Exa 研究 X...”)。
  6. **LLM:**使用thoughtNumber: 2 、新的thought 、更新的totalThoughts (如果需要)、 nextThoughtNeeded: True调用sequentialthinking工具。
  7. 服务器: MAS 处理 -> 协调员综合(例如,“研究完成。研究结果表明想法 #1 的假设存在缺陷。建议:修改想法 #1...”)。
  8. **LLM:**收到回复,看到推荐。
  9. **LLM:**制定修订思路。
  10. **LLM:**使用thoughtNumber: 3 、修订thoughtisRevision: TruerevisesThought: 1nextThoughtNeeded: True调用sequentialthinking工具。
  11. ...等等,根据需要进行分支或扩展。

工具响应格式

该工具返回一个 JSON 字符串,包含以下内容:

{ "processedThoughtNumber": int, "estimatedTotalThoughts": int, "nextThoughtNeeded": bool, "coordinatorResponse": "Synthesized output from the agent team, including analysis, findings, and guidance for the next step...", "branches": ["list", "of", "branch", "ids"], "thoughtHistoryLength": int, "branchDetails": { "currentBranchId": "main | branchId", "branchOriginThought": null | int, "allBranches": {"main": count, "branchId": count, ...} }, "isRevision": bool, "revisesThought": null | int, "isBranch": bool, "status": "success | validation_error | failed", "error": "Error message if status is not success" // Optional }

日志记录

  • 日志写入~/.sequential_thinking/logs/sequential_thinking.log
  • 使用 Python 的标准logging模块。
  • 包括旋转文件处理程序(10MB 限制,5 个备份)和控制台处理程序(INFO 级别)。
  • 日志包括时间戳、级别、记录器名称和消息,包括格式化的思想表示。

发展

(如果适用,请在此处添加开发指南,例如,设置开发环境、运行测试、检查代码。)

  1. 克隆存储库。
  2. 设置虚拟环境。
  3. 安装依赖项,可能包括开发附加项:
    # Using uv uv pip install -e ".[dev]" # Using pip pip install -e ".[dev]"
  4. 运行 linters/formatters/tests。

执照

麻省理工学院

-
security - not tested
F
license - not found
-
quality - not tested

先进的 MCP 服务器使用专门的 AI 代理(规划器、研究员、分析器、评论家、合成器)协调团队实现复杂的顺序思维,深入分析问题并提供高质量的结构化推理。

  1. Overview
    1. Key Differences from Original Version (TypeScript)
      1. How it Works (Coordinate Mode)
        1. Token Consumption Warning
          1. Prerequisites
            1. MCP Server Configuration (Client-Side)
              1. Installation & Setup
                1. Usage
                  1. sequentialthinking Tool Parameters
                  2. Interacting with the Tool (Conceptual Example)
                  3. Tool Response Format
                2. Logging
                  1. Development
                    1. License
                      ID: 3i5xp9fksy