-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
Describe the bug
When using Semantic Kernel Python with Gemini 3 Pro (gemini-3-pro-preview) and thinking enabled (thinking_config: {"include_thoughts": true}), the model's internal reasoning/thinking text parts leak into the application-visible ChatMessageContent. The thinking text appears as the response content instead of the actual model answer.
This is because _create_chat_message_content and _create_streaming_chat_message_content in GoogleAIChatCompletion add all text parts to the response without checking part.thought. Gemini returns thinking parts with part.thought = True (via the google-genai SDK Part object).
The fix in #13609 correctly handled thought_signature on function call parts, but the same filtering was not applied to text parts.
To Reproduce
- Install
semantic-kernel==1.41.1 - Configure
GoogleAIChatCompletionwithgemini-3-pro-preview - Enable thinking via execution settings:
thinking_config = {"include_thoughts": True} - Register kernel functions/tools and enable auto function calling
- Send a prompt that triggers tool calls
- Observe the final
ChatMessageContent— it contains the model's thinking/reasoning text (e.g. "Processing the Task Request Okay, the task creation was successful...") mixed into or replacing the actual answer
Expected behavior
Text parts where part.thought is True should be excluded from ChatMessageContent.items (or provided separately), so that only the actual model response is surfaced to the application. The raw thinking parts should still be accessible via inner_content for debugging.
Screenshots
N/A — text-based reproduction. Example leaked output:
**Processing the Task Request**
Okay, the task creation was successful; run_id is "78602cd8-...". No need to update any instance yet...
This is the model's internal reasoning, not the actual response.
Platform
- Language: Python
- Source: pip package
semantic-kernel==1.41.1 - AI model: Google Gemini 3 Pro Preview (
gemini-3-pro-preview) - IDE: VS Code
- OS: Windows 11 / Linux (Docker)
Additional context
The fix is to add if part.thought: continue before the if part.text: check in both _create_chat_message_content and _create_streaming_chat_message_content. See PR #13711.