From 5365b1b4dc8b024e14980189456c91b60bb2202a Mon Sep 17 00:00:00 2001 From: Lawrence Liu Date: Sun, 16 Nov 2025 08:13:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(decision):=20add=20missing=20actions=20to?= =?UTF-8?q?=20AI=20prompt=20(#983)=20=E9=97=AE=E9=A2=98=EF=BC=9AAI=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=20adjust=5Fstop=5Floss=20=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=86=B3=E7=AD=96=E9=AA=8C=E8=AF=81=E5=A4=B1=E8=B4=A5=20?= =?UTF-8?q?=E6=A0=B9=E5=9B=A0=EF=BC=9Aprompt=20=E5=8F=AA=E5=88=97=E5=87=BA?= =?UTF-8?q?=206=20=E4=B8=AA=20action=EF=BC=8C=E7=BC=BA=E5=B0=91=203=20?= =?UTF-8?q?=E4=B8=AA=E6=9C=89=E6=95=88=20action=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=EF=BC=88TDD=EF=BC=89=EF=BC=9A=201.=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=AA=8C=E8=AF=81=20prompt=20=E5=8C=85?= =?UTF-8?q?=E5=90=AB=E6=89=80=E6=9C=89=209=20=E4=B8=AA=E6=9C=89=E6=95=88?= =?UTF-8?q?=20action=202.=20=E6=9C=80=E5=B0=8F=E4=BF=AE=E6=94=B9=EF=BC=9A?= =?UTF-8?q?=E5=9C=A8=20action=20=E5=88=97=E8=A1=A8=E4=B8=AD=E8=A1=A5?= =?UTF-8?q?=E5=85=85=203=20=E4=B8=AA=E7=BC=BA=E5=A4=B1=E9=A1=B9=20=20=20?= =?UTF-8?q?=20-=20update=5Fstop=5Floss=20=20=20=20-=20update=5Ftake=5Fprof?= =?UTF-8?q?it=20=20=20=20-=20partial=5Fclose=20=E6=B5=8B=E8=AF=95=EF=BC=9A?= =?UTF-8?q?=20-=20TestBuildSystemPrompt=5FContainsAllValidActions=20?= =?UTF-8?q?=E2=9C=85=20-=20TestBuildSystemPrompt=5FActionListCompleteness?= =?UTF-8?q?=20=E2=9C=85=20Fixes:=20=E6=97=A0=E6=95=88=E7=9A=84action:=20ad?= =?UTF-8?q?just=5Fstop=5Floss?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- decision/engine.go | 2 +- decision/prompt_test.go | 50 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 decision/prompt_test.go diff --git a/decision/engine.go b/decision/engine.go index cc3ea3dc..a6b0113e 100644 --- a/decision/engine.go +++ b/decision/engine.go @@ -350,7 +350,7 @@ func buildSystemPrompt(accountEquity float64, btcEthLeverage, altcoinLeverage in sb.WriteString("]\n```\n") sb.WriteString("\n\n") sb.WriteString("## 字段说明\n\n") - sb.WriteString("- `action`: open_long | open_short | close_long | close_short | hold | wait\n") + sb.WriteString("- `action`: open_long | open_short | close_long | close_short | update_stop_loss | update_take_profit | partial_close | hold | wait\n") sb.WriteString("- `confidence`: 0-100(开仓建议≥75)\n") sb.WriteString("- 开仓时必填: leverage, position_size_usd, stop_loss, take_profit, confidence, risk_usd, reasoning\n\n") diff --git a/decision/prompt_test.go b/decision/prompt_test.go new file mode 100644 index 00000000..f8fc1b3b --- /dev/null +++ b/decision/prompt_test.go @@ -0,0 +1,50 @@ +package decision + +import ( + "strings" + "testing" +) + +// TestBuildSystemPrompt_ContainsAllValidActions 测试 prompt 是否包含所有有效的 action +func TestBuildSystemPrompt_ContainsAllValidActions(t *testing.T) { + // 这是系统中定义的所有有效 action(来自 validateDecision) + validActions := []string{ + "open_long", + "open_short", + "close_long", + "close_short", + "update_stop_loss", + "update_take_profit", + "partial_close", + "hold", + "wait", + } + + // 构建 prompt + prompt := buildSystemPrompt(1000.0, 10, 5, "default") + + // 验证每个有效 action 都在 prompt 中出现 + for _, action := range validActions { + if !strings.Contains(prompt, action) { + t.Errorf("Prompt 缺少有效的 action: %s", action) + } + } +} + +// TestBuildSystemPrompt_ActionListCompleteness 测试 action 列表的完整性 +func TestBuildSystemPrompt_ActionListCompleteness(t *testing.T) { + prompt := buildSystemPrompt(1000.0, 10, 5, "default") + + // 检查是否包含关键的缺失 action + missingActions := []string{ + "update_stop_loss", + "update_take_profit", + "partial_close", + } + + for _, action := range missingActions { + if !strings.Contains(prompt, action) { + t.Errorf("Prompt 缺少关键 action: %s(这会导致 AI 返回无效决策)", action) + } + } +}