From 994950f2734ddbcbb9bfa8d0ee4078a61cce818c Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 25 Jan 2026 11:50:09 +0800 Subject: [PATCH] Enhance OpenAI Provider Request Body with Thinking Parameter - Added support for a new "thinking" parameter in the request body for models that support reasoning/thinking mode, improving functionality. - Updated the request body construction to include debugging output for the full request body, aiding in troubleshooting and development. - Ensured that the model and other settings are retrieved from the connector, maintaining consistency in configuration handling. --- agent/llm/providers/openai/openai.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/agent/llm/providers/openai/openai.go b/agent/llm/providers/openai/openai.go index cc99f9e6..f6390821 100644 --- a/agent/llm/providers/openai/openai.go +++ b/agent/llm/providers/openai/openai.go @@ -1039,13 +1039,19 @@ func (p *Provider) buildRequestBody(messages []context.Message, options *context return nil, fmt.Errorf("options are required") } - // Get model from connector settings + // Get model and other settings from connector setting := p.Connector.Setting() model, ok := setting["model"].(string) if !ok || model == "" { return nil, fmt.Errorf("model is not set in connector") } + // Get thinking setting from connector (for models that support reasoning/thinking mode) + var thinkingSetting interface{} + if thinking, exists := setting["thinking"]; exists { + thinkingSetting = thinking + } + // Convert messages to API format apiMessages := make([]map[string]interface{}, 0, len(messages)) for _, msg := range messages { @@ -1202,6 +1208,17 @@ func (p *Provider) buildRequestBody(messages []context.Message, options *context body["audio"] = options.Audio } + // Add thinking parameter for models that support reasoning/thinking mode + if thinkingSetting != nil { + body["thinking"] = thinkingSetting + fmt.Printf("[DEBUG] Adding thinking parameter to request: %+v\n", thinkingSetting) + } + + // Debug: Print full request body + if bodyJSON, err := jsoniter.MarshalIndent(body, "", " "); err == nil { + fmt.Printf("[DEBUG] Request body:\n%s\n", string(bodyJSON)) + } + return body, nil }