MASFactory 深度解析:Vibe Graphing 如何改变多智能体系统开发范式

MASFactory 是一个图-centric 的多智能体系统(MAS)编排框架,核心创新是 Vibe Graphing —— 从自然语言意图直接生成可执行的多智能体工作流。

目录
  1. 项目概述
  2. 核心问题:多智能体编排的困境
  3. Vibe Graphing:核心创新
  4. 定义
  5. 工作流程
  6. 示例对比
  7. 四层架构设计
  8. 核心组件详解
  9. 1. Agent(智能体节点)
  10. 2. Graph(子图封装)
  11. 3. Loop(循环组件)
  12. 4. Switch(分支/路由)
  13. 5. Human(人机协作)
  14. 6. 内置复合图模式
  15. 三种开发模式对比
  16. ContextBlock:上下文协议
  17. MASFactory Visualizer
  18. 应用案例
  19. 1. NowWhat(AI 论文简报)
  20. 2. OhNoPPT(论文转 PPT)
  21. 3. 复现的经典 MAS 系统
  22. 与现有框架对比
  23. 快速开始
  24. 安装
  25. 最小示例
  26. 深层思考
  27. 1. 从"写代码"到"设计系统"
  28. 2. 图结构的普适性
  29. 3. 复用的层次
  30. 参考链接

项目概述

MASFactory 是一个图-centric 的多智能体系统(MAS)编排框架,核心创新是 Vibe Graphing —— 从自然语言意图直接生成可执行的多智能体工作流。

属性内容
全称MASFactory: A Graph-centric Framework for Orchestrating LLM-Based Multi-Agent Systems
机构北京邮电大学 GAMMA 实验室
arXiv2603.06007
GitHubhttps://github.com/BUPT-GAMMA/MASFactory
官网https://masfactory.dev
文档https://docs.masfactory.dev/
Stars222
Forks42
LicenseApache-2.0

核心问题:多智能体编排的困境

当前多智能体系统开发面临三大痛点:

痛点现状MASFactory 的解决方案
开发成本高手动编写复杂图工作流,需要学习 DSLVibe Graphing:自然语言 → 图设计 → 可执行工作流
复用性差每个项目从零组装组件化:Agent/Graph/Loop/Switch 等可复用单元
外部上下文整合难Memory/RAG/MCP 各自为政ContextBlock 协议:统一的上下文组织模型

Vibe Graphing:核心创新

定义

Vibe Graphing 是一种人机协作的意图驱动设计方法:
用自然语言表达需求 → AI 起草协作结构 → 人类修正确认 → 编译为可执行图

工作流程

Intent (自然语言意图)
    ↓
Graph Design (图设计规范,JSON/YAML)
    ↓  [可视化编辑器迭代]
Executable Graph (可执行工作流)
    ↓
Runtime Execution (运行时追踪)

示例对比

传统方式(手动编码):

# 需要手写 Node、Edge、消息传递逻辑
agent1 = Agent(...)
agent2 = Agent(...)
edge = Edge(agent1, agent2, condition=...)

Vibe Graphing(意图驱动):

用户:"我想开发一个五子棋游戏,先分析需求,然后设计架构,最后编码实现"
    ↓
MASFactory 生成:
- 需求分析 Agent → 架构设计 Agent → 编码 Agent
- 并行检查节点
- 循环直到测试通过


四层架构设计

┌─────────────────────────────────────────────────────────────────┐
│  第四层:交互层 (Interaction Layer)                               │
│  ├── Vibe Graphing (自然语言驱动)                                │
│  ├── Declarative (声明式代码)                                    │
│  ├── Imperative (命令式代码)                                     │
│  └── Visualizer (可视化拖拽)                                     │
├─────────────────────────────────────────────────────────────────┤
│  第三层:协议层 (Protocol Layer)                                  │
│  ├── Message Adapter (消息适配器)                                │
│  └── Context Adapter (上下文适配器: Memory/RAG/MCP)              │
├─────────────────────────────────────────────────────────────────┤
│  第二层:组件层 (Component Layer)                                 │
│  ├── Agent (基本执行单元)                                        │
│  ├── Graph (可嵌套子图)                                          │
│  ├── Loop (迭代直到条件满足)                                      │
│  ├── Switch (分支/动态路由)                                       │
│  ├── Human (人机协作节点)                                        │
│  ├── ComposedGraph (复合图)                                      │
│  └── NodeTemplate (节点模板)                                     │
├─────────────────────────────────────────────────────────────────┤
│  第一层:图骨架层 (Graph Skeleton Layer)                          │
│  ├── Node (节点抽象)                                             │
│  └── Edge (边抽象: 依赖、消息流)                                  │
└─────────────────────────────────────────────────────────────────┘


核心组件详解

1. Agent(智能体节点)

最基本的执行单元:

from masfactory import Agent, OpenAIModel

model = OpenAIModel(api_key="...", model_name="gpt-4o-mini")

agent = Agent(
    model=model,
    instructions="You are a problem analysis expert.",
    prompt_template="User question: {query}",
    tools=[...],  # 可选工具
    memory=...,   # 可选记忆
)

2. Graph(子图封装)

支持嵌套,实现层次化设计:

from masfactory import Graph, RootGraph

# 子图
subgraph = Graph(
    name="analysis_phase",
    nodes=[...],
    edges=[...]
)

# 主图引用子图
main_graph = RootGraph(
    nodes=[
        ("analysis", subgraph),  # 子图作为节点
        ("coding", coding_agent),
    ],
    edges=[...]
)

3. Loop(循环组件)

处理迭代任务:

from masfactory import Loop

# 循环直到测试通过
review_loop = Loop(
    name="code_review",
    body=review_graph,
    condition="exit_code == 0",  # 退出条件
    max_iterations=10
)

4. Switch(分支/路由)

动态路由消息:

from masfactory import LogicSwitch, AgentSwitch

# 基于条件分支
router = LogicSwitch(
    conditions={
        "simple": simple_agent,
        "complex": complex_agent,
    }
)

# 由模型决定路由
smart_router = AgentSwitch(
    decision_agent=routing_agent,
    targets=[agent_a, agent_b, agent_c]
)

5. Human(人机协作)

在关键步骤引入人类:

from masfactory import HumanConfirm, HumanInput, HumanReview

# 确认节点
confirm = HumanConfirm(message="是否继续执行?")

# 输入节点
input_node = HumanInput(prompt="请提供更多信息:")

# 审查节点
review = HumanReview(file_path="generated_code.py")

6. 内置复合图模式

from masfactory import InstructorAssistantGraph, BrainstormingGraph

# 教练-助手模式
instructor_workflow = InstructorAssistantGraph(
    instructor=instructor_agent,
    assistant=assistant_agent,
    iterations=3
)

# 头脑风暴模式
brainstorm = BrainstormingGraph(
    participants=[agent1, agent2, agent3],
    aggregator=summary_agent
)


三种开发模式对比

模式适用场景学习曲线灵活性
Vibe Graphing快速原型、探索性设计低中
Declarative生产级工作流、团队协作中高
Imperative复杂逻辑、自定义行为高最高
Visualizer可视化设计、调试追踪低中
关键优势:三种模式共享同一运行时,可以混用。


ContextBlock:上下文协议

统一组织多源上下文:

from masfactory import ContextBlock

context = ContextBlock(
    memory=chat_memory,           # 对话历史
    retrieval=rag_retriever,      # RAG 检索结果
    mcp=mcp_tools,                # MCP 工具结果
    custom=custom_data            # 自定义数据
)

agent = Agent(
    context=context,
    context_injection="auto"  # 自动注入到 prompt
)

支持的上下文源:

  • Memory:短期/长期记忆
  • RAG:检索增强生成
  • MCP:模型上下文协议(外部工具)
  • Custom:任意自定义数据

MASFactory Visualizer

VS Code 扩展,提供:

功能描述
Topology Preview预览图结构
Runtime Tracing运行时节点状态、消息流追踪
Human-in-the-loop在关键节点介入、编辑、确认
White-box Debugging白盒调试,定位问题
安装:
VS Code → Extensions → Search "MASFactory Visualizer" → Install


应用案例

1. NowWhat(AI 论文简报)

  • 功能:将每日 AI 论文流转化为结构化简报
  • 地址:https://what.masfactory.dev
  • 技术:多源聚合 → 智能筛选 → 摘要生成 → 优先级排序

2. OhNoPPT(论文转 PPT)

  • 功能:上传论文,自动生成可编辑的 .pptx
  • 地址:https://ppt.masfactory.dev
  • 技术:论文解析 → 内容提取 → 幻灯片设计 → 格式导出

3. 复现的经典 MAS 系统

系统路径说明
ChatDevapplications/chatdev/完整版软件开发多智能体
ChatDev Liteapplications/chatdev_lite/简化版
ChatDev VibeGraphapplications/chatdev_lite_vibegraph/Vibe Graphing 版
AgentVerseapplications/agentverse/任务求解
CAMELapplications/camel/角色扮演
MetaGPTapplications/metagpt/软件公司模拟
HuggingGPT2applications/hugggpt2/工具调用

与现有框架对比

框架类型核心特色MASFactory 差异
AutoGenCode微软出品,对话编程MASFactory 提供 Vibe Graphing 降低门槛
LangGraphCodeLangChain 生态,状态机MASFactory 图-centric 设计更纯粹
CrewAICode角色扮演,流程定义MASFactory 组件化程度更高
DifyLow-code可视化工作流MASFactory 同时支持代码和 Vibe Graphing
CozeLow-code字节跳动,插件生态MASFactory 开源,可本地部署

快速开始

安装

pip install -U masfactory

最小示例

import os
from masfactory import RootGraph, Agent, OpenAIModel, NodeTemplate

# 配置模型
model = OpenAIModel(
    api_key=os.getenv("OPENAI_API_KEY"),
    model_name="gpt-4o-mini",
)

# 创建节点模板
BaseAgent = NodeTemplate(Agent, model=model)

# 定义两阶段工作流
g = RootGraph(
    name="qa_two_stage",
    nodes=[
        ("analyze", BaseAgent(
            instructions="You are a problem analysis expert.",
            prompt_template="User question: {query}"
        )),
        ("answer", BaseAgent(
            instructions="You are a solution expert.",
            prompt_template="Question: {query}
Analysis: {analysis}"
        )),
    ],
    edges=[
        ("entry", "analyze", {"query": "User question"}),
        ("analyze", "answer", {"query": "Original question", "analysis": "Analysis result"}),
        ("answer", "exit", {"answer": "Final answer"}),
    ],
)

# 构建并执行
g.build()
out, _ = g.invoke({"query": "I want to learn Python. Where should I start?"})
print(out["answer"])


深层思考

1. 从"写代码"到"设计系统"

MASFactory 的核心哲学是将人类努力从底层连线转移到系统设计本身。

传统方式:程序员 = 布线工人(Node A → Node B → Node C) Vibe Graphing:程序员 = 系统设计师("我需要需求分析、架构设计、编码实现三个阶段")

2. 图结构的普适性

MAS 工作流天然是有向计算图:

  • 节点 = Agent/子工作流
  • 边 = 依赖关系 + 消息传递
图结构的优势:
  • 可视化直观
  • 数学上可分析(拓扑排序、关键路径)
  • 支持嵌套和复用

3. 复用的层次

层次复用单元示例
L1NodeTemplateBaseAgent(预设模型和配置)
L2SubGraphanalysis_phase(预设分析流程)
L3ComposedGraphInstructorAssistantGraph(预设协作模式)
L4Full WorkflowChatDev(完整软件开发生命周期)

参考链接

  • GitHub: https://github.com/BUPT-GAMMA/MASFactory
  • arXiv: https://arxiv.org/abs/2603.06007
  • 官网: https://masfactory.dev
  • 文档: https://docs.masfactory.dev/
  • 演示视频: https://www.youtube.com/watch?v=ANynzVfY32k
  • Vibe Graphing 解释: https://www.youtube.com/watch?v=QFlQuX_cddk
#多智能体 #MAS #VibeGraphing #工作流编排 #北京邮电大学 #GAMMA实验室

暂无表态

想参与讨论或点赞?登录后使用完整功能

讨论回复(0)

暂无回复,登录后可参与讨论
合作

智谱 GLM-5 已上线

在智谱开放平台 BigModel.cn 打造 AI 应用。新一代旗舰模型 GLM-5 在推理、代码、智能体综合能力达到开源模型 SOTA。

领取 2000万 Tokens