feat: disable apply_diff and enable edit tool for Vertex and Gemini providers (#11619)

* feat: disable apply_diff and enable edit tool for Vertex and Gemini providers

* feat: disable apply_diff and enable edit tool for Anthropic provider

* feat: disable apply_diff and enable edit tool for Anthropic Vertex provider

* fix: remove out-of-scope Anthropic/Anthropic-Vertex changes

The PR scope is Gemini and Vertex providers only. Reverting the
Anthropic and Anthropic-Vertex tool preference changes that were
not part of the stated scope.

---------

Co-authored-by: Roo Code <roomote@roocode.com>
This commit is contained in:
roomote[bot] 2026-02-19 23:02:44 -07:00 committed by GitHub
parent 318bb928e0
commit 0d5b932d2e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 55 additions and 1 deletions

View file

@ -173,6 +173,20 @@ describe("GeminiHandler", () => {
const modelInfo = invalidHandler.getModel()
expect(modelInfo.id).toBe(geminiDefaultModelId) // Default model
})
it("should exclude apply_diff and include edit in tool preferences", () => {
const modelInfo = handler.getModel()
expect(modelInfo.info.excludedTools).toContain("apply_diff")
expect(modelInfo.info.includedTools).toContain("edit")
})
it("should not duplicate tool entries if already present", () => {
const modelInfo = handler.getModel()
const excludedCount = modelInfo.info.excludedTools!.filter((t: string) => t === "apply_diff").length
const includedCount = modelInfo.info.includedTools!.filter((t: string) => t === "edit").length
expect(excludedCount).toBe(1)
expect(includedCount).toBe(1)
})
})
describe("calculateCost", () => {

View file

@ -137,5 +137,31 @@ describe("VertexHandler", () => {
expect(modelInfo.info.maxTokens).toBe(8192)
expect(modelInfo.info.contextWindow).toBe(1048576)
})
it("should exclude apply_diff and include edit in tool preferences", () => {
const testHandler = new VertexHandler({
apiModelId: "gemini-2.0-flash-001",
vertexProjectId: "test-project",
vertexRegion: "us-central1",
})
const modelInfo = testHandler.getModel()
expect(modelInfo.info.excludedTools).toContain("apply_diff")
expect(modelInfo.info.includedTools).toContain("edit")
})
it("should not duplicate tool entries if already present", () => {
const testHandler = new VertexHandler({
apiModelId: "gemini-2.0-flash-001",
vertexProjectId: "test-project",
vertexRegion: "us-central1",
})
const modelInfo = testHandler.getModel()
const excludedCount = modelInfo.info.excludedTools!.filter((t: string) => t === "apply_diff").length
const includedCount = modelInfo.info.includedTools!.filter((t: string) => t === "edit").length
expect(excludedCount).toBe(1)
expect(includedCount).toBe(1)
})
})
})

View file

@ -359,6 +359,13 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
defaultTemperature: info.defaultTemperature ?? 1,
})
// Gemini models perform better with the edit tool instead of apply_diff.
info = {
...info,
excludedTools: [...new Set([...(info.excludedTools || []), "apply_diff"])],
includedTools: [...new Set([...(info.includedTools || []), "edit"])],
}
// The `:thinking` suffix indicates that the model is a "Hybrid"
// reasoning model and that reasoning is required to be enabled.
// The actual model ID honored by Gemini's API does not have this

View file

@ -15,7 +15,7 @@ export class VertexHandler extends GeminiHandler implements SingleCompletionHand
override getModel() {
const modelId = this.options.apiModelId
let id = modelId && modelId in vertexModels ? (modelId as VertexModelId) : vertexDefaultModelId
const info: ModelInfo = vertexModels[id]
let info: ModelInfo = vertexModels[id]
const params = getModelParams({
format: "gemini",
modelId: id,
@ -24,6 +24,13 @@ export class VertexHandler extends GeminiHandler implements SingleCompletionHand
defaultTemperature: info.defaultTemperature ?? 1,
})
// Vertex Gemini models perform better with the edit tool instead of apply_diff.
info = {
...info,
excludedTools: [...new Set([...(info.excludedTools || []), "apply_diff"])],
includedTools: [...new Set([...(info.includedTools || []), "edit"])],
}
// The `:thinking` suffix indicates that the model is a "Hybrid"
// reasoning model and that reasoning is required to be enabled.
// The actual model ID honored by Gemini's API does not have this