feat(api): LLM 整合 Expert System 診斷上下文
長期方案實作: Expert 診斷 + LLM 智能分析 變更: 1. decision_manager._dual_engine_analyze(): - 測試資源跳過 LLM (省錢) - 傳遞 Expert 診斷上下文給 LLM - LLM 失敗時根據診斷調整回應 2. openclaw.generate_incident_proposal(): - 新增 expert_context 參數 - Prompt 包含 Expert 診斷結果 - 引導 LLM 基於診斷做決策 流程: Playbook → Expert診斷 → LLM(with context) → 智能建議 這是「先診斷根因,再決定行動」的正確實作 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1068,17 +1068,25 @@ Trace URL: {signoz_trace_url}
|
||||
severity: str,
|
||||
signals: list[dict],
|
||||
affected_services: list[str],
|
||||
expert_context: dict | None = None,
|
||||
) -> tuple[dict | None, str, bool]:
|
||||
"""
|
||||
為 Incident 生成 LLM-based 修復提案
|
||||
|
||||
Phase 6.4: 賦予大腦「生成解決方案」的思考能力
|
||||
2026-03-27: 整合 Expert System 診斷上下文
|
||||
|
||||
Args:
|
||||
incident_id: Incident ID
|
||||
severity: 嚴重度 (P0/P1/P2/P3)
|
||||
signals: 關聯的告警訊號
|
||||
affected_services: 受影響服務
|
||||
expert_context: Expert System 初步診斷 (可選)
|
||||
- initial_diagnosis: 規則匹配結果
|
||||
- diagnosis_description: 診斷描述
|
||||
- suggested_diagnosis_commands: 建議診斷指令
|
||||
- expert_confidence: 信心分數
|
||||
- requires_human_review: 是否需人工介入
|
||||
|
||||
Returns:
|
||||
(proposal_dict, provider, success)
|
||||
@@ -1108,11 +1116,31 @@ Trace URL: {signoz_trace_url}
|
||||
signoz_context = f"""
|
||||
## 📊 SignOz Real-time Metrics
|
||||
{signoz_metrics.to_summary()}
|
||||
"""
|
||||
|
||||
# 2026-03-27: 整合 Expert System 診斷上下文
|
||||
expert_diagnosis_context = ""
|
||||
if expert_context:
|
||||
diagnosis_cmds = expert_context.get("suggested_diagnosis_commands", [])
|
||||
diagnosis_cmds_str = "\n".join([f" - `{cmd}`" for cmd in diagnosis_cmds]) if diagnosis_cmds else " - (無)"
|
||||
expert_diagnosis_context = f"""
|
||||
## 🔍 Expert System Initial Diagnosis
|
||||
- **Matched Rule**: {expert_context.get('initial_diagnosis', 'unknown')}
|
||||
- **Diagnosis**: {expert_context.get('diagnosis_description', 'N/A')}
|
||||
- **Confidence**: {expert_context.get('expert_confidence', 0.5):.0%}
|
||||
- **Requires Human Review**: {'Yes' if expert_context.get('requires_human_review') else 'No'}
|
||||
- **Suggested Diagnosis Commands**:
|
||||
{diagnosis_cmds_str}
|
||||
|
||||
**IMPORTANT**: The Expert System has provided an initial diagnosis.
|
||||
Consider this context but apply your own analysis. If Expert says "human review required",
|
||||
provide diagnostic guidance rather than automated fixes.
|
||||
"""
|
||||
|
||||
proposal_prompt = f"""{OPENCLAW_SYSTEM_PROMPT}
|
||||
|
||||
{signoz_context}
|
||||
{expert_diagnosis_context}
|
||||
|
||||
## 🚨 Incident Context
|
||||
- **Incident ID**: {incident_id}
|
||||
@@ -1124,13 +1152,14 @@ Trace URL: {signoz_trace_url}
|
||||
{signal_summary}
|
||||
|
||||
## 🎯 Your Task
|
||||
Based on the above incident and signals, generate a remediation proposal.
|
||||
Based on the above incident, signals, and Expert System diagnosis, generate a remediation proposal.
|
||||
You MUST respond with ONLY valid JSON following the schema above.
|
||||
Focus on:
|
||||
1. Root cause analysis based on signals and SignOz data
|
||||
2. Specific kubectl command to remediate
|
||||
1. Root cause analysis based on signals, SignOz data, and Expert diagnosis
|
||||
2. Specific kubectl command to remediate (or diagnostic command if root cause unclear)
|
||||
3. Risk assessment for the proposed action
|
||||
4. Preventive recommendations
|
||||
5. If Expert System flagged "human review required", prioritize diagnostic commands over fixes
|
||||
"""
|
||||
|
||||
logger.info(
|
||||
|
||||
Reference in New Issue
Block a user