feat(core): steer model to use edit tool for surgical edits, fix a typo#26480
feat(core): steer model to use edit tool for surgical edits, fix a typo#26480aishaneeshah merged 4 commits intomainfrom
Conversation
…g files This change updates tool descriptions for 'write_file' and 'replace' to encourage surgical edits and simplify the 'replace' tool's strict context requirements. It also fixes a typo in the system prompt guidance.
Reverted changes to default-legacy.ts and ensured gemini-3.ts replace description retains all existing details while adding the preference for surgical edits. Updated snapshots accordingly.
Summary of ChangesHello, 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 improves the guidance provided to the gemini-3 model regarding file editing tools. By clarifying the intended use cases for 'write_file' and 'replace', the changes aim to reduce token consumption, streamline code reviews, and prevent accidental file deletions. Additionally, a minor correction was made to the system prompt guidelines to accurately reflect tool behavior. Highlights
Using Gemini Code AssistThe 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
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 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. Footnotes
|
|
Size Change: +183 B (0%) Total Size: 34 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Code Review
This pull request updates the prompt guidelines and tool descriptions for the replace and write_file tools. It corrects the prompt text to clarify that the replace tool fails when the old_string is ambiguous and updates tool descriptions to highlight the advantages of using replace for surgical edits, including reduced token usage and simplified reviews. I have no feedback to provide.
|
✅ 70 tests passed successfully on gemini-3-flash-preview. 🧠 Model Steering GuidanceThis PR modifies files that affect the model's behavior (prompts, tools, or instructions).
This is an automated guidance message triggered by steering logic signatures. |
| exports[`coreTools snapshots for specific models > Model: gemini-3-pro-preview > snapshot for tool: replace 1`] = ` | ||
| { | ||
| "description": "Replaces text within a file. By default, the tool expects to find and replace exactly ONE occurrence of \`old_string\`. If you want to replace multiple occurrences of the exact same string, set \`allow_multiple\` to true. This tool requires providing significant context around the change to ensure precise targeting. | ||
| "description": "Replaces text within a file. By default, the tool expects to find and replace exactly ONE occurrence of \`old_string\`. If you want to replace multiple occurrences of the exact same string, set \`allow_multiple\` to true. This tool is preferred for surgical edits to existing files as it minimizes token usage, simplifies code reviews, and avoids accidental deletions. This tool requires providing significant context around the change to ensure precise targeting. |
There was a problem hiding this comment.
This all looks ok at a glance but perhaps it's worth running evals to check for regressions because in my experience replace is very finicky. I found that changes to edit guidance frequently caused more tool failures or turns.
Replace needs a large enough old_string to not be ambiguous but a small enough one that the model can remember it without typos.
There was a problem hiding this comment.
I haven't run evals. The large context requirement was in the existing description - happy to remove it but figured it was something that was tuned earlier.
Addition to steer model to use edit tool was to address a bunch of issues which reported that Gemini CLI uses write_file to edit large files - there by deleting a lot of existing code or other unintentional side effects
In my personal use - I see this all the time specially when updating tests - and need to instruct the model to only edit the test file, or not remove existing comments etc.
There was a problem hiding this comment.
Also - in all of those cases - technically the tool doesn't "fail" but it fails on the overall intent.
Summary
This PR updates the tool descriptions for `write_file` and `replace` in the `gemini-3` model family to steer the model towards more efficient and safer editing practices. It specifically encourages using the `replace` tool for surgical edits to existing files to minimize token usage, simplify code reviews, and prevent accidental deletions.
Details
Related Issues
Fixes #24713, #25568
How to Validate
Pre-Merge Checklist