diff --git a/apps/api/src/services/ai_providers/nemotron.py b/apps/api/src/services/ai_providers/nemotron.py index 013db91a..9140c8b2 100644 --- a/apps/api/src/services/ai_providers/nemotron.py +++ b/apps/api/src/services/ai_providers/nemotron.py @@ -146,11 +146,12 @@ class NemotronProvider: suggested_action = context.get("suggested_action", prompt) namespace = context.get("namespace", "awoooi-prod") + # 2026-04-09 Claude Code: 明確指示 deployment_name,防止 Nemotron 填 placeholder tool_prompt = f"""根據以下 AI 分析結果,生成對應的 kubectl 操作指令: ## Incident 上下文 - Incident ID: {incident_id} -- 目標資源: {target_resource} +- 目標資源 (deployment_name): {target_resource} - Namespace: {namespace} ## OpenClaw 分析 @@ -158,7 +159,8 @@ class NemotronProvider: - 推理過程: {reasoning[:500]} ## 你的任務 -生成最適合的 kubectl 操作。如果操作有風險,請標註驗證步驟。 +使用提供的工具生成 kubectl 操作。 +**重要**: deployment_name 必須填入 "{target_resource}",不可使用 placeholder。 """ try: diff --git a/apps/api/src/services/openclaw.py b/apps/api/src/services/openclaw.py index b39e4bf6..e56b859a 100644 --- a/apps/api/src/services/openclaw.py +++ b/apps/api/src/services/openclaw.py @@ -1635,11 +1635,12 @@ Focus on: start_time = time.time() # 建構 Tool Calling prompt + # 2026-04-09 Claude Code: 明確指示 deployment_name,防止 Nemotron 填 placeholder tool_prompt = f"""根據以下 AI 分析結果,生成對應的 kubectl 操作指令: ## Incident 上下文 - Incident ID: {incident_id} -- 目標資源: {target_resource} +- 目標資源 (deployment_name): {target_resource} - Namespace: {namespace} ## OpenClaw 分析 @@ -1647,7 +1648,8 @@ Focus on: - 推理過程: {reasoning[:500]} ## 你的任務 -生成最適合的 kubectl 操作。如果操作有風險,請標註驗證步驟。 +使用提供的工具生成 kubectl 操作。 +**重要**: deployment_name 必須填入 "{target_resource}",不可使用 placeholder。 """ # 定義可用 Tools (K8s 操作) @@ -1737,6 +1739,22 @@ Focus on: } tools.append(tool_entry) + # 2026-04-09 Claude Code: 修正 Nemotron 回傳 placeholder 問題 + # 若 deployment_name 是 placeholder 或空值,用 target_resource 覆蓋 + _PLACEHOLDERS = {"", "", "", "unknown", "null", "None"} + for t in tools: + args = t.get("args", {}) + if isinstance(args, dict): + dn = args.get("deployment_name", "") + if not dn or str(dn).strip("<>") in _PLACEHOLDERS or dn.startswith("<"): + args["deployment_name"] = target_resource + logger.info( + "nemotron_placeholder_corrected", + incident_id=incident_id, + original=dn, + corrected=target_resource, + ) + validation_status = "✅ 驗證通過" if validation_passed and tools else "❌ 驗證失敗" return {