> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-zh/ai-ping-tai-yu-zhi-neng-ti/metagpt.md).

# MetaGPT 软件公司

在 Clore.ai 上部署 MetaGPT——在经济实惠的 GPU 云服务器上运行一个完全自主的多智能体 AI 软件公司，从单个……生成完整代码库、PRD、架构设计和 QA 测试

## 概览

[MetaGPT](https://github.com/geekan/MetaGPT) 是一个多智能体 AI 框架，模拟一家 **软件公司** ——配备产品经理、架构师、工程师和 QA 工程师智能体——所有智能体协同工作，将一句话的想法转化为一个完全可运行的软件项目。MetaGPT 在 GitHub 上拥有 45K+ 星标，是 AI 驱动软件开发最具创新性的方案之一。

不同于单一编码智能体，MetaGPT 模拟真实团队的工作流程。当你给它一个类似“用 Python 构建一个贪吃蛇游戏”的任务时，它会：

1. **产品经理** ——编写产品需求文档（PRD）
2. **架构师** ——设计系统架构和技术栈
3. **项目经理** ——拆解任务并进行分配
4. **工程师** ——为每个组件编写实际可运行的代码
5. **QA 工程师** ——编写单元测试并验证实现

最终结果是一个完整的项目目录，包含代码、文档和测试——由系统自动生成。

**关键能力：**

* **完整的软件生命周期** ——从需求到可运行代码，一条命令完成
* **基于角色的智能体** ——职责各不相同的专用智能体
* **文档生成** ——自动生成 PRD、系统设计、API 规范
* **多语言支持** ——Python、Node.js、Go 等
* **数据解释器** ——自动化数据分析与可视化智能体
* **增量开发** ——为现有项目添加功能
* **人机交互模式** ——在关键阶段暂停，供人工审核

**为什么 MetaGPT 选择 Clore.ai？**

MetaGPT 本身是基于 CPU 的，但 Clore.ai 提供了关键优势：

* **长时间运行的任务** ——MetaGPT 生成可能需要 10–60 分钟；专用服务器可以处理这些任务而不会超时
* **本地 LLM 后端** ——使用 Ollama 或 vLLM，消除大型项目按 token 计费的 API 成本
* **成本控制** ——以每小时 $0.20–0.35 的价格，运行大量 MetaGPT 会话比调用 GPT-4o API 更便宜
* **隔离环境** ——生成的代码在受控服务器环境中运行
* **团队协作** ——在开发团队中共享一个 MetaGPT 服务器端点

***

## 需求

MetaGPT 负责协调 LLM API 调用——只有在你运行本地 LLM 后端时才需要 GPU。

| 配置                                 | GPU       | 显存    | 内存    | 存储     | 预估价格                              |
| ---------------------------------- | --------- | ----- | ----- | ------ | --------------------------------- |
| **MetaGPT + OpenAI/Anthropic API** | 无         | —     | 4 GB  | 20 GB  | 约 $0.03–0.08/小时                   |
| **+ Ollama（Qwen2.5-Coder 7B）**     | RTX 3090  | 24 GB | 16 GB | 40 GB  | $0.07–0.21/小时                     |
| **+ Ollama（DeepSeek Coder 33B）**   | RTX 4090  | 24 GB | 32 GB | 60 GB  | $0.14–0.42/小时                     |
| **+ vLLM（Qwen2.5-Coder 32B）**      | RTX 4090  | 24 GB | 32 GB | 80 GB  | $0.14–0.42/小时                     |
| **+ vLLM（Llama 3.1 70B）**          | A100 80GB | 80 GB | 64 GB | 100 GB | [裸机](https://clore.ai/bare-metal) |

> **推荐：** MetaGPT 在很大程度上依赖模型质量来实现连贯的多步推理。对于复杂项目，请使用 GPT-4o 或 Claude Sonnet 3.5 API，或者在本地使用 Qwen2.5-Coder-32B / DeepSeek-Coder-V2。参见 [GPU 比较指南](/guides/guides_v2-zh/ru-men-zhi-nan/gpu-comparison.md).

**Clore.ai 服务器上的软件要求：**

* Docker Engine（所有 Clore.ai 镜像均已预装）
* NVIDIA Container Toolkit（仅适用于本地 LLM 方案）
* 20+ GB 可用磁盘空间（MetaGPT 镜像 + 生成的项目文件）
* 可访问外网（用于拉取 Docker 镜像和连接 LLM API）

***

## 快速开始

### 步骤 1：连接到你的 Clore.ai 服务器

在以下平台预订服务器 [Clore.ai 市场](https://clore.ai):

* 仅 API 模式：任意 ≥4 GB 内存的服务器
* 本地 LLM：配备 ≥24 GB VRAM 的 GPU

```bash
ssh root@<server-ip> -p <ssh-port>
```

### 步骤 2：拉取 MetaGPT Docker 镜像

```bash
docker pull metagpt/metagpt:latest
```

> MetaGPT 镜像约为 3 GB。首次拉取可能需要 2–5 分钟。

### 步骤 3：设置配置

MetaGPT 需要一个包含你的 LLM API 凭据的 YAML 配置文件：

```bash
# 创建目录
mkdir -p /opt/metagpt/{config,workspace}

# 从镜像中提取默认配置模板
docker run --rm metagpt/metagpt:latest \
  cat /app/metagpt/config/config2.yaml \
  > /opt/metagpt/config/config2.yaml

# 查看配置
cat /opt/metagpt/config/config2.yaml
```

### 步骤 4：配置你的 LLM 提供商

编辑配置文件：

```bash
nano /opt/metagpt/config/config2.yaml
```

**OpenAI（GPT-4o）：**

```yaml
llm:
  api_type: "openai"
  model: "gpt-4o"
  base_url: "https://api.openai.com/v1"
  api_key: "sk-your-openai-key-here"

repair_llm_output: true
max_auto_summarize_code: 1
```

**Anthropic（Claude）：**

```yaml
llm:
  api_type: "anthropic"
  model: "claude-3-5-sonnet-20241022"
  api_key: "sk-ant-your-key-here"

repair_llm_output: true
```

**本地 Ollama（见 GPU 部分）：**

```yaml
llm:
  api_type: "ollama"
  model: "ollama/qwen2.5-coder:32b"
  base_url: "http://host.docker.internal:11434"
  api_key: "ollama"

repair_llm_output: true
```

### 步骤 5：运行你的第一个 MetaGPT 项目

```bash
# 生成一个贪吃蛇游戏（经典示例）
docker run --rm --privileged \
  -v /opt/metagpt/config/config2.yaml:/app/metagpt/config/config2.yaml \
  -v /opt/metagpt/workspace:/app/metagpt/workspace \
  metagpt/metagpt:latest \
  metagpt "Create a snake game with Python"
```

观察智能体的工作过程：你会依次看到 PRD 生成、系统设计、代码编写和测试。根据你的 LLM，预计需要 5–15 分钟。

### 步骤 6：查看输出

```bash
ls -la /opt/metagpt/workspace/
# 你会看到一个以你的项目命名的目录

find /opt/metagpt/workspace -type f | head -30
# 列出所有生成的文件：.py、.md、requirements.txt、tests/
```

***

## 配置

### 完整配置参考

```yaml
# /opt/metagpt/config/config2.yaml

# 主 LLM 配置
llm:
  api_type: "openai"          # openai | anthropic | ollama | azure | gemini
  model: "gpt-4o"
  base_url: "https://api.openai.com/v1"
  api_key: "your-api-key"
  temperature: 0.0            # 越低 = 代码生成越确定
  max_token: 4096

# MetaGPT 行为设置
repair_llm_output: true       # 自动修复格式错误的 LLM 响应
max_auto_summarize_code: 1    # 代码摘要迭代次数（0 = 禁用）
max_project_auto_run: 5       # 最大自动执行轮数

# 项目设置
project_name: ""              # 可选：覆盖生成的项目名称
inc: false                    # 增量模式（向现有项目添加内容）
reqa_file: ""                 # 对特定文件运行 QA

# 成本跟踪
max_budget: 10.0              # 最多花费金额（仅 API 调用）
```

### 交互模式运行

如需更多控制，请在带有人审检查点的情况下运行 MetaGPT：

```bash
docker run --rm -it --privileged \
  -v /opt/metagpt/config/config2.yaml:/app/metagpt/config/config2.yaml \
  -v /opt/metagpt/workspace:/app/metagpt/workspace \
  metagpt/metagpt:latest \
  metagpt "Build a REST API for a todo list app with FastAPI" \
  --human-review
```

使用 `--human-review`时，MetaGPT 会在 PRD 和系统设计阶段后暂停，允许你在工程开发开始前提供反馈。

### 增量开发（添加到现有项目）

```bash
# 在现有项目上继续开发
docker run --rm -it --privileged \
  -v /opt/metagpt/config/config2.yaml:/app/metagpt/config/config2.yaml \
  -v /opt/metagpt/workspace:/app/metagpt/workspace \
  -v /opt/metagpt/workspace/my-project:/app/metagpt/workspace/my-project \
  metagpt/metagpt:latest \
  metagpt "Add user authentication to the existing todo API" \
  --project-path /app/metagpt/workspace/my-project \
  --inc
```

### 运行数据解释器

MetaGPT 内置了一个用于数据分析的专用数据解释器智能体：

```bash
# 交互式 Python 数据分析
docker run --rm -it --privileged \
  -v /opt/metagpt/config/config2.yaml:/app/metagpt/config/config2.yaml \
  -v /opt/metagpt/workspace:/app/metagpt/workspace \
  -v /path/to/your/data:/data:ro \
  metagpt/metagpt:latest \
  python -m metagpt.roles.di.data_interpreter \
    "分析 /data/sales.csv，找出表现最佳的产品，并创建可视化"
```

### 用于持久化设置的 Docker Compose

```yaml
# /opt/metagpt/docker-compose.yml
version: "3.9"

services:
  metagpt:
    image: metagpt/metagpt:latest
    privileged: true
    volumes:
      - /opt/metagpt/config/config2.yaml:/app/metagpt/config/config2.yaml:ro
      - /opt/metagpt/workspace:/app/metagpt/workspace
      - /opt/metagpt/logs:/app/metagpt/logs
    environment:
      - PYTHONUNBUFFERED=1
    stdin_open: true
    tty: true
    # 注意：MetaGPT 是基于任务的，不是一个持久化服务。
    # 使用 'docker compose run metagpt metagpt "your task"' 来执行
    entrypoint: ["bash"]
```

```bash
# 通过 docker-compose 运行任务
docker compose -f /opt/metagpt/docker-compose.yml \
  run --rm metagpt \
  metagpt "Create a Flask web app with user registration"
```

***

## GPU 加速（本地 LLM 集成）

### MetaGPT + Ollama

使用本地编码模型，完全免费运行 MetaGPT（无 API 成本）：

```bash
# 步骤 1：使用 GPU 启动 Ollama
docker run -d \\
  --name ollama \\
  --gpus all \\
  --restart unless-stopped \
  -p 11434:11434 \
  -v ollama-models:/root/.ollama \
  ollama/ollama:latest

# 步骤 2：拉取高质量编码模型
# 适用于 RTX 3090/4090（24 GB VRAM）：
docker exec ollama ollama pull qwen2.5-coder:32b      # 最适合代码
docker exec ollama ollama pull deepseek-coder-v2:16b  # 替代方案
# 适用于较小 GPU（8–16 GB VRAM）：
docker exec ollama ollama pull qwen2.5-coder:7b
docker exec ollama ollama pull codellama:13b

# 步骤 3：为 Ollama 配置 MetaGPT
cat > /opt/metagpt/config/config2.yaml << 'EOF'
llm:
  api_type: "ollama"
  model: "ollama/qwen2.5-coder:32b"
  base_url: "http://host.docker.internal:11434"
  api_key: "ollama"
  temperature: 0.0
  max_token: 4096

repair_llm_output: true
max_auto_summarize_code: 0
EOF

# 步骤 4：使用 host 网络运行 MetaGPT，以访问 Ollama
docker run --rm --privileged \
  --add-host host.docker.internal:host-gateway \
  -v /opt/metagpt/config/config2.yaml:/app/metagpt/config/config2.yaml \
  -v /opt/metagpt/workspace:/app/metagpt/workspace \
  metagpt/metagpt:latest \
  metagpt "Create a Python CLI tool for file organization"
```

> 查看完整的 [Ollama 指南](/guides/guides_v2-zh/yu-yan-mo-xing/ollama.md) 用于模型设置和 GPU 优化。

### MetaGPT + vLLM（高吞吐）

适用于大型、复杂项目的最大 token 吞吐量：

```bash
# 步骤 1：使用编码模型启动 vLLM
docker run -d \\
  --name vllm \\
  --gpus all \\
  --restart unless-stopped \
  -p 8000:8000 \
  --ipc=host \\
  vllm/vllm-openai:latest \
  --model Qwen/Qwen2.5-Coder-32B-Instruct \
  --max-model-len 32768 \\
  --gpu-memory-utilization 0.90

# 等待模型加载
until curl -s http://localhost:8000/health | grep -q ok; do
  echo "Waiting for vLLM..."; sleep 10
done

# 步骤 2：为 vLLM 配置 MetaGPT
cat > /opt/metagpt/config/config2.yaml << 'EOF'
llm:
  api_type: "openai"
  model: "Qwen/Qwen2.5-Coder-32B-Instruct"
  base_url: "http://host.docker.internal:8000/v1"
  api_key: "none"
  temperature: 0.0
  max_token: 8192

repair_llm_output: true
EOF

# 步骤 3：运行 MetaGPT
docker run --rm --privileged \
  --add-host host.docker.internal:host-gateway \
  -v /opt/metagpt/config/config2.yaml:/app/metagpt/config/config2.yaml \
  -v /opt/metagpt/workspace:/app/metagpt/workspace \
  metagpt/metagpt:latest \
  metagpt "Build a complete e-commerce backend with FastAPI and PostgreSQL"
```

> 请参阅 [vLLM 指南](/guides/guides_v2-zh/yu-yan-mo-xing/vllm.md) 用于量化选项和多 GPU 配置。

### 按任务推荐的模型

| 任务类型   | 模型                             | 最低显存  | 备注            |
| ------ | ------------------------------ | ----- | ------------- |
| 简单脚本   | `qwen2.5-coder:7b`             | 8 GB  | 速度快，适合 CLI 工具 |
| 中等规模项目 | `qwen2.5-coder:14b`            | 12 GB | 平衡性好          |
| 复杂系统   | `qwen2.5-coder:32b`            | 24 GB | 最佳本地方案        |
| 大型代码库  | `gpt-4o` / `claude-3-5-sonnet` | API   | 对复杂 PRD 最可靠   |

> **提示：** 本地模型在代码生成方面表现良好，但有时难以应对复杂的架构推理。对于生产级别的 PRD 和系统设计，建议在规划阶段使用 GPT-4o 或 Claude，在代码生成阶段使用本地模型。

***

## 提示与最佳实践

### 1. 编写有效的任务提示词

MetaGPT 的表现很大程度上取决于你最初提示词的质量：

```
✅ 好的提示词：
"使用 FastAPI 创建一个 Python REST API 来管理图书馆目录。
功能：添加/搜索/删除图书，使用 JWT 进行用户认证， 
SQLite 数据库，OpenAPI 文档。目标：带测试、可投入生产。"

"构建一个 Python CLI 数据管道工具，读取 CSV 文件，
执行统计分析，并使用 matplotlib 输出图表。"

❌ 模糊的提示词：
"做一个网页应用"
"用 Python 做点什么"
```

### 2. 在运行前估算 API 成本

```bash
# MetaGPT 每个项目会处理大量 token：
# - 简单脚本：约 50K token（使用 GPT-4o 约 $0.25）
# - 中等 web 应用：约 200K token（使用 GPT-4o 约 $1.00）
# - 复杂系统：约 500K+ token（使用 GPT-4o 约 $2.50+）

# 在配置中设置预算上限：
# max_budget: 2.0  # 花费 $2 后停止
```

### 3. 先审查生成的 PRD

使用 `--human-review` 适用于重要项目。PRD 阶段是需求锁定的地方——在这里发现问题，比在代码生成后再修改能节省大量 token 成本。

### 4. 测试生成的代码

MetaGPT 会生成单元测试，但务必验证：

```bash
# 进入生成的项目目录
cd /opt/metagpt/workspace/<your-project>

# 安装依赖
pip install -r requirements.txt

# 运行生成的测试
pytest tests/ -v

# 尝试运行主应用
python main.py
```

### 5. 使用版本控制

```bash
# 在工作区初始化 git
cd /opt/metagpt/workspace
git init
git add .
git commit -m "Initial MetaGPT generation"

# 每次迭代后
git add .
git commit -m "MetaGPT: Added authentication feature"
```

### 6. 批量运行多个项目

在 Clore.ai 上连夜运行多个项目，以获得最大价值：

```bash
#!/bin/bash
# /opt/metagpt/batch-run.sh
PROJECTS=(
  "使用 Python 和 Redis 创建一个短链接服务"
  "构建一个将 Markdown 转换为 PDF 的 CLI 工具"
  "为带评论和标签的博客创建一个 REST API"
)

for project in "${PROJECTS[@]}"; do
  echo "Starting: $project"
  docker run --rm --privileged \
    -v /opt/metagpt/config/config2.yaml:/app/metagpt/config/config2.yaml \
    -v /opt/metagpt/workspace:/app/metagpt/workspace \
    metagpt/metagpt:latest \
    metagpt "$project"
  echo "Completed: $project"
done
```

***

## 故障排查

### 镜像拉取失败

```bash
# 如果遇到 Docker Hub 限流
docker login  # 使用你的 Docker Hub 账号登录
docker pull metagpt/metagpt:latest

# 检查可用磁盘空间
df -h
# MetaGPT 镜像约 3 GB；工作区可能增长到数 GB
```

### 未找到配置文件

```bash
# 验证路径映射是否正确
docker run --rm \\
  -v /opt/metagpt/config/config2.yaml:/app/metagpt/config/config2.yaml \
  metagpt/metagpt:latest \
  ls -la /app/metagpt/config/

# 同时验证你的 YAML 是否有效
python3 -c "import yaml; yaml.safe_load(open('/opt/metagpt/config/config2.yaml'))"
```

### LLM API 身份验证错误

```bash
# 独立测试你的 API 密钥
curl https://api.openai.com/v1/models \
  -H "Authorization: Bearer sk-your-key"

# 对 Anthropic：
curl https://api.anthropic.com/v1/models \
  -H "x-api-key: sk-ant-your-key" \
  -H "anthropic-version: 2023-06-01"

# 常见问题：
# - 密钥复制时带有多余空白
# - 密钥已过期或配额已用尽
# - 配置中的 api_type 错误（例如 "openai" 与 "anthropic"）
```

### 容器连接 Ollama 被拒绝

```bash
# 验证 Ollama 是否正在运行
docker ps | grep ollama
curl http://localhost:11434/api/tags

# 从 MetaGPT 容器视角测试
docker run --rm \\
  --add-host host.docker.internal:host-gateway \
  metagpt/metagpt:latest \
  curl http://host.docker.internal:11434/api/tags

# 如果仍然失败，查看 Ollama 日志
docker logs ollama --tail 20
```

### 生成卡住或超时

```bash
# 检查 LLM 是否真的有响应
# 添加调试日志以查看哪个智能体卡住了
docker run --rm --privileged \
  -e PYTHONUNBUFFERED=1 \
  -v /opt/metagpt/config/config2.yaml:/app/metagpt/config/config2.yaml \
  -v /opt/metagpt/workspace:/app/metagpt/workspace \
  metagpt/metagpt:latest \
  metagpt "Simple task" 2>&1 | tee /opt/metagpt/logs/debug.log

# 常见原因：
# - 本地模型太慢（尝试更小的量化模型）
# - API 限流（添加延迟或切换套餐）
# - 模型上下文窗口超出（降低 max_auto_summarize_code）
```

### 磁盘空间不足

```bash
# 生成的项目可能很大；清理旧项目
du -sh /opt/metagpt/workspace/*
rm -rf /opt/metagpt/workspace/old-project/

# 同时清理 Docker 构建缓存
docker system prune -f

# 检查总占用
df -h /opt/metagpt/
```

### “修复 LLM 输出” 循环

```bash
# 如果 MetaGPT 因 LLM 输出格式错误而不断重试：
# 1. 尝试更强大的模型（GPT-4o、Claude Sonnet）
# 2. 降低 temperature（设为 0.0 以获得确定性）
# 3. 禁用修复（如果使用的是能力足够强的模型）：
#    repair_llm_output: false
```

***

## 延伸阅读

* [MetaGPT GitHub 仓库](https://github.com/geekan/MetaGPT) ——源代码、示例、路线图
* [MetaGPT 文档](https://docs.deepwisdom.ai/main/en/) ——官方文档、配置参考、教程
* [MetaGPT Discord](https://discord.gg/DYn29wFk9z) ——社区支持、使用案例、模型技巧
* [Docker Hub：metagpt/metagpt](https://hub.docker.com/r/metagpt/metagpt) — 可用镜像标签
* [Clore.ai 上的 Ollama](/guides/guides_v2-zh/yu-yan-mo-xing/ollama.md) — 运行本地 LLM，为 MetaGPT 提供免费动力
* [Clore.ai 上的 vLLM](/guides/guides_v2-zh/yu-yan-mo-xing/vllm.md) — 面向大规模 MetaGPT 的高吞吐本地 LLM
* [GPU 比较指南](/guides/guides_v2-zh/ru-men-zhi-nan/gpu-comparison.md) — 为你的工作负载选择合适的 Clore.ai GPU
* [SWE-bench 排行榜](https://www.swebench.com) — 多智能体编码框架基准测试
* [MetaGPT 论文](https://arxiv.org/abs/2308.00352) — 原创研究：“MetaGPT：面向多智能体协作框架的元编程”


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-zh/ai-ping-tai-yu-zhi-neng-ti/metagpt.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
