Skip to content

[Firebase AI] Add Thought summaries #1317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

a-maurice
Copy link
Collaborator

Description

Provide details of the change, and generalize the change in the PR title above.

Add logic for receiving thought summaries when generating content.


Testing

Describe how you've tested these changes.

Running tests locally.


Type of Change

Place an x the applicable box:

  • Bug fix. Add the issue # below if applicable.
  • New feature. A non-breaking change which adds functionality.
  • Other, such as a build process or documentation change.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @a-maurice, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces the capability to retrieve and expose the AI model's internal 'thought summaries' when generating content. This new feature allows developers to gain insight into the model's reasoning process, enhancing transparency and debugging capabilities for AI-powered applications. It includes updates to the content generation response structure and configuration options to enable this functionality.

Highlights

  • New Feature: Thought Summaries: A new "ThoughtSummary" property has been added to "GenerateContentResponse" to provide a consolidated string of the model's internal thinking process, if available and enabled.
  • Configuration for Thought Summaries: The "ThinkingConfig" within "GenerationConfig" now includes an "IncludeThoughts" option, allowing users to explicitly request thought summaries in the model's responses.
  • Internal Content Part Identification: An "IsThought" property has been introduced to the "ModelContent.Part" interface and its implementing classes ("TextPart", "InlineDataPart", "FunctionCallPart") to differentiate between regular content and parts representing the model's thoughts.
  • Behavioral Change in FunctionCalls Property: The "FunctionCalls" property in "GenerateContentResponse" now filters results to only include function calls that are explicitly marked as 'thoughts'. This changes its previous behavior of returning all function calls.
  • Improved JSON Serialization/Deserialization: New "AddIfHasValue" extension methods have been added to "InternalHelpers.cs" to streamline the serialization of optional values to JSON dictionaries. Parsing logic for content parts has been updated to handle the new "IsThought" and "thoughtSignature" fields.
  • Automated Testing: New automated tests ("TestIncludeThoughts", "InternalTestThoughtSummary") have been added to validate the correct functionality and parsing of thought summaries.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@a-maurice
Copy link
Collaborator Author

/gemini review

@firebase firebase deleted a comment from gemini-code-assist bot Aug 21, 2025
@firebase firebase deleted a comment from gemini-code-assist bot Aug 21, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for receiving thought summaries from the model, which is a great feature for providing insight into the model's reasoning process. The implementation is mostly solid, with good additions to GenerationConfig and ModelContent to support this. However, I've identified two critical issues. First, the FunctionCalls property in GenerateContentResponse is incorrectly filtered to only return function calls that are thoughts, which is likely the opposite of the intended behavior. Second, in ModelContent, the InlineDataPart does not correctly deserialize the isThought property from JSON, which would cause it to be ignored. I've provided specific suggestions to address both of these issues.

Comment on lines +238 to +250
public static void AddIfHasValue<T>(this JsonDict jsonDict, string key,
T? value) where T : struct {
if (value.HasValue) {
jsonDict.Add(key, value.Value);
}
}

public static void AddIfHasValue<T>(this JsonDict jsonDict, string key,
T value) where T : class {
if (value != null) {
jsonDict.Add(key, value);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why we would need to functions, the only difference I can find is the ? after T in parameters

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

By default, struct's are not-nullable, which is why I need the version with T?, and retrieve the underlying value with .Value. Classes can be null, and by default doing T? with a class will result in a warning. So doing two methods helps prevent that warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants