Skip to content

Comments

feat(core): refine Edit and WriteFile tool schemas for Gemini 3#19476

Merged
SandyTao520 merged 7 commits intomainfrom
st/feat/edit-tools-schema-refinement
Feb 20, 2026
Merged

feat(core): refine Edit and WriteFile tool schemas for Gemini 3#19476
SandyTao520 merged 7 commits intomainfrom
st/feat/edit-tools-schema-refinement

Conversation

@SandyTao520
Copy link
Contributor

@SandyTao520 SandyTao520 commented Feb 18, 2026

Summary

This PR refines and optimizes the tool schema descriptions for the Edit (replace) and WriteFile tools, specifically for Gemini 3 models. The goal is to reduce token usage, improve clarity, and resolve internal contradictions in the schema definitions.

Details

  • Edit (replace) Tool:
    • Removed redundant suggestions to use read_file from the top-level description.
    • Simplified the instruction parameter description by removing verbose 'how-to' sections and examples.
    • Resolved the logic contradiction regarding the old_string context requirement when expected_replacements is used.
    • Cleaned up excessive whitespace and indentation to produce a more compact JSON schema.
    • Updated old_string and new_string descriptions to reflect the strict requirement for unescaped literal text.
  • WriteFile Tool:
    • Cleaned up formatting (indentation and newlines) in the tool description.
  • Model-Specific Application: These changes are applied exclusively to the Gemini 3 model set in packages/core/src/tools/definitions/model-family-sets/gemini-3.ts. The legacy tool set remains unchanged to preserve historical behavior.
  • Snapshot Updates: Updated the model-specific snapshot tests to match the refined descriptions.

Related Issues

Related to #17547, #17546
Relates to #19269

How to Validate

  1. Inspect the generated tool schemas for Gemini 3 models to ensure they are more compact and clear.
  2. Verify that the legacy models still receive the full, detailed descriptions.
  3. Run snapshot tests: npm run test -w @google/gemini-cli-core -- src/tools/definitions/coreToolsModelSnapshots.test.ts

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on MacOS

@SandyTao520 SandyTao520 requested a review from a team as a code owner February 18, 2026 21:49
@gemini-cli
Copy link
Contributor

gemini-cli bot commented Feb 18, 2026

Hi @SandyTao520, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this.

We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines.

Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed.

Thank you for your understanding and for being a part of our community!

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @SandyTao520, 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 focuses on optimizing the tool schema descriptions for the Edit (replace) and WriteFile tools within the Gemini 3 model set. The primary goal is to enhance the efficiency and clarity of these tool definitions by streamlining descriptions, removing redundancies, and resolving logical inconsistencies, thereby improving their utility for large language models while maintaining backward compatibility for other model families.

Highlights

  • Tool Schema Refinement: Refined the tool schema descriptions for the Edit (replace) and WriteFile tools, specifically targeting Gemini 3 models.
  • Token Usage and Clarity: Reduced token usage and improved clarity in the schema definitions for both Edit and WriteFile tools.
  • Contradiction Resolution: Resolved a logical contradiction in the Edit tool schema regarding the old_string context requirement when expected_replacements is used.
  • Parameter Description Updates: Simplified the instruction parameter description for the Edit tool and updated old_string and new_string descriptions to emphasize strict unescaped literal text requirements.
  • Model-Specific Application: Applied these schema changes exclusively to the Gemini 3 model set, ensuring legacy tool sets remain unchanged.
  • Snapshot Updates: Updated model-specific snapshot tests to reflect the refined tool descriptions.
Changelog
  • packages/core/src/tools/definitions/snapshots/coreToolsModelSnapshots.test.ts.snap
    • Updated the snapshot for the replace tool, removing redundant suggestions, simplifying the instruction parameter description, and clarifying old_string and new_string requirements.
    • Updated the snapshot for the write_file tool, cleaning up its description formatting.
  • packages/core/src/tools/definitions/model-family-sets/gemini-3.ts
    • Simplified the write_file tool description by removing excessive whitespace and newlines.
    • Refined the replace tool description, removing redundant read_file suggestions, simplifying the instruction parameter, and updating old_string and new_string descriptions for clarity and strictness.
Activity
  • No specific activity (comments, reviews, or progress updates) was noted in the provided context.
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.

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 does a great job of refining and optimizing the tool schemas for Edit and WriteFile, specifically for Gemini 3 models. The changes successfully reduce token usage and improve clarity by simplifying descriptions and resolving a key logical contradiction around multiple replacements. The overall direction is excellent. I have one suggestion to further improve the clarity of the replace tool's schema to prevent potential ambiguity for the model.

@github-actions
Copy link

github-actions bot commented Feb 18, 2026

Size Change: -2.74 kB (-0.01%)

Total Size: 24.5 MB

Filename Size Change
./bundle/gemini.js 24.5 MB -2.74 kB (-0.01%)
ℹ️ View Unchanged
Filename Size
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB
./bundle/sandbox-macos-strict-open.sb 4.82 kB
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB

compressed-size-action

@gemini-cli gemini-cli bot added area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Feb 18, 2026
@SandyTao520 SandyTao520 force-pushed the st/feat/edit-tools-schema-refinement branch from fcc8848 to 5f95733 Compare February 19, 2026 00:10
@SandyTao520 SandyTao520 force-pushed the st/feat/edit-tools-schema-refinement branch from 5f95733 to 2b39807 Compare February 19, 2026 00:14
Copy link
Contributor

@aishaneeshah aishaneeshah left a comment

Choose a reason for hiding this comment

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

One question/suggestion

**Important:** If ANY of the above are not satisfied, the tool will fail. CRITICAL for \`old_string\`: Must uniquely identify the single instance to change. Include at least 3 lines of context BEFORE and AFTER the target text, matching whitespace and indentation precisely. If this string matches multiple locations, or does not match exactly, the tool will fail.
5. Prefer to break down complex and long changes into multiple smaller atomic calls to this tool. Always check the content of the file after changes or not finding a string to match.
**Multiple replacements:** Set \`expected_replacements\` to the number of occurrences you want to replace. The tool will replace ALL occurrences that match \`old_string\` exactly. Ensure the number of replacements matches your expectation.",
"description": "Replaces text within a file. By default, replaces a single occurrence, but can replace multiple occurrences when \`expected_replacements\` is specified. This tool requires providing significant context around the change to ensure precise targeting.
Copy link
Contributor

Choose a reason for hiding this comment

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

The expected_replacement part is mentioned multiple times - would it make sense to just add "only" here at the higher level description, and remove them from below?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can still reduce further

"Replaces text within a file. By default, replaces a single occurrence, but can replace multiple occurrences ONLY when `expected_replacements` is specified. This tool requires providing significant context around the change to ensure precise targeting.
The user has the ability to modify the `new_string` content. If modified, this will be stated in the response.

CRITICAL for `old_string`: Include at least 3 lines of context BEFORE and AFTER the target text, matching whitespace and indentation precisely."

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@SandyTao520 SandyTao520 force-pushed the st/feat/edit-tools-schema-refinement branch from 6399bbb to e8bf7a3 Compare February 19, 2026 17:59
Copy link
Contributor

@adamfweidman adamfweidman left a comment

Choose a reason for hiding this comment

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

LGTM, just remove the .tgz file

@SandyTao520 SandyTao520 force-pushed the st/feat/edit-tools-schema-refinement branch from e8bf7a3 to eb3f5fc Compare February 19, 2026 18:27
@SandyTao520 SandyTao520 force-pushed the st/feat/edit-tools-schema-refinement branch from 213b975 to 9e3e03d Compare February 19, 2026 19:38
@SandyTao520 SandyTao520 added this pull request to the merge queue Feb 20, 2026
Merged via the queue into main with commit fb1b1b4 Feb 20, 2026
27 checks passed
@SandyTao520 SandyTao520 deleted the st/feat/edit-tools-schema-refinement branch February 20, 2026 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants