fix(nemotron): 修復 deployment_name placeholder 問題

根因: Nemotron tool calling 收到 target_resource=DockerContainerUnhealthy
  (非真實 K8s deployment name),不確定時填 <deployment_name>

修復:
1. prompt 明確標注 deployment_name 必須填入 target_resource
2. 收到 tool call 結果後,偵測 placeholder 並用 target_resource 覆蓋

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-04-09 11:44:25 +08:00
parent 85d4857d1b
commit d467fc11be
2 changed files with 24 additions and 4 deletions

View File

@@ -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:

View File

@@ -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 = {"<deployment_name>", "<target>", "", "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 {