mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2025-12-06 13:54:41 +08:00
fix(decision): add missing actions to AI prompt (#983)
问题:AI 返回 adjust_stop_loss 导致决策验证失败 根因:prompt 只列出 6 个 action,缺少 3 个有效 action 修复(TDD): 1. 添加测试验证 prompt 包含所有 9 个有效 action 2. 最小修改:在 action 列表中补充 3 个缺失项 - update_stop_loss - update_take_profit - partial_close 测试: - TestBuildSystemPrompt_ContainsAllValidActions ✅ - TestBuildSystemPrompt_ActionListCompleteness ✅ Fixes: 无效的action: adjust_stop_loss
This commit is contained in:
committed by
tangmengqiu
parent
b690debf5e
commit
a74aed5a20
@@ -350,7 +350,7 @@ func buildSystemPrompt(accountEquity float64, btcEthLeverage, altcoinLeverage in
|
||||
sb.WriteString("]\n```\n")
|
||||
sb.WriteString("</decision>\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")
|
||||
|
||||
|
||||
50
decision/prompt_test.go
Normal file
50
decision/prompt_test.go
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user