This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
- **Status**: Accepted
|
||||
- **Date**: 2026-04-19
|
||||
- **Deciders**: 統帥
|
||||
- **Related**: ADR-001(三 Agent 分工), ADR-004(NemoTron Fallback), ADR-007(AI Dual-Write), ADR-011(跨專案隔離)
|
||||
- **Related**: ADR-001(三 Agent 分工), ADR-004(NemoTron Fallback), ADR-007(AI Dual-Write), ADR-011(跨專案隔離), ADR-018(四 AI Agent 自動化控制面)
|
||||
|
||||
## Context
|
||||
|
||||
@@ -25,7 +25,7 @@ P2/P3 Inline Keyboard 降價決策上線後,統帥希望進一步讓 AI Agent
|
||||
| **L0 Direct** | — | 模板直出 | — | 永遠可用(保底) |
|
||||
| **L1 Observer** | Hermes | 翻譯 stack trace、摘要、風險等級標註 | 寫任何資料 / 呼叫外部 API | → L0 + 🟡 標記 |
|
||||
| **L2 Investigator** | NemoTron | 寫 `ai_insights`、執行 **5+3 個安全 tool**、發 Telegram | 動 prod 資料表 / 容器 / 外部系統 | → Hermes 規則引擎(ADR-004)|
|
||||
| **L3 Operator** | OpenClaw | 提方案 + HITL 按鈕 → 人批准後執行任意動作 | 無 HITL 批准前執行 | → 人工 SOP(寄信通知)|
|
||||
| **L3 Operator** | OpenClaw / ElephantAlpha | OpenClaw 提策略方案;ElephantAlpha 做 orchestration + HITL + AutoHeal bridge | 無 HITL 批准前執行高風險動作;不可繞過 ADR-011/013 | → 人工 SOP(寄信通知)|
|
||||
|
||||
### ② 安全 Action 白名單(L2 NemoTron 可用)
|
||||
|
||||
@@ -41,6 +41,11 @@ P2/P3 Inline Keyboard 降價決策上線後,統帥希望進一步讓 AI Agent
|
||||
- `query_km(query, limit=5)` — RAG 檢索歷史同類事件
|
||||
- `silence_alert(event_key, duration_min=60)` — 靜音抑制,避免告警風暴
|
||||
|
||||
**2026-04-29 實作狀態:**
|
||||
- `flag_for_human_review`、`route_to_km`、`mark_for_relearn` 已從 stub 改為 OpenClaw memory 寫入,並保留 audit trail。
|
||||
- EventRouter 僅會執行 `SAFE_ACTIONS`,且需 action plan 明確 `auto_execute` 或 `dispatch_to=safe_action`。
|
||||
- Telegram 發送失敗會寫入 file queue,後續成功送出時 replay。
|
||||
|
||||
### ③ EventRouter 分類規則
|
||||
|
||||
單一入口 `services/event_router.py::dispatch(event)`,依 `severity × event_type` 決定 Tier:
|
||||
@@ -134,9 +139,17 @@ L1 Hermes 掛 → L0 模板直出 + 🟡 「AI 分析暫不可用」
|
||||
- **Phase 4**:依需求擴 L3 HITL 按鈕
|
||||
- **Phase 5**:Prometheus metric 接入(`agent_action_total{tier,agent,event_type}`、`agent_latency_seconds`)
|
||||
|
||||
## 2026-04-29 Implementation Update
|
||||
|
||||
- Phase 1~3 核心已落地:EventRouter 分流、L2 safe action、NemoTron fallback、OpenClaw memory 寫入與通知 replay 已具測試覆蓋。
|
||||
- L3 已擴展為 OpenClaw + ElephantAlpha:OpenClaw 負責策略/記憶,ElephantAlpha 負責 orchestration/HITL/AutoHeal bridge。
|
||||
- 尚未完成:Prometheus metrics 與完整線上 smoke dashboard。
|
||||
|
||||
## References
|
||||
- `services/event_router.py` — 分流入口(Phase 1)
|
||||
- `services/agent_actions.py` — 安全 action 白名單(Phase 1)
|
||||
- `services/telegram_templates.py::triaged_alert()` — L1/L2 訊息格式(Phase 1)
|
||||
- `docs/guides/codex_agent_roles.md` — Codex 化角色矩陣與派工規則
|
||||
- `docs/guides/ai_automation_session_sop.md` — AI 自動化 session 與收尾 SOP
|
||||
- `docs/memory/history_logs.md` — Agent 事件與 Telegram 相關歷史脈絡
|
||||
- `docs/memory/ai_automation_closure_20260429.md` — 2026-04-29 AI 自動化閉環修復實況
|
||||
|
||||
@@ -43,7 +43,9 @@ Exception → Incident(DB) → PlayBook 匹配 → Auto-Heal 執行 → HealLog(
|
||||
|
||||
### 安全設計
|
||||
|
||||
- SSH 指令白名單:僅允許 `docker restart *`, `docker compose restart *`, `docker start *`
|
||||
- SSH 指令白名單:2026-04-29 起僅允許明確列入 allowlist 的 read-only 診斷指令;高副作用容器操作需走受控 PlayBook 與保護清單
|
||||
- `momo-db` / `momo-postgres` 永遠是 protected resource,不得被自動 restart / stop / recreate
|
||||
- DB / DNS 類離線 playbook 若無法安全修復,降級為 `ALERT_ONLY` 或 `WAIT_RETRY`
|
||||
- 冷卻機制:同 PlayBook 在 `cooldown_min` 內不重複觸發
|
||||
- 升級機制:達到 `max_retries` 後 incident.status = `escalated` 並通知人工
|
||||
|
||||
@@ -98,6 +100,15 @@ result=success duration=3110ms # DNS_FAIL → docker restart momo-db 成功
|
||||
|
||||
heal_log 在 restart momo-db 後因 DB 瞬斷無法寫入 DB(id=7~9 遺失)屬設計邊界,Telegram 通知仍正常推播。
|
||||
|
||||
### 2026-04-29 安全修訂
|
||||
|
||||
上述 `DNS_FAIL → docker restart momo-db` 屬早期實測紀錄,現在不再允許作為自動修復策略。最新規則:
|
||||
|
||||
- `momo-db` / `momo-postgres` 是資料層 protected resource。
|
||||
- AutoHeal 寫 DB 失敗時不可讓自癒流程 crash,需保留 Telegram / log / fallback 記錄。
|
||||
- `CODE_FIX`、resource action 與 ElephantAlpha orchestration 必須橋接 AutoHeal,不得直接執行危險副作用。
|
||||
- raw `ai_insights` 寫入後必須 enqueue embedding,讓自癒知識進入 RAG。
|
||||
|
||||
### 新增 DB 表
|
||||
|
||||
- `migrations/014_telegram_users.sql` — EventRouter 推播對象(替代 .env 硬編碼)
|
||||
|
||||
86
docs/adr/ADR-018-four-agent-ai-automation-control-plane.md
Normal file
86
docs/adr/ADR-018-four-agent-ai-automation-control-plane.md
Normal file
@@ -0,0 +1,86 @@
|
||||
# ADR-018: 四 AI Agent 自動化控制面(Hermes / NemoTron / OpenClaw / ElephantAlpha)
|
||||
|
||||
- **Status**: Accepted
|
||||
- **Date**: 2026-04-29
|
||||
- **Deciders**: 統帥
|
||||
- **Related**: ADR-001, ADR-004, ADR-007, ADR-009, ADR-011, ADR-012, ADR-013
|
||||
|
||||
## Context
|
||||
|
||||
ADR-001 定義 Hermes / NemoTron / OpenClaw 三 Agent 自主學習分工,ADR-012 定義事件介入的 L0/L1/L2/L3 信任邊界,ADR-013 定義 AIOps 自癒閉環。
|
||||
|
||||
2026-04-29 的 AI 自動化盤點與修復後,系統實作已超出原本三 Agent 學習分工:
|
||||
|
||||
- `services/event_router.py` 已成為告警、降級、去重、通知重放與安全 L2 action 的共同入口。
|
||||
- `services/auto_heal_service.py` 已承擔 incident / playbook / heal log / KM 沉澱的自癒閉環,但必須保護 `momo-db`。
|
||||
- `services/openclaw_learning_service.py` 已成為 raw `ai_insights` 寫入與 embedding queue 的橋接層。
|
||||
- `services/elephant_alpha_autonomous_engine.py` 已接入 HITL、AutoHeal bridge、Telegram 通知與受控 SSH log scan。
|
||||
|
||||
因此需要把 ElephantAlpha 正式納入 MOMO PRO / EwoooC 的 AI 自動化控制面,避免文件仍停留在三 Agent 舊模型。
|
||||
|
||||
## Decision
|
||||
|
||||
採用「四 AI Agent + EventRouter + AutoHeal」控制面:
|
||||
|
||||
| 角色 | 層級 | 主要責任 | 不可越界 |
|
||||
|---|---|---|---|
|
||||
| Hermes | L1 Observer / Embedding | 摘要、規則降級、embedding、品質分數、RAG 輔助 | 不直接做外部副作用,不生成最終策略報告 |
|
||||
| NemoTron | L2 Investigator | tool calling、事件路由、低風險安全 action、DB/KM 寫入派發 | 不動 prod 容器與外部系統,不做不可逆操作 |
|
||||
| OpenClaw | L3 Strategist | 高品質策略、報告、長期洞察、人工核准後的高風險建議 | 無 HITL 不直接執行高風險動作 |
|
||||
| ElephantAlpha | L3 Orchestrator | 跨 Agent 編排、HITL 決策、AutoHeal bridge、受控執行計畫 | 不繞過 EventRouter / AutoHeal / ADR-011 邊界 |
|
||||
|
||||
控制面規則:
|
||||
|
||||
1. EventRouter 是告警與 L2 action 的唯一入口;通知鏈不可因 AI 失敗中斷。
|
||||
2. AutoHeal 是自癒副作用的唯一入口;`momo-db` / `momo-postgres` 永遠不得被自動 restart / stop / recreate。
|
||||
3. OpenClaw learning 是 AI 記憶落點;raw `ai_insights` 寫入者必須同步 enqueue embedding 或具備可回補機制。
|
||||
4. ElephantAlpha 只能編排與橋接,不可直接跳過 HITL、安全白名單或跨專案隔離規則。
|
||||
5. L2 安全 action 只允許保守、可審計、可回放的動作,例如 `retry_task`、`query_km`、`silence_alert`、`flag_for_human_review`、`route_to_km`、`mark_for_relearn`。
|
||||
|
||||
## Alternatives Considered
|
||||
|
||||
| 方案 | 不採用原因 |
|
||||
|---|---|
|
||||
| 維持 ADR-001 三 Agent 模型 | 無法解釋 ElephantAlpha 的 orchestration / HITL / AutoHeal bridge 實況 |
|
||||
| 讓 ElephantAlpha 取代 OpenClaw | 會混淆策略報告與執行編排責任,成本與風險邊界不清 |
|
||||
| 讓 NemoTron 直接執行所有自癒 | L2 不應具備高副作用權限,與 ADR-012 信任邊界衝突 |
|
||||
| 導入外部 Agent framework | 黑盒程度高,難審計,不符合本專案 FinOps 與安全透明原則 |
|
||||
|
||||
## Consequences
|
||||
|
||||
正面:
|
||||
|
||||
- 四個 AI Agent 都有明確位置,避免重疊工作與越權。
|
||||
- 告警、自癒、通知、記憶沉澱形成可測試閉環。
|
||||
- NemoTron / OpenClaw / ElephantAlpha 失敗時仍可降級到 Hermes / L0 模板。
|
||||
- AI 記憶不再只依賴單一路徑,raw insert 也能排入 embedding queue。
|
||||
|
||||
風險與約束:
|
||||
|
||||
- 文件與實作必須同步維護,否則新 session 容易回到三 Agent 舊心智模型。
|
||||
- ElephantAlpha 的「編排」很容易被誤解成「全權執行」,所有 bridge 必須走既有安全入口。
|
||||
- AutoHeal 若找不到 DB 或 PlayBook,必須安全降級為 alert / file / log,不可因記錄失敗而中斷通知。
|
||||
|
||||
## Implementation Notes
|
||||
|
||||
2026-04-29 已落地的關鍵 commit:
|
||||
|
||||
- `779b27f` 修復 P0 告警自癒鏈與測試收集
|
||||
- `0875dd8` 補強 5.5 自癒安全回看
|
||||
- `1c2dc6c` 補強 AI 自動化閉環與安全降級
|
||||
- `f0e044a` 補齊自癒稽核與 OpenClaw 記憶閉環
|
||||
- `0c2e9bb` 串接 AI 洞察向量化與漏通知入口
|
||||
- `78eebfb` 加入告警去重與洞察向量回補
|
||||
- `d486598` 補強 ElephantAlpha 執行與通知閉環
|
||||
- `5b25f55` 補齊 EventRouter 失敗通知回放
|
||||
- `162a76b` 落地 L2 安全記憶動作
|
||||
|
||||
## References
|
||||
|
||||
- `docs/AI_INTELLIGENCE_MODULE_SOT.md`
|
||||
- `docs/memory/ai_automation_closure_20260429.md`
|
||||
- `docs/guides/ai_automation_session_sop.md`
|
||||
- `services/event_router.py`
|
||||
- `services/auto_heal_service.py`
|
||||
- `services/openclaw_learning_service.py`
|
||||
- `services/elephant_alpha_autonomous_engine.py`
|
||||
@@ -39,6 +39,7 @@
|
||||
| [015](ADR-015-telegram-bot-menu-restoration.md) | Telegram Bot 完整菜單系統恢復 | Accepted | 2026-04-20 |
|
||||
| [016](ADR-016-daily-sales-cache-fingerprint.md) | daily_sales cache fingerprint(gunicorn 多 worker 一致性) | Accepted | 2026-04-29 |
|
||||
| [017](ADR-017-modularization-cleanup-roadmap.md) | 模組化收尾路線圖(Phase 3f) | Accepted | 2026-04-29 |
|
||||
| [018](ADR-018-four-agent-ai-automation-control-plane.md) | 四 AI Agent 自動化控制面(Hermes/NemoTron/OpenClaw/ElephantAlpha) | Accepted | 2026-04-29 |
|
||||
|
||||
## 規範
|
||||
|
||||
|
||||
Reference in New Issue
Block a user