> 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/autogpt.md).

# AutoGPT 自主智能体

## 概览

[AutoGPT](https://github.com/Significant-Gravitas/AutoGPT) 是开创性的开源自治 AI 智能体平台，拥有 **175K+ GitHub 星标** —— GitHub 上星标最多的仓库之一。AutoGPT 最初是一个在 2023 年爆红的 Python CLI 工具，如今已演进为一个功能完备的平台，具备网页前端、可视化工作流构建器、多智能体编排以及自我改进的智能体基准测试套件。

当前的 AutoGPT 平台由以下部分组成：

* **前端** — Next.js 可视化智能体构建器（端口 3000）
* **后端 / API** — 处理智能体执行的 FastAPI 服务（端口 8000）
* **智能体执行器** — 运行自治任务循环的 Python 工作进程
* **Postgres** — 用于保存智能体状态和运行记录的持久化存储
* **Redis** — 任务队列和发布/订阅
* **Minio** — 兼容 S3 的智能体产物对象存储

在 **Clore.ai**，AutoGPT 完全运行在 CPU 上（它将 LLM 调用委托给云端 API），使其运行成本低至 **$0.05–0.20/小时**。你还可以通过其对 OpenAI 兼容提供方的支持，选择性集成本地模型。

**关键能力：**

* 🤖 **自治智能体** — 智能体将任务拆解为子目标并迭代执行
* 🌐 **网页浏览** — 智能体可以搜索网页、抓取页面并综合信息
* 💻 **代码执行** — 用于编码智能体的沙箱化 Python 执行环境
* 📁 **文件操作** — 在任务执行过程中读取、写入和管理文件
* 🔗 **多智能体** — 生成专门的子智能体并以层级方式进行编排
* 🧠 **长期记忆** — 基于向量的记忆，可跨会话持久保存
* 📈 **智能体基准测试** — 内置 AgentBenchmark 套件，用于评估智能体性能

***

## 需求

AutoGPT 的算力需求取决于你使用云端 LLM API（默认）还是本地模型。平台本身很轻量。

| 配置                   | GPU        | 显存    | 系统内存  | 磁盘     | Clore.ai 价格                       |
| -------------------- | ---------- | ----- | ----- | ------ | --------------------------------- |
| **极小** （云端 API）      | 无 / CPU    | —     | 4 GB  | 20 GB  | \~$0.05/小时（CPU）                   |
| **标准**               | 无 / CPU    | —     | 8 GB  | 40 GB  | \~$0.08/小时                        |
| **推荐**               | 无 / CPU    | —     | 16 GB | 60 GB  | \~$0.12/小时                        |
| **+ 本地 LLM（Ollama）** | RTX 3090   | 24 GB | 16 GB | 80 GB  | $0.07–0.21/小时                     |
| **+ 大型本地 LLM**       | A100 40 GB | 40 GB | 32 GB | 100 GB | [裸机](https://clore.ai/bare-metal) |

> **注意：** AutoGPT 默认使用基于 API 的 LLM（OpenAI GPT-4、Anthropic Claude 等）。只有当你通过 Ollama 或其他兼容 OpenAI 的服务器配置本地模型端点时，GPU 才有用。

### 需要 API 密钥

你至少需要以下其中之一：

* **OpenAI API 密钥** （推荐 GPT-4o 以获得最佳智能体性能）
* **Anthropic API 密钥** （Claude 3.5 Sonnet 非常适合智能体）
* **Google AI 密钥** （支持 Gemini 模型）

***

## 快速开始

### 1. 租用一台 Clore.ai 服务器

登录 [clore.ai](https://clore.ai) 并启动一个具有以下配置的服务器：

* **2+ CPU 核心，8 GB 内存** 最低
* 开放端口 **8000** （后端 API）和 **3000** （前端）
* 已启用 SSH 访问
* **20+ GB 磁盘空间**

### 2. 连接到服务器

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

# 更新软件包
apt-get update && apt-get upgrade -y

# 验证 Docker 和 Compose
docker --version
docker compose version   # 必须是 v2.x
```

### 3. 克隆并配置 AutoGPT

```bash
# 克隆仓库
git clone https://github.com/Significant-Gravitas/AutoGPT.git
cd AutoGPT/autogpt_platform

# 复制环境模板
cp .env.example .env

# 编辑环境文件
nano .env
```

### 4. 设置必需的环境变量

```bash
# .env 中最低必需项：

# ── LLM 提供方（至少选择一个）──────────────────────────────────────
OPENAI_API_KEY=sk-...
# ANTHROPIC_API_KEY=sk-ant-...

# ── 密钥（请更改这些）─────────────────────────────────────────────
APP_SECRET_KEY=$(openssl rand -hex 32)
JWT_SECRET_KEY=$(openssl rand -hex 32)

# ── 数据库 ─────────────────────────────────────────────────────────────────
DATABASE_URL=postgresql://postgres:password@db:5432/autogpt

# ── 后端 URL（设置为你的 Clore 服务器 IP）──────────────────────────────
NEXT_PUBLIC_AGPT_SERVER_URL=http://<clore-server-ip>:8000/api
```

### 5. 构建并启动

```bash
# 构建镜像并启动所有服务（首次运行需要 5-10 分钟）
docker compose up -d --build

# 观察构建和启动进度
docker compose logs -f

# 启动后，验证所有容器都在运行
docker compose ps
```

### 6. 验证服务是否健康

```bash
# 检查每个服务
docker compose ps

# 预期运行中的服务：
# autogpt_platform-db-1        运行中（健康）
# autogpt_platform-redis-1     运行中
# autogpt_platform-minio-1     运行中
# autogpt_platform-backend-1   运行中
# autogpt_platform-frontend-1  运行中
# autogpt_platform-executor-1  运行中

# 测试后端 API
curl http://localhost:8000/api/health
# 预期：{"status": "ok"}
```

### 7. 访问 AutoGPT

打开你的浏览器：

* **前端：** `http://<clore-server-ip>:3000`
* **后端 API：** `http://<clore-server-ip>:8000`
* **API 文档（Swagger）：** `http://<clore-server-ip>:8000/docs`

在前端创建一个账户，在 Settings 中配置你的 LLM 提供方，然后开始构建智能体。

***

## 配置

### 完整 `.env` 参考

```bash
# ── 应用 ──────────────────────────────────────────────────────────────
ENVIRONMENT=production
APP_SECRET_KEY=<generate-with-openssl-rand-hex-32>
JWT_SECRET_KEY=<generate-with-openssl-rand-hex-32>
ALLOWED_ORIGINS=http://<clore-server-ip>:3000

# ── LLM 提供方 ────────────────────────────────────────────────────────────
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GROQ_API_KEY=gsk_...

# ── 兼容 OpenAI（用于通过 Ollama/vLLM 运行本地模型）──────────────────
OPENAI_API_BASE=http://localhost:11434/v1   # Ollama 的 OpenAI 兼容端点
OPENAI_API_KEY=ollama                        # Ollama 的占位密钥

# ── 数据库 ─────────────────────────────────────────────────────────────────
DATABASE_URL=postgresql://postgres:password@db:5432/autogpt
POSTGRES_USER=postgres
POSTGRES_PASSWORD=password    # 生产环境中请更改！
POSTGRES_DB=autogpt

# ── Redis（任务队列）──────────────────────────────────────────────────────
REDIS_URL=redis://redis:6379/0

# ── Minio（对象存储）─────────────────────────────────────────────────
MINIO_ROOT_USER=minioadmin
MINIO_ROOT_PASSWORD=minioadmin   # 生产环境中请更改！
MINIO_URL=http://minio:9000

# ── 前端 ─────────────────────────────────────────────────────────────────
NEXT_PUBLIC_AGPT_SERVER_URL=http://<clore-server-ip>:8000/api
NEXTAUTH_SECRET=<generate-with-openssl-rand-hex-32>
NEXTAUTH_URL=http://<clore-server-ip>:3000
```

### 自定义智能体能力

```bash
# 启用网页浏览能力
WEB_BROWSER_ENABLED=true
SELENIUM_CHROME_DRIVER_URL=http://selenium:4444/wd/hub

# 将 Selenium 添加到 docker-compose 以用于网页浏览：
# services:
#   selenium:
#     image: selenium/standalone-chrome:latest
#     shm_size: 2gb
#     ports:
#       - "4444:4444"

# 文件系统访问（智能体工作区）
WORKSPACE_PATH=/workspace
RESTRICT_TO_WORKSPACE=true
```

### 管理智能体执行器扩缩容

```bash
# 扩展执行器工作进程以并行运行智能体
docker compose up -d --scale executor=4

# 监控执行器日志
docker compose logs -f executor
```

***

## GPU 加速

AutoGPT 默认将所有 LLM 推理委托给外部提供方。要使用本地 GPU 加速模型：

### 连接到同一台服务器上的 Ollama

```bash
# 在 Clore 服务器上安装 Ollama
curl -fsSL https://ollama.com/install.sh | sh

# 拉取一个能力足够的模型（Llama 3 70B 需要 A100，8B 可在 RTX 3090 上运行）
ollama pull llama3:8b
# 为获得最佳智能体性能：
ollama pull llama3.1:70b   # 需要 A100 40GB+

# 让 Docker 容器能够访问 Ollama
OLLAMA_HOST=0.0.0.0 ollama serve &

# 测试 OpenAI 兼容端点
curl http://localhost:11434/v1/models
```

在 `.env`，然后将 AutoGPT 指向 Ollama：

```bash
OPENAI_API_BASE=http://host.docker.internal:11434/v1
OPENAI_API_KEY=ollama
OPENAI_DEFAULT_MODEL=llama3.1:70b
```

> **性能提示：** 自治智能体会进行许多连续的 LLM 调用。RTX 3090 上的本地模型（约 30 token/s）可以使用，但 A100 80GB 能带来更快的迭代。参见 [GPU 对比](/guides/guides_v2-zh/ru-men-zhi-nan/gpu-comparison.md).

### 智能体本地模型推荐

| 模型                    | 智能体质量 | 显存    | Clore GPU |
| --------------------- | ----- | ----- | --------- |
| Llama 3 8B            | 一般    | 8 GB  | RTX 3080  |
| Llama 3.1 8B Instruct | 好     | 8 GB  | RTX 3080  |
| Llama 3.1 70B         | 优秀    | 40 GB | A100 40GB |
| Mixtral 8x7B          | 好     | 24 GB | RTX 3090  |
| Qwen 2.5 72B          | 优秀    | 40 GB | A100 40GB |

***

## 提示与最佳实践

### Clore.ai 上的成本管理

```bash
# AutoGPT 最大的成本通常是 LLM API 调用，而不是算力
# 在智能体配置中设置 token 预算上限：
# MAX_TOKENS_PER_RUN=100000
# MAX_COST_PER_RUN=1.00   # 美元

# 在停止 Clore 实例之前备份智能体状态
docker exec autogpt_platform-db-1 \\
  pg_dump -U postgres autogpt | gzip > autogpt-backup-$(date +%Y%m%d).sql.gz

# 复制到本地机器
scp -P <port> root@<ip>:autogpt-backup-*.sql.gz ./
```

### 更新 AutoGPT

```bash
cd AutoGPT

# 拉取最新更改
git pull origin master

cd autogpt_platform

# 使用新代码重新构建
docker compose down
docker compose up -d --build

# 如有需要，运行数据库迁移
docker compose exec backend alembic upgrade head
```

### 监控智能体运行

```bash
# 查看后端日志中的智能体活动
docker compose logs -f backend executor

# 在智能体运行期间监控系统资源
htop
# 或
docker stats

# 通过 API 查看智能体运行历史
curl http://localhost:8000/api/v1/runs | python3 -m json.tool
```

### 安全加固

```bash
# 切勿在没有认证的情况下将 8000/3000 端口直接暴露到互联网
# 使用 Nginx 或 Caddy 作为带 HTTPS 的反向代理：

# Caddyfile：
# autogpt.yourdomain.com {
#     reverse_proxy localhost:3000
# }
# api.autogpt.yourdomain.com {
#     reverse_proxy localhost:8000
# }

# 限制智能体文件系统访问
RESTRICT_TO_WORKSPACE=true
WORKSPACE_PATH=/agent-workspace

# 在初始设置后禁用用户注册
ALLOW_SIGNUP=false
```

### 优化构建时间

```bash
# 首次构建较慢（约 10 分钟）；后续构建会使用缓存
# 使用 BuildKit 加速构建：
DOCKER_BUILDKIT=1 docker compose up -d --build

# 预先拉取基础镜像以加快构建
docker pull python:3.11-slim
docker pull node:20-alpine
```

***

## 故障排查

### 构建因内存不足错误而失败

```bash
# Docker 构建需要足够的内存（4GB+）
# 如有需要，添加交换空间：
fallocate -l 8G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile

# 永久生效
echo '/swapfile none swap sw 0 0' >> /etc/fstab
```

### 后端返回 500 / "数据库未就绪"

```bash
# 检查数据库健康状态
docker compose ps db
docker compose logs db

# 手动运行数据库迁移
docker compose exec backend alembic upgrade head

# 如果迁移失败，检查 .env 中的 DATABASE_URL
docker compose exec backend printenv DATABASE_URL
```

### 前端显示“无法连接到后端”

```bash
# 确认 NEXT_PUBLIC_AGPT_SERVER_URL 设置正确
grep NEXT_PUBLIC_AGPT_SERVER_URL .env

# 必须是公网 IP，而不是 localhost（浏览器会发起该请求）
NEXT_PUBLIC_AGPT_SERVER_URL=http://<clore-server-ip>:8000/api

# 更改此环境变量后，重新构建前端
docker compose up -d --build frontend
```

### 智能体执行器崩溃 / 被 OOM 杀死

```bash
# 检查内存使用情况
docker stats autogpt_platform-executor-1

# 限制执行器内存并添加重启策略
# 在 docker-compose.yaml 中：
#   executor:
#     mem_limit: 2g
#     restart: unless-stopped

# 或减少并发运行的智能体数量
MAX_CONCURRENT_RUNS=2
```

### Redis 连接被拒绝

```bash
# 检查 Redis 是否在运行
docker compose ps redis
docker compose logs redis

# 从后端测试连通性
docker compose exec backend redis-cli -h redis ping
# 预期：PONG

# 如果 Redis 需要认证，设置：
REDIS_URL=redis://:password@redis:6379/0
```

### 智能体陷入循环

```bash
# AutoGPT 智能体有时会进入无限循环
# 设置最大循环次数限制：
MAX_AGENT_CYCLES=50

# 或通过 API 中断正在运行的智能体：
curl -X POST http://localhost:8000/api/v1/runs/<run-id>/stop
```

***

## 延伸阅读

* [AutoGPT 官方文档](https://docs.agpt.co)
* [AutoGPT GitHub 仓库](https://github.com/Significant-Gravitas/AutoGPT)
* [AutoGPT 平台设置指南](https://docs.agpt.co/platform/getting-started)
* [在 Clore.ai 上运行 Ollama](/guides/guides_v2-zh/yu-yan-mo-xing/ollama.md)
* [在 Clore.ai 上运行 vLLM](/guides/guides_v2-zh/yu-yan-mo-xing/vllm.md)
* [Clore.ai GPU 对比](/guides/guides_v2-zh/ru-men-zhi-nan/gpu-comparison.md)
* [AutoGPT Discord 社区](https://discord.gg/autogpt)


---

# 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/autogpt.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.
