rohitsalesforce132/recursive-mas

GitHub: rohitsalesforce132/recursive-mas

基于斯坦福递归多智能体系统论文的 Python 工具包,通过隐状态通信和递归精炼循环替代传统文本传递,实现更快、更省、更准的多智能体协作框架。

Stars: 0 | Forks: 0

# 递归多智能体系统 —— 实用工具包 基于斯坦福大学的 [递归多智能体系统 (arXiv:2604.25917)](https://arxiv.org/abs/2604.25917)。 ## 功能概述 传统的多智能体系统通过**文本**进行通信(有损、缓慢、昂贵)。RecursiveMAS 通过**隐状态**(丰富、快速、廉价)进行通信,并通过循环进行优化。 | 模块 | 功能 | |--------|-------------| | **RecursiveLink** | 将一个智能体的隐空间映射到另一个智能体隐空间的轻量级适配器 | | **Collaboration Loop** | 智能体进行多轮迭代,不断优化隐状态 | | **4 种智能体模式** | Pipeline、Debate、Mixture-of-Agents、Hierarchical | | **Inner-Outer Training** | 共享梯度在所有递归轮次中流经所有智能体 | | **Benchmarks** | 衡量相对于基于文本的多智能体系统在准确性、速度和 token 节省方面的表现 | | **电信 Demo** | 针对网络运营的多智能体事件响应 | ## 核心洞察 ``` Traditional MAS: Agent A → "I think the answer is X" → Agent B → "Based on X, I think Y" → Agent C Tokens: 20+ per message | Speed: Slow | Info: Lossy RecursiveMAS: Agent A → [0.23, -0.87, 0.45, ...] → Agent B → [0.91, 0.12, -0.33, ...] → Agent C Tokens: 0 during recursion | Speed: 1.2-2.4× faster | Info: Complete ``` ## 快速开始 ### 构建递归多智能体系统 ``` from recursive_mas import RecursiveMAS, Agent from linkers import MLPLinker # 定义 agents planner = Agent(name="Planner", role="Break down complex problems") researcher = Agent(name="Researcher", role="Gather and analyze information") executor = Agent(name="Executor", role="Implement solutions") # 通过 latent links 连接 linker = MLPLinker(hidden_dim=256) mas = RecursiveMAS( agents=[planner, researcher, executor], linker=linker, pattern="pipeline", # pipeline | debate | moa | hierarchical recursion_rounds=3, ) # 运行 task result = mas.solve("Diagnose why pod web-api-7d2f is crash-looping in production") print(result.answer) print(f"Rounds used: {result.rounds}") print(f"Tokens saved: {result.token_savings}%") ``` ### 电信事件响应 Demo ``` from demos import TelecomIncidentDemo demo = TelecomIncidentDemo() report = demo.run( alert="High error rate (12%) detected on API gateway in us-east-1", recursion_rounds=3, ) print(report.summary()) ``` ### 与基于文本的 MAS 进行性能基准对比 ``` from benchmarks import compare_mas results = compare_mas( task="multi_step_reasoning", methods=["text_mas", "recursive_mas"], num_tasks=100, ) # → Text MAS: 72% 准确率, 4500 tokens, 12.3s # → Recursive: 80% 准确率 (+8%), 1800 tokens (-60%), 6.1s (快 2.0×) ``` ## 4 种协作模式 ``` Pattern 1: PIPELINE (Sequential) A ──→ B ──→ C ──→ ┐ ↑ │ └──────────────────┘ (recursive loop) Pattern 2: DEBATE (Adversarial) A ←──→ B ↑ │ └───────┘ (refine through disagreement) Pattern 3: MIXTURE-OF-AGENTS (Parallel Ensemble) A ──┐ B ──┤──→ Combiner ──→ ┐ C ──┘ │ ↑──────────────────────┘ Pattern 4: HIERARCHICAL (Top-Down) Boss ──→ Worker A ──→ Worker B ──→ Worker C ↑_________________┘ ``` ## 项目结构 ``` recursive-mas/ ├── README.md ├── STAR.md ├── recursive_mas.py # Core RecursiveMAS framework ├── agents/ │ ├── base.py # Base Agent class with latent state handling │ ├── planner.py # Task decomposition agent │ ├── researcher.py # Information gathering agent │ ├── executor.py # Solution implementation agent │ └── supervisor.py # Hierarchical supervisor agent ├── linkers/ │ ├── base.py # Base RecursiveLink interface │ ├── mlp_linker.py # MLP-based latent space adapter │ └── attention_linker.py # Attention-based linker ├── patterns/ │ ├── pipeline.py # Sequential pipeline pattern │ ├── debate.py # Adversarial debate pattern │ ├── moa.py # Mixture-of-Agents pattern │ └── hierarchical.py # Boss-Workers pattern ├── demos/ │ └── telecom_demo.py # Network incident response demo ├── benchmarks/ │ ├── compare.py # Text MAS vs Recursive MAS comparison │ └── tasks.py # Benchmark task definitions ├── reports/ # Generated benchmark reports ├── .github/ │ └── copilot-instructions.md └── requirements.txt ``` ## 论文实验结果 | 指标 | 传统 MAS | RecursiveMAS | 提升 | |--------|----------------|-------------|-------------| | **准确性** | 基准线 | 平均 +8.3% | 涵盖 9 个基准测试 | | **推理速度** | 1× | 1.2×-2.4× | 更快的端到端速度 | | **Token 使用量** | 100% | 减少 34.6%-75.6% | 显著的成本节约 | 测试领域:数学、科学、医学、搜索、代码生成 ## 为什么这很重要 1. **新的扩展维度:** 不是更大的模型,也不是更多的数据——而是通过递归实现更深度的协作 2. **Latent > Text:** 文本是智能体间通信的瓶颈。神经激活携带了更多的信息 3. **通用框架:** 可直接提升任何多智能体拓扑的性能 4. **实际收益:** 同时实现更快、更便宜且更准确 ## 面试谈话要点 - “文本是智能体通信的瓶颈——隐状态传递以更低的成本保留了更多信息” - “下一个扩展维度不是更大的模型或更多的数据——而是通过递归实现更深度的协作” - “RecursiveMAS 证明了你可以同时获得准确性、速度和成本节约” - “递归循环中的共享梯度意味着智能体会协同适应——它们学会了生成同伴真正能用的隐状态” ## 研究背景 **论文:** [递归多智能体系统](https://arxiv.org/abs/2604.25917) **机构:** 斯坦福大学 (Xiyuan Yang, Jiaru Zou, James Zou + 8 人) **核心创新:** 通过 RecursiveLink 模块和内外循环训练,将递归扩展从单一模型推广到了多智能体系统。 ## 许可证 MIT
标签:AIOps, AI通信协议, DLL 劫持, Docker 部署, Latent State, LLM, Mixture-of-Agents, MLP Linker, Network Operations, NLP, PyRIT, Token节省, Unmanaged PE, 人工智能, 凭据扫描, 分布式AI, 图神经网络, 多智能体框架, 多智能体系统, 多智能体辩论, 大语言模型, 学术研究开源, 层级智能体, 故障响应, 斯坦福大学, 智能体协作, 流水线模式, 深度学习, 潜在状态通信, 用户模式Hook绕过, 电信行业应用, 网络运维, 自动化运维, 逆向工具, 递归优化, 递归多智能体