AutoGPT 自主 AI Agent

使用 AutoGPT 建立能自主完成任務的 AI Agent,支援記憶、規劃、工具使用等進階功能

專案簡介

AutoGPT 是一個開源的自主 AI Agent 框架,讓 AI 能夠自動分解任務、規劃執行步驟、使用工具完成複雜目標。是最早的 AI Agent 專案之一。

GitHub Stars: 181K+

主要功能

  • 自主規劃 - AI 自動分解並規劃任務
  • 記憶系統 - 長短期記憶管理
  • 工具使用 - 網路搜尋、程式執行、檔案操作
  • 多模型 - GPT-4、Claude、本地模型
  • 可擴展 - 自訂工具和外掛

安裝

快速開始

1
2
3
4
5
6
7
8
git clone https://github.com/Significant-Gravitas/AutoGPT.git
cd AutoGPT/autogpt

# 複製設定檔
cp .env.template .env

# 安裝依賴
pip install -r requirements.txt

Docker 部署

1
docker compose up -d

設定 API Key

編輯 .env

1
2
3
OPENAI_API_KEY=sk-xxx
# 或使用其他提供者
ANTHROPIC_API_KEY=sk-ant-xxx

啟動

互動模式

1
python -m autogpt

持續模式

1
python -m autogpt --continuous

指定目標

1
python -m autogpt --goal "Research the latest CVE vulnerabilities"

基本使用

定義 AI 角色

1
2
3
4
5
6
7
Enter the AI's name: SecurityResearcher
Enter the AI's role: A cybersecurity researcher that finds and analyzes vulnerabilities
Enter up to 5 goals:
1. Search for recent CVE announcements
2. Analyze the impact of critical vulnerabilities
3. Generate a summary report
4. Save the report to a file

執行過程

1
2
3
4
5
6
7
8
Thinking...
REASONING: I need to search for recent CVE information first.
PLAN:
- Search for CVE announcements from the last week
- Filter for critical severity
- Analyze each vulnerability
CRITICISM: I should verify sources and cross-reference information.
NEXT ACTION: COMMAND = web_search ARGUMENTS = {"query": "CVE critical 2026"}

核心概念

思考循環

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
         ┌──────────────┐
         │   Observe    │
         └──────┬───────┘
         ┌──────────────┐
         │    Think     │
         └──────┬───────┘
         ┌──────────────┐
         │    Plan      │
         └──────┬───────┘
         ┌──────────────┐
         │     Act      │
         └──────┬───────┘
         ┌──────────────┐
         │   Evaluate   │
         └──────────────┘

記憶系統

  • 短期記憶 - 當前任務上下文
  • 長期記憶 - 向量資料庫儲存
  • 工作記憶 - 執行中的任務狀態

內建工具

檔案操作

1
2
3
4
5
6
7
8
# 讀取檔案
read_file(filename)

# 寫入檔案
write_file(filename, content)

# 列出目錄
list_files(directory)

網路操作

1
2
3
4
5
6
7
8
# 網頁搜尋
web_search(query)

# 瀏覽網頁
browse_website(url)

# 下載檔案
download_file(url)

程式執行

1
2
3
4
5
# 執行 Python
execute_python_code(code)

# 執行 Shell
execute_shell_command(command)

自訂工具

建立工具

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# autogpt/plugins/security_scanner/__init__.py
from autogpt.plugins.base import AutoGPTPlugin

class SecurityScannerPlugin(AutoGPTPlugin):
    def __init__(self):
        super().__init__()
        self.name = "Security Scanner"

    def can_handle_command(self, command_name: str) -> bool:
        return command_name == "scan_vulnerability"

    def handle_command(self, command_name: str, arguments: dict):
        target = arguments.get("target")
        return self.scan(target)

    def scan(self, target: str) -> str:
        # 實作掃描邏輯
        return f"Scan results for {target}"

註冊工具

1
2
3
4
5
6
# plugins/__init__.py
from .security_scanner import SecurityScannerPlugin

PLUGINS = [
    SecurityScannerPlugin(),
]

進階設定

模型設定

1
2
3
4
5
6
7
# 使用 GPT-4
SMART_LLM=gpt-4o
FAST_LLM=gpt-4o-mini

# Token 限制
SMART_TOKEN_LIMIT=8000
FAST_TOKEN_LIMIT=4000

記憶體設定

1
2
3
4
5
6
7
8
9
# 使用 Redis
MEMORY_BACKEND=redis
REDIS_HOST=localhost
REDIS_PORT=6379

# 或使用 Pinecone
MEMORY_BACKEND=pinecone
PINECONE_API_KEY=xxx
PINECONE_ENVIRONMENT=us-east-1

安全設定

1
2
3
4
5
6
# 限制 Shell 命令
EXECUTE_LOCAL_COMMANDS=False
RESTRICT_TO_WORKSPACE=True

# 限制網路存取
DISABLED_COMMANDS=["execute_shell"]

AutoGPT Platform

視覺化介面

AutoGPT 提供 Web 平台:

1
2
cd autogpt_platform
docker compose up -d

訪問 http://localhost:3000

功能

  • 視覺化建構 Agent
  • 監控執行狀態
  • 管理多個 Agent
  • API 整合

使用案例

安全研究

1
2
3
4
5
Goal: Research and document the OWASP Top 10 2025 vulnerabilities
- Search for official OWASP documentation
- Analyze each vulnerability category
- Find real-world examples
- Generate comprehensive report

程式開發

1
2
3
4
5
Goal: Create a Python web scraper for security news
- Design the scraper architecture
- Write the Python code
- Test the implementation
- Document the usage

資料分析

1
2
3
4
5
Goal: Analyze log files for security incidents
- Read the log files
- Identify suspicious patterns
- Correlate events
- Generate incident report

最佳實踐

明確的目標

1
2
✓ "Find the top 5 CVEs from January 2026 and create a summary"
✗ "Research security stuff"

限制範圍

1
2
3
4
5
# 限制預算
OPENAI_API_BUDGET=10.0

# 限制迭代次數
CONTINUOUS_LIMIT=50

監控執行

定期檢查 Agent 輸出,確保行為符合預期。

相關連結

延伸閱讀

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy