fix(api): 全面清除假信心分數 - 遵循 feedback_confidence_truthfulness.md
🔴 違規修正: 規則匹配/Expert System 不是 AI 分析,confidence 必須 = 0.0 修正檔案: - agents/action_planner.py: 0.9 → 0.0 - agents/blast_radius.py: 0.85/0.5/0.9 → 0.0 - agents/security.py: 計算公式 → 0.0 - signoz_webhook.py: 0.7 → 0.0 - auto_approve.py: default 0.5 → 0.0 - ci_auto_repair.py: 整個計算函數 → return 0.0 - error_analyzer_service.py: default 0.5 → 0.0 - intent_classifier.py: 計算公式 → 0.0 - openclaw.py: default 0.5 → 0.0 - resource_resolver.py: 0.8 → 0.0 - k8s_naming.py: 0.9/0.7 → 0.0 只有 LLM 真實分析返回的 confidence 才能 > 0 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -180,7 +180,7 @@ class AutoApprovePolicy:
|
||||
"""
|
||||
# 基本資訊
|
||||
risk_level = proposal_data.get("risk_level", "medium").lower()
|
||||
confidence = proposal_data.get("confidence", 0.5)
|
||||
confidence = proposal_data.get("confidence", 0.0) # 🔴 無信心度=規則匹配
|
||||
action = proposal_data.get("action", "") or proposal_data.get("kubectl_command", "")
|
||||
action_pattern = self._extract_action_pattern(action)
|
||||
|
||||
|
||||
@@ -362,29 +362,15 @@ class CIAutoRepairService:
|
||||
}
|
||||
return reasons.get(action, "Unknown action")
|
||||
|
||||
def _calculate_confidence(self, action: RepairAction, error_type: str) -> float:
|
||||
"""計算修復信心度"""
|
||||
# 基礎信心度
|
||||
base_confidence = {
|
||||
RepairAction.RETRY_WORKFLOW: 0.6,
|
||||
RepairAction.CLEAR_CACHE: 0.7,
|
||||
RepairAction.RESTART_RUNNER: 0.8,
|
||||
RepairAction.SCALE_RESOURCE: 0.5,
|
||||
RepairAction.ROLLBACK_COMMIT: 0.4,
|
||||
RepairAction.FIX_CONFIG: 0.3,
|
||||
RepairAction.FIX_DEPENDENCY: 0.5,
|
||||
RepairAction.MANUAL_REQUIRED: 0.1,
|
||||
}
|
||||
def _calculate_confidence(self, _action: RepairAction, _error_type: str) -> float:
|
||||
"""
|
||||
計算修復信心度
|
||||
|
||||
confidence = base_confidence.get(action, 0.5)
|
||||
|
||||
# 錯誤類型與動作的匹配度調整
|
||||
if error_type == "timeout" and action == RepairAction.RESTART_RUNNER:
|
||||
confidence += 0.2
|
||||
elif error_type == "build" and action == RepairAction.CLEAR_CACHE:
|
||||
confidence += 0.15
|
||||
|
||||
return min(confidence, 1.0)
|
||||
🔴 2026-03-29 修正: 規則匹配不是 AI 分析,統一返回 0.0
|
||||
根據 feedback_confidence_truthfulness.md 鐵律
|
||||
"""
|
||||
# 規則匹配/規則引擎判斷,非 AI 分析
|
||||
return 0.0
|
||||
|
||||
def _estimate_duration(self, action: RepairAction) -> int:
|
||||
"""估算修復時間 (秒)"""
|
||||
|
||||
@@ -329,7 +329,7 @@ class ErrorAnalyzerService:
|
||||
fix_recommendation=fix_recommendation,
|
||||
prevention=prevention,
|
||||
related_files=data.get("related_files", []),
|
||||
confidence=float(data.get("confidence", 0.5)),
|
||||
confidence=float(data.get("confidence", 0.0)), # 🔴 無信心度=規則匹配
|
||||
reasoning=data.get("reasoning", ""),
|
||||
)
|
||||
|
||||
|
||||
@@ -478,21 +478,13 @@ class IntentClassifier:
|
||||
best_intent = max(scores, key=lambda k: scores[k][0])
|
||||
best_score, matched_keywords = scores[best_intent]
|
||||
|
||||
# 計算信心度 (基於匹配數量)
|
||||
max_possible = len(INTENT_KEYWORDS.get(best_intent, [])) * 2
|
||||
confidence = min(1.0, best_score / max(max_possible, 1) + 0.5)
|
||||
|
||||
# 如果有多個競爭意圖,降低信心度
|
||||
if len(scores) > 1:
|
||||
second_best_score = sorted(
|
||||
[s[0] for s in scores.values()], reverse=True
|
||||
)[1]
|
||||
if second_best_score > best_score * 0.7:
|
||||
confidence *= 0.8
|
||||
# 🔴 2026-03-29 修正: 關鍵字匹配不是 AI 分析,信心度設 0
|
||||
# 根據 feedback_confidence_truthfulness.md 鐵律
|
||||
confidence = 0.0
|
||||
|
||||
result = IntentResult(
|
||||
intent=best_intent,
|
||||
confidence=round(confidence, 2),
|
||||
confidence=confidence,
|
||||
method="keyword",
|
||||
matched_keywords=matched_keywords,
|
||||
detected_resources=detected_resources,
|
||||
|
||||
@@ -1010,7 +1010,7 @@ class OpenClawService:
|
||||
raw_confidence=data.get("confidence"),
|
||||
forcing_collab=True,
|
||||
)
|
||||
data["confidence"] = 0.5 # 低信心分數
|
||||
data["confidence"] = 0.0 # 🔴 LLM 未返回信心度,設為 0
|
||||
data["primary_responsibility"] = "COLLAB" # 強制協作處理
|
||||
|
||||
# Step 3: 使用 Pydantic 驗證 (會自動正規化 risk_level, data_impact 等)
|
||||
@@ -1204,7 +1204,7 @@ Trace URL: {signoz_trace_url}
|
||||
## 🔍 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%}
|
||||
- **Confidence**: {expert_context.get('expert_confidence', 0.0):.0%}
|
||||
- **Requires Human Review**: {'Yes' if expert_context.get('requires_human_review') else 'No'}
|
||||
- **Suggested Diagnosis Commands**:
|
||||
{diagnosis_cmds_str}
|
||||
|
||||
@@ -203,7 +203,7 @@ class ResourceResolver:
|
||||
resource_name=best_match,
|
||||
namespace=normalized.namespace or namespace,
|
||||
resource_type=normalized.resource_type,
|
||||
confidence=0.8,
|
||||
confidence=0.0, # 🔴 模糊匹配,非 AI
|
||||
note=f"Fuzzy matched from '{raw_resource}'",
|
||||
original_input=raw_resource,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user