Files
awoooi/docs/adr/ADR-019-system-prompt-management.md
OG T 30f045bf28 feat: ADR-019 System Prompt 集中管理 + Nightly LLM Workflow
新增:
- docs/adr/ADR-019-system-prompt-management.md - System Prompt 規範
- apps/api/src/core/prompts.py - 集中管理 System Prompts
- .github/workflows/nightly-llm.yaml - 每夜 LLM 迴歸測試

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-26 12:27:47 +08:00

80 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ADR-019: System Prompt 集中管理
| 屬性 | 值 |
|------|-----|
| **狀態** | Accepted |
| **建立日期** | 2026-03-26 |
| **決策者** | 首席架構師 |
| **關聯** | Phase 17 P2 改進 |
## 背景
System Prompt 分散在多個檔案中:
- `src/services/openclaw.py` - 生產環境 Prompt (約 125 行)
- `tests/test_prompt_validation.py` - 測試用 Prompt (約 15 行)
問題:
1. **違反 DRY 原則** - 相同內容重複定義
2. **維護困難** - 修改需同步多處
3. **版本不一致風險** - 容易遺漏同步
## 決策
建立 `src/core/prompts.py` 集中管理所有 System Prompt。
### 結構
```python
# src/core/prompts.py
# 生產環境完整 Prompt
OPENCLAW_SYSTEM_PROMPT = """..."""
# 測試用精簡 Prompt
OPENCLAW_TEST_PROMPT = """..."""
# 版本資訊
PROMPT_VERSION = "7.1"
PROMPT_UPDATED = "2026-03-26"
```
### 使用方式
```python
# 生產環境
from src.core.prompts import OPENCLAW_SYSTEM_PROMPT
# 測試
from src.core.prompts import OPENCLAW_TEST_PROMPT
```
## 影響檔案
| 檔案 | 變更 |
|------|------|
| `src/core/prompts.py` | 新增 |
| `src/services/openclaw.py` | 改為 import |
| `tests/test_prompt_validation.py` | 改為 import |
## 優點
1. **單一來源** - 所有 Prompt 集中管理
2. **版本追蹤** - 明確的版本號和更新日期
3. **易於測試** - 可獨立測試 Prompt 內容
4. **可擴展** - 未來可加入更多 Prompt 變體
## 替代方案
| 方案 | 優點 | 缺點 | 決定 |
|------|------|------|------|
| **維持現狀** | 無需改動 | DRY 違規 | ❌ |
| **外部檔案 (YAML/JSON)** | 非開發者可編輯 | 增加複雜度 | ❌ |
| **集中式 Python 模組** | 類型安全IDE 支援 | - | ✅ |
## 實作完成
- [x] 建立 `src/core/prompts.py`
- [x] 更新 `openclaw.py` import
- [x] 更新 `test_prompt_validation.py` import
- [x] 驗證 import 正確