fix(ai): 移除 confidence 預設值,強制 LLM 真實計算

變更:
1. models/ai.py: confidence 改為 REQUIRED (移除 default=0.8)
2. openclaw.py: 如果 LLM 沒輸出 confidence,設為 0.5 + COLLAB

根本原因:
- 原本 Pydantic default=0.8 導致信心分數永遠是 80%
- 現在強制 LLM 必須計算真實信心分數

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-03-28 22:21:29 +08:00
parent 984d31de0c
commit d469a239af
2 changed files with 15 additions and 2 deletions

View File

@@ -130,11 +130,13 @@ class OpenClawDecision(BaseModel):
)
# === 信心度與影響範圍 ===
# 2026-03-29 ogt: 移除預設值,強制 LLM 必須輸出真實信心分數
# 如果 LLM 沒有輸出 confidence解析時會補 0.5 並標記為 COLLAB
confidence: float = Field(
default=0.8,
..., # REQUIRED - 不允許預設值
ge=0.0,
le=1.0,
description="決策信心度 (0-1)",
description="決策信心度 (0-1) - LLM 必須計算",
)
affected_services: list[str] = Field(
default_factory=list,

View File

@@ -996,6 +996,17 @@ class OpenClawService:
if "suggested_action" not in data:
data["suggested_action"] = "NO_ACTION"
# Step 2.5: 2026-03-29 ogt - 強制 confidence 必須由 LLM 輸出
# 如果 LLM 沒有輸出 confidence強制設為 0.5 並標記為 COLLAB
if "confidence" not in data or not isinstance(data["confidence"], (int, float)):
logger.warning(
"llm_missing_confidence",
raw_confidence=data.get("confidence"),
forcing_collab=True,
)
data["confidence"] = 0.5 # 低信心分數
data["primary_responsibility"] = "COLLAB" # 強制協作處理
# Step 3: 使用 Pydantic 驗證 (會自動正規化 risk_level, data_impact 等)
decision = OpenClawDecision(**data)