88 "nofx/mcp"
99 "nofx/pool"
1010 "regexp"
11+ "strconv"
1112 "strings"
1213 "time"
1314)
@@ -114,6 +115,8 @@ type FullDecision struct {
114115 CoTTrace string `json:"cot_trace"` // 思维链分析(AI输出)
115116 Decisions []Decision `json:"decisions"` // 具体决策列表
116117 Timestamp time.Time `json:"timestamp"`
118+ // AIRequestDurationMs 记录 AI API 调用耗时(毫秒)方便排查延迟问题
119+ AIRequestDurationMs int64 `json:"ai_request_duration_ms,omitempty"`
117120}
118121
119122// GetFullDecision 获取AI的完整交易决策(批量分析所有币种和持仓)
@@ -133,13 +136,24 @@ func GetFullDecisionWithCustomPrompt(ctx *Context, mcpClient *mcp.Client, custom
133136 userPrompt := buildUserPrompt (ctx )
134137
135138 // 3. 调用AI API(使用 system + user prompt)
139+ aiCallStart := time .Now ()
136140 aiResponse , err := mcpClient .CallWithMessages (systemPrompt , userPrompt )
141+ aiCallDuration := time .Since (aiCallStart )
137142 if err != nil {
138143 return nil , fmt .Errorf ("调用AI API失败: %w" , err )
139144 }
140145
141146 // 4. 解析AI响应
142147 decision , err := parseFullDecisionResponse (aiResponse , ctx .Account .TotalEquity , ctx .BTCETHLeverage , ctx .AltcoinLeverage )
148+
149+ // 无论是否有错误,都要保存 SystemPrompt 和 UserPrompt(用于调试和决策未执行后的问题定位)
150+ if decision != nil {
151+ decision .Timestamp = time .Now ()
152+ decision .SystemPrompt = systemPrompt // 保存系统prompt
153+ decision .UserPrompt = userPrompt // 保存输入prompt
154+ decision .AIRequestDurationMs = aiCallDuration .Milliseconds ()
155+ }
156+
143157 if err != nil {
144158 return decision , fmt .Errorf ("解析AI响应失败: %w" , err )
145159 }
0 commit comments