🚀 企業級 AI 智能平台 | Multi-Agent 協作 | RAG 知識庫 | 可擴展插件系統
功能特色 • 快速開始 • 系統架構 • API 文檔 • 插件開發 • 部署指南
OpenCode Platform 是一個功能完整的企業級 AI 智能平台,整合了:
- 🤖 Multi-Agent 系統 - 5 個專業 Agent 協作處理複雜任務
- 📚 RAG 知識庫 - 上傳 PDF 文件,進行語意搜尋和智能問答
- 🔍 深度研究 - 多引擎網路搜尋,自動生成研究報告
- 🖼️ 多模態對話 - 支援圖片上傳、文件分析
- 💻 代碼沙箱 - 安全執行 Python/Bash 代碼,支援數據分析和圖表
- 🧩 插件系統 - 熱插拔架構,支援自定義 Agent 和工具
- 🔄 工作流編排 - 視覺化設計 Agent 工作流程
| Agent | 職責 | 能力 |
|---|---|---|
| Dispatcher | 總機 | 意圖識別、任務分派 |
| Researcher | 研究員 | RAG 搜尋、網路研究 |
| Writer | 寫手 | 文案撰寫、報告生成 |
| Coder | 程式師 | 代碼生成、執行分析 |
| Analyst | 分析師 | 數據分析、圖表製作 |
| Reviewer | 審稿員 | 品質檢查、內容審核 |
- 支援 PDF 文件上傳和解析
- Cohere 多語言嵌入模型 (embed-multilingual-v3.0)
- Qdrant 向量資料庫
- 智能分塊和語意搜尋
- 支援文件過濾和相關性評分
- 多引擎搜尋 (DuckDuckGo、Wikipedia、arXiv)
- LLM 相關性檢查
- 自動生成結構化研究報告
- 來源引用和追蹤
- 熱插拔,無需重啟
- 支援 Agent 插件和 Tool 插件
- ZIP 上傳 / Git 安裝
- 沙箱執行保障安全
- Python: 3.11+
- Node.js: 18+
- Docker: 20+ (用於 Qdrant 和沙箱)
- 記憶體: 8GB+ 建議
git clone https://github.com/bai0821/opencode_platform.git
cd opencode_platform# 複製範例文件
cp .env.example .env
# 編輯 .env,填入你的 API Keys.env 必填項目:
# LLM API (至少填一個)
OPENAI_API_KEY=sk-proj-xxx
GEMINI_API_KEY=xxx # 可選
# Embedding
COHERE_API_KEY=xxx
# 安全設定
JWT_SECRET=your-secret-key-change-in-production
ADMIN_PASSWORD=your-admin-passworddocker run -d \
--name qdrant \
-p 6333:6333 \
-v $(pwd)/qdrant_storage:/qdrant/storage \
qdrant/qdrant# 建立虛擬環境(建議)
python -m venv venv
# 啟用虛擬環境
# Windows:
venv\Scripts\activate
# Linux/Mac:
source venv/bin/activate
# 安裝依賴
pip install -r requirements.txtcd frontend
npm install
cd ..方式 A:使用啟動腳本(推薦)
# Windows
powershell -ExecutionPolicy Bypass -File start.ps1
# Linux/Mac
bash deploy.sh方式 B:手動啟動
# 終端 1:後端
python run.py api
# 終端 2:前端
cd frontend
npm run dev- 前端介面: http://localhost:5173
- API 文檔: http://localhost:8000/docs
- Qdrant Dashboard: http://localhost:6333/dashboard
| 帳號 | 密碼 | 角色 |
|---|---|---|
| admin | admin123 (或 .env 中設定的) | 管理員 |
┌─────────────────────────────────────────────────────────────────┐
│ Frontend │
│ React + Tailwind CSS │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ API Gateway │
│ FastAPI + JWT Auth │
├─────────────────────────────────────────────────────────────────┤
│ /chat │ /research │ /sandbox │ /plugins │ /workflow │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Agent Coordinator │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │Dispatcher│ │Researcher│ │ Coder │ │ Analyst │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
│ │
│ ┌────────────────────────────────────────────────────────────┐ │
│ │ Plugin Agents │ │
│ │ (Stock Analyst, Weather Tool, Custom Agents...) │ │
│ └────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Services Layer │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ RAG │ │ Sandbox │ │ Search │ │ Workflow │ │
│ │ Service │ │ Service │ │ Service │ │ Engine │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Infrastructure │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Qdrant │ │ OpenAI │ │ Cohere │ │ Docker │ │
│ │ (Vector) │ │ (LLM) │ │(Embedding)│ │(Sandbox) │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────────────────────────────────────────────────────┘
opencode_platform/
├── src/opencode/ # 後端源碼
│ ├── api/ # FastAPI 路由
│ ├── agents/ # Multi-Agent 系統
│ │ ├── base.py # Agent 基類
│ │ ├── coordinator.py # 協調器
│ │ ├── dispatcher.py # 總機 Agent
│ │ └── specialists.py # 專業 Agents
│ ├── services/ # 服務層
│ │ └── knowledge_base/ # RAG 服務
│ ├── plugins/ # 插件系統
│ ├── workflow/ # 工作流引擎
│ ├── sandbox/ # 代碼沙箱
│ ├── auth/ # 認證授權
│ └── control_plane/ # 審計、成本追蹤
│
├── frontend/ # 前端源碼
│ ├── src/
│ │ ├── components/ # React 組件
│ │ └── App.jsx # 主應用
│ ├── package.json
│ └── vite.config.js
│
├── plugins/ # 插件目錄
│ ├── stock-analyst/ # 範例:股票分析 Agent
│ ├── weather-tool/ # 範例:天氣工具
│ └── PLUGIN_DEV_GUIDE.md # 插件開發指南
│
├── docker/ # Docker 配置
├── nginx/ # Nginx 配置
├── tests/ # 測試文件
├── docs/ # 文檔
│
├── .env.example # 環境變數範例
├── requirements.txt # Python 依賴
├── docker-compose.yml # Docker Compose
├── run.py # 啟動腳本
└── README.md # 本文件
| 端點 | 方法 | 說明 |
|---|---|---|
/api/chat/stream |
POST | 串流對話 (SSE) |
/api/research/deep |
POST | 深度研究 |
/api/upload |
POST | 上傳文件 |
/api/documents |
GET | 文件列表 |
/api/sandbox/execute |
POST | 執行代碼 |
/api/plugins |
GET | 插件列表 |
/api/workflows |
GET/POST | 工作流管理 |
/api/agents |
GET | Agent 列表 |
啟動服務後訪問:http://localhost:8000/docs
- 在
plugins/目錄創建插件文件夾 - 添加
plugin.json和main.py - 在管理介面啟用插件
# plugins/my-agent/main.py
from opencode.plugins.manager import AgentPlugin
class PluginImpl(AgentPlugin):
@property
def agent_name(self) -> str:
return "my_agent"
@property
def agent_description(self) -> str:
return "我的自定義 Agent"
async def process_task(self, task_description, parameters, context):
# 你的邏輯
return {"success": True, "output": "Hello from plugin!"}{
"id": "my-agent",
"name": "我的 Agent",
"version": "1.0.0",
"type": "agent",
"entry_point": "main"
}詳見 插件開發指南
docker-compose up -ddocker-compose --profile production up -d# 查看日誌
docker-compose logs -f
# 停止服務
docker-compose down
# 重啟單個服務
docker-compose restart api| 變數 | 必填 | 說明 | 預設值 |
|---|---|---|---|
OPENAI_API_KEY |
✅ | OpenAI API Key | - |
COHERE_API_KEY |
✅ | Cohere API Key | - |
GEMINI_API_KEY |
❌ | Google Gemini API Key | - |
JWT_SECRET |
✅ | JWT 密鑰 | - |
ADMIN_PASSWORD |
❌ | 管理員密碼 | admin123 |
QDRANT_HOST |
❌ | Qdrant 主機 | localhost |
QDRANT_PORT |
❌ | Qdrant 端口 | 6333 |
LOG_LEVEL |
❌ | 日誌等級 | INFO |
預設使用 Collection:opencode_documents
向量維度:1024 (Cohere embed-multilingual-v3.0)
# 運行所有測試
pytest
# 運行特定測試
pytest tests/test_rag.py
# 測試覆蓋率
pytest --cov=src/opencode確保 Docker 容器正在運行:
docker ps | grep qdrant檢查 CORS 設定和後端是否在 8000 端口運行。
確保 Docker 服務正在運行,且有足夠權限。
確認 .env 文件中的 Key 格式正確,沒有多餘空格。
歡迎貢獻!請查看 CONTRIBUTING.md 了解詳情。
- Fork 本專案
- 創建功能分支 (
git checkout -b feature/amazing-feature) - 提交更改 (
git commit -m 'Add amazing feature') - 推送分支 (
git push origin feature/amazing-feature) - 開啟 Pull Request
本專案採用 MIT 授權 - 詳見 LICENSE 文件
Built with ❤️ by OpenCode Team
