Skip to content

Python: surface Gemini thought summaries as reasoning content - #7488

Open
giles17 wants to merge 1 commit into
microsoft:mainfrom
giles17:gemini-thought-summaries
Open

Python: surface Gemini thought summaries as reasoning content#7488
giles17 wants to merge 1 commit into
microsoft:mainfrom
giles17:gemini-thought-summaries

Conversation

@giles17

@giles17 giles17 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

GeminiChatClient never surfaced a Gemini model's reasoning. When
thinking_config.include_thoughts is set, Gemini returns thought summaries
(condensed traces of its internal reasoning) as response parts with
part.thought = True, but _parse_parts skipped every thought part. As a
result the reasoning never reached ChatResponse.contents, and downstream
consumers (AG-UI/CopilotKit, "thinking" UIs) showed nothing even when the caller
opted in via include_thoughts.

This also made behaviour inconsistent across providers: OpenAIResponsesClient
already surfaces reasoning as Content.from_text_reasoning(...).

Description & Review Guide

  • What are the major changes?

    • _parse_parts now emits thought-summary parts as text_reasoning content
      (Content.from_text_reasoning(text=..., raw_representation=part)) instead of
      dropping them. A thought part with no text still produces no content.
    • Updated the ThinkingConfig.include_thoughts docstring to reflect that
      summaries are surfaced as text_reasoning.
    • Replaced test_thinking_parts_are_silently_skipped with
      test_thinking_parts_are_surfaced_as_reasoning, and added
      test_empty_thinking_part_produces_no_reasoning_content.
  • What is the impact of these changes?

    • Gemini reasoning is now visible to downstream consumers, matching
      OpenAIResponsesClient. The change is round-trip safe: _convert_message_contents
      never re-emits reasoning text as a Part, so nothing is sent back to Gemini on
      replay. Thought parts are only returned when the caller sets
      include_thoughts, so default behaviour is unchanged.
  • What do you want reviewers to focus on?

    • That the round-trip remains safe and that the existing Gemini 3
      thought_signature-as-reasoning path (on function-call parts) is unaffected.

Related Issue

Fixes #7225

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Gemini thought-summary parts (part.thought=True) were dropped in _parse_parts, so reasoning never reached ChatResponse.contents. Emit them as text_reasoning content instead, matching OpenAIResponsesClient. Round-trip is safe: _convert_message_contents never re-emits reasoning text as a Part.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: b8aa906e-1408-40c1-9a45-6deb40dc36f8
Copilot AI review requested due to automatic review settings August 3, 2026 16:32
@giles17
giles17 temporarily deployed to github-app-auth August 3, 2026 16:32 — with GitHub Actions Inactive
@giles17
giles17 temporarily deployed to github-app-auth August 3, 2026 16:32 — with GitHub Actions Inactive
@giles17
giles17 temporarily deployed to github-app-auth August 3, 2026 16:32 — with GitHub Actions Inactive
@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Aug 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Python Gemini provider to surface Gemini “thought summary” response parts (when thinking_config.include_thoughts is enabled) as text_reasoning content in ChatResponse.contents, aligning the behavior with other providers that already expose reasoning content.

Changes:

  • Update GeminiChatClient._parse_parts to emit Content.from_text_reasoning(...) for part.thought == True parts that include text.
  • Update ThinkingConfig.include_thoughts documentation to reflect that thought summaries are surfaced as text_reasoning.
  • Replace the prior “thought parts are skipped” test with new coverage asserting (a) thought parts become reasoning content and (b) empty thought parts produce no content.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
python/packages/gemini/agent_framework_gemini/_chat_client.py Emit Gemini thought-summary parts as text_reasoning content and update docstrings accordingly.
python/packages/gemini/tests/test_gemini_client.py Update/add tests to validate reasoning surfacing and empty-thought behavior.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 5 | Confidence: 44% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Failure Modes, Design Approach


Automated review by giles17's agents

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/gemini/agent_framework_gemini
   _chat_client.py4731995%404, 723, 744–745, 763–764, 773–774, 777–778, 810, 817, 942, 953, 1145–1146, 1150, 1161–1162
TOTAL44557412790% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9127 34 💤 0 ❌ 0 🔥 2m 26s ⏱️

@giles17
giles17 marked this pull request as ready for review August 3, 2026 16:44
@giles17
giles17 temporarily deployed to github-app-auth August 3, 2026 16:44 — with GitHub Actions Inactive

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 5 | Confidence: 47% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Failure Modes, Design Approach


Automated review by giles17's agents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Feature]: Gemini thought summaries are dropped — surface them as reasoning content

2 participants