semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

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

Open dariusFTOS opened this issue 8 months ago • 3 comments

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.

dariusFTOS avatar Mar 26 '26 15:03 dariusFTOS

I believe for anthropic models there is a similar implementation gap

ds-brandao avatar Apr 06 '26 05:04 ds-brandao

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] avatar Jul 06 '26 02:07 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jul 21 '26 02:07 github-actions[bot]