Skip to content

Python: Bug: Google AI connector leaks thinking/thought text parts into ChatMessageContent #13710

@dariusFTOS

Description

@dariusFTOS

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

  1. Install semantic-kernel==1.41.1
  2. Configure GoogleAIChatCompletion with gemini-3-pro-preview
  3. Enable thinking via execution settings: thinking_config = {"include_thoughts": True}
  4. Register kernel functions/tools and enable auto function calling
  5. Send a prompt that triggers tool calls
  6. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions