fix(canvas): Agent 模型调用 - 修复关闭思考被误判为开启

This commit is contained in:
ddcat666
2026-09-30 14:39:02 +08:00
parent 4c0aa682a5
commit eb13f73626
3 changed files with 43 additions and 2 deletions

View File

@@ -135,7 +135,7 @@ func (s *Service) runCloudAgentModelStep(ctx context.Context, userID, runID stri
},
"textOptions": map[string]any{
"stream": true,
"thinking": thinkingLevel != "off",
"thinking": cloudAgentPiThinkingEnabled(thinkingLevel),
"maxOutputTokens": cloudAgentStepOutputBudget(state.StepLimits, state.BoostStepOutputBudget),
},
}
@@ -198,6 +198,13 @@ func (s *Service) runCloudAgentModelStep(ctx context.Context, userID, runID stri
return map[string]any{"text": result.Text, "reasoning": result.Reasoning, "toolCalls": runtimeToolCalls(result.ToolCalls)}, false, nil
}
// cloudAgentPiThinkingEnabled treats an omitted thinking level the same as Pi's
// explicit "off" value. Pi omits the field when thinking is disabled, and the
// Go JSON decoder represents that omitted field as an empty string.
func cloudAgentPiThinkingEnabled(thinkingLevel string) bool {
return thinkingLevel != "" && thinkingLevel != "off"
}
// cloudAgentModelTaskRetryable 按上游真实 HTTP 状态判断失败是否是临时性的:
// 5xx、429、408 与没有拿到任何响应的网络错误可以重试;空回复也可以重试。
// 其余 4xx(参数、鉴权、模型不存在)重试结果不会变,直接失败。