Skip to content

Fix tool output fragmentation by encapsulating content in functionResponse - #13082

Merged
joshualitt merged 5 commits into
mainfrom
abhipatel12/consolidate-fc-response
Dec 15, 2025
Merged

Fix tool output fragmentation by encapsulating content in functionResponse#13082
joshualitt merged 5 commits into
mainfrom
abhipatel12/consolidate-fc-response

Conversation

@abhipatel12

Copy link
Copy Markdown
Contributor

Summary

Refactors convertToFunctionResponse to ensure all tool outputs—specifically arrays and binary data—are consistently wrapped within the content field of a single functionResponse part. This fixes an issue where certain tools (like ReadManyFilesTool and DiscoveredMCPTool) returned fragmented responses across multiple parts.

Details

  • Encapsulation: Modified convertToFunctionResponse in packages/core/src/core/coreToolScheduler.ts to wrap Part[] and PartListUnion outputs into response: { content: [...] }.
  • Backward Compatibility: Simple string outputs continue to use the legacy response: { output: ... } format to minimize disruption for simple tools.
  • Test Updates: Updated coreToolScheduler.test.ts and nonInteractiveToolExecutor.test.ts to match the new output structure, ensuring binary data and mixed content are correctly asserted as being inside functionResponse.

How to Validate

  1. Run Core Scheduler Tests:

    npm test src/core/coreToolScheduler.test.ts

    Verify that all tests pass, especially the new cases for "PartListUnion array" and "inlineData".

  2. Run Executor Tests:

    npm test src/core/nonInteractiveToolExecutor.test.ts

    Confirm that should correctly format llmContent with inlineData passes with the new expectation.

  3. Manual Verification (Optional):

    • Use ReadFileTool to read an image or PDF (ask the model to do this)
    • Inspect the tool output to ensure it is a single functionResponse part containing the binary data within content, rather than a functionResponse followed by a separate inlineData part (via /chat share foo.json)

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@abhipatel12
abhipatel12 requested a review from a team as a code owner November 14, 2025 19:03
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @abhipatel12, 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 a significant refactoring to how tool outputs are structured within the system. The primary goal is to eliminate fragmentation by ensuring that complex outputs, such as arrays of parts or binary data, are always encapsulated within a single functionResponse object under a dedicated content field. This change standardizes tool responses, making them more predictable and easier to process, while carefully preserving compatibility for simpler string-based outputs.

Highlights

  • Output Encapsulation: Refactored the convertToFunctionResponse function to ensure all tool outputs, especially arrays and binary data, are consistently wrapped within the content field of a single functionResponse part.
  • Fragmentation Fix: This change resolves an issue where certain tools (e.g., ReadManyFilesTool, DiscoveredMCPTool) were returning fragmented responses across multiple parts, leading to inconsistent output.
  • Backward Compatibility: Simple string outputs will continue to use the legacy response: { output: ... } format to minimize disruption for existing tools.
  • Test Updates: Updated coreToolScheduler.test.ts and nonInteractiveToolExecutor.test.ts to align with the new output structure, ensuring correct assertion of binary data and mixed content within functionResponse.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request refactors convertToFunctionResponse to consistently wrap complex tool outputs into a single functionResponse part, which is a great improvement for handling fragmented responses. The changes are logical and well-tested. I've found one critical issue where the identity (name and ID) of a nested functionResponse is lost during transformation, which could lead to incorrect output attribution. I've provided a suggestion to preserve this information.

Comment thread packages/core/src/core/coreToolScheduler.ts Outdated
@github-actions

github-actions Bot commented Nov 14, 2025

Copy link
Copy Markdown

Size Change: +650 B (0%)

Total Size: 21.6 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 21.6 MB +650 B (0%)
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B

compressed-size-action

@abhipatel12
abhipatel12 force-pushed the abhipatel12/consolidate-fc-response branch 4 times, most recently from cc5ff91 to 04288bc Compare December 12, 2025 17:52
Comment thread packages/core/src/core/coreToolScheduler.ts
@abhipatel12
abhipatel12 force-pushed the abhipatel12/consolidate-fc-response branch from 04288bc to 0fba3f9 Compare December 12, 2025 19:39
@abhipatel12
abhipatel12 force-pushed the abhipatel12/consolidate-fc-response branch from 0fba3f9 to 8ac50af Compare December 15, 2025 18:00
…ponse

Refactors `convertToFunctionResponse` to ensure all tool outputs—specifically arrays and binary data—are consistently wrapped within the `content` field of a single `functionResponse` part. This fixes an issue where certain tools returned fragmented responses across multiple parts.

Details:
- Modified `convertToFunctionResponse` in `packages/core/src/core/coreToolScheduler.ts` to wrap `Part[]` and `PartListUnion` outputs into `response: { content: [...] }`.
- Introduced a `toParts` helper to consistently convert various input types into a `Part[]`.
- Simple string outputs continue to use the legacy `response: { output: ... }` format.
- Updated `coreToolScheduler.test.ts` and `nonInteractiveToolExecutor.test.ts`.
@abhipatel12
abhipatel12 force-pushed the abhipatel12/consolidate-fc-response branch from 8ac50af to 8c70761 Compare December 15, 2025 20:02
@abhipatel12
abhipatel12 added this pull request to the merge queue Dec 15, 2025
@abhipatel12
abhipatel12 removed this pull request from the merge queue due to a manual request Dec 15, 2025
@joshualitt
joshualitt added this pull request to the merge queue Dec 15, 2025
Merged via the queue into main with commit d236df5 Dec 15, 2025
20 checks passed
@joshualitt
joshualitt deleted the abhipatel12/consolidate-fc-response branch December 15, 2025 20:50
thacio added a commit to thacio/auditaria that referenced this pull request Jan 23, 2026
@sripasg sripasg added the size/l A large sized PR label Jun 2, 2026
software-0ficial pushed a commit to software-0ficial/gemini-cli that referenced this pull request Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l A large sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants