diff --git a/apps/api/src/agents/solver_agent.py b/apps/api/src/agents/solver_agent.py index d62f6dcb..3ab91848 100644 --- a/apps/api/src/agents/solver_agent.py +++ b/apps/api/src/agents/solver_agent.py @@ -200,7 +200,31 @@ blast_radius 參考: # ───────────────────────────────────────────────────────────────────────────── def _extract_candidates(parsed: dict[str, Any]) -> list[CandidateAction]: - """從 LLM 解析結果提取候選方案(按信心降序)。""" + """從 LLM 解析結果提取候選方案(按信心降序)。 + + 支援兩種格式: + 1. 標準格式:{"candidates": [{action, blast_radius, rollback_cost, confidence, rationale}]} + 2. OpenClaw Nemo 格式:{"action_title": "...", "risk_level": "...", "confidence": 0.85} + + 2026-04-16 ogt + Claude Sonnet 4.6: 與 diagnostician 同步,修復 openclaw_nemo 格式不相容 + """ + # OpenClaw Nemo 格式轉換 + if "action_title" in parsed and "candidates" not in parsed: + action_title = str(parsed.get("action_title", "")) + confidence = float(parsed.get("confidence", 0.5)) + risk_level = str(parsed.get("risk_level", "medium")) + risk_to_blast = {"critical": 60, "high": 40, "medium": 25, "low": 10} + blast = risk_to_blast.get(risk_level.lower(), 30) + if action_title and confidence > 0: + return [CandidateAction( + action=action_title[:200], + blast_radius=blast, + rollback_cost=20, + confidence=confidence, + rationale=f"OpenClaw Nemo 建議: {action_title}", + )] + return [] + raw = parsed.get("candidates", []) candidates = [] for item in raw: