Skip to content

MetaGPT:多智能体协作框架

MetaGPT Logo

概述

MetaGPT 是一个专为自动化软件开发设计的多智能体框架,它模拟完整的软件开发团队——产品经理、架构师、项目经理、工程师——作为协调的 AI 智能体,遵循标准化的工程工作流程。

核心哲学Code = SOP(Team)

MetaGPT 将 SOP(标准操作流程)具象化,并应用于由 LLM 构成的团队。

主要特点

一行需求,完整输出

MetaGPT 接收一句话的需求作为输入,输出完整的软件开发产物:

  • 用户故事(User Stories)
  • 竞品分析(Competitive Analysis)
  • 需求文档(Requirements)
  • 数据结构设计(Data Structures)
  • API 设计(APIs)
  • 代码实现(Code)
  • 测试用例(Tests)

软件公司模拟

Software Company Structure

MetaGPT 内部包含多个专业角色:

角色职责
Product Manager分析需求,撰写用户故事和竞品分析
Architect设计系统架构,定义 API 和数据结构
Project Manager分解任务,制定项目计划
Engineer实现代码,编写功能模块
QA Engineer编写测试用例,执行质量保证
Data Analyst数据分析和可视化

快速开始

安装

bash
# 确保 Python 3.9-3.11
pip install --upgrade metagpt

# 初始化配置
metagpt --init-config

配置

编辑 ~/.metagpt/config2.yaml

yaml
llm:
  api_type: "openai"
  model: "gpt-4-turbo"
  base_url: "https://api.openai.com/v1"
  api_key: "YOUR_API_KEY"

使用

CLI 方式

bash
metagpt "Create a 2048 game"

Python 库方式

python
from metagpt.software_company import generate_repo
from metagpt.utils.project_repo import ProjectRepo

repo: ProjectRepo = generate_repo("Create a 2048 game")
print(repo)  # 打印仓库结构和文件

Data Interpreter 方式

python
import asyncio
from metagpt.roles.di.data_interpreter import DataInterpreter

async def main():
    di = DataInterpreter()
    await di.run("Run data analysis on sklearn Iris dataset, include a plot")

asyncio.run(main())

项目亮点

学术认可

  • ICLR 2024 收录论文,被引用量最高
  • AFlow 论文在 ICLR 2025 获得 Oral Presentation(前 1.8%),在 LLM Agent 类别中排名第 2

产品化

  • MGX (MetaGPT X) - 世界首个 AI 智能体开发团队
  • Product Hunt 周榜 #1(2025年3月10日)
  • Product Hunt 日榜 #1(2025年3月4日)

开源社区

  • GitHub Stars: 40k+
  • 活跃的 Discord 社区
  • 丰富的文档和示例

本章内容

本章将深入介绍 MetaGPT 的核心概念和使用方法:

小节内容
16.1 架构MetaGPT 的整体架构和核心概念
16.2 角色与动作Role 和 Action 的定义与使用
16.3 Data Interpreter数据解释器的功能和应用
16.4 AFlow 与 SPO自动化工作流生成和提示优化
16.5 框架对比与 LangChain、LangGraph、DeepAgent 的对比

参考资源


MetaGPT 是多智能体协作领域的先驱,它首次真正实现了"一行代码生成完整应用"的愿景。

基于 MIT 许可证发布。内容版权归作者所有。