Skip to content

Commit 24a070d

Browse files
authored
Merge pull request #3270 from Kilo-Org/christiaan/haiku-read-file
Use single file read_file tool for Haiku 4.5
2 parents 87b41a1 + 2b35053 commit 24a070d

File tree

7 files changed

+50
-12
lines changed

7 files changed

+50
-12
lines changed

.changeset/nervous-nails-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"kilo-code": patch
3+
---
4+
5+
Claude Haiku 4.5 now uses a simplified read file tool for reduced error rate

packages/types/src/single-file-read-models.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@
1010
* @returns true if the model should use single file reads
1111
*/
1212
export function shouldUseSingleFileRead(modelId: string): boolean {
13-
return false // kilocode_change
14-
return modelId.includes("grok-code-fast-1") || modelId.includes("code-supernova")
13+
return modelId.includes("claude-haiku-4.5") || modelId.includes("claude-haiku-4-5") // kilocode_change
1514
}

src/core/prompts/tools/native-tools/__tests__/getAllowedJSONToolsForMode.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("getAllowedJSONToolsForMode", () => {
3434
mockCodeIndexManager,
3535
providerState as ClineProviderState,
3636
true,
37-
false,
37+
undefined,
3838
)
3939

4040
const applyDiffTool = tools.find((tool) => "function" in tool && tool.function.name === "apply_diff")
@@ -59,7 +59,7 @@ describe("getAllowedJSONToolsForMode", () => {
5959
mockCodeIndexManager,
6060
providerState as ClineProviderState,
6161
true,
62-
false,
62+
undefined,
6363
)
6464

6565
const applyDiffTool = tools.find((tool) => "function" in tool && tool.function.name === "apply_diff")

src/core/prompts/tools/native-tools/getAllowedJSONToolsForMode.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ToolName } from "@roo-code/types"
1+
import { ModelInfo, shouldUseSingleFileRead, ToolName } from "@roo-code/types"
22
import { CodeIndexManager } from "../../../../services/code-index/manager"
33
import { Mode, getModeConfig, isToolAllowedForMode, getGroupName } from "../../../../shared/modes"
44
import { ClineProviderState } from "../../../webview/ClineProvider"
@@ -7,13 +7,14 @@ import { ALWAYS_AVAILABLE_TOOLS, TOOL_GROUPS } from "../../../../shared/tools"
77
import { isFastApplyAvailable } from "../../../tools/editFileTool"
88
import { nativeTools } from "."
99
import { apply_diff_multi_file, apply_diff_single_file } from "./apply_diff"
10+
import { read_file_multi, read_file_single } from "./read_file"
1011

1112
export function getAllowedJSONToolsForMode(
1213
mode: Mode,
1314
codeIndexManager: CodeIndexManager | undefined,
1415
clineProviderState: ClineProviderState | undefined,
1516
diffEnabled: boolean,
16-
supportsImages: boolean,
17+
model: { id: string; info: ModelInfo } | undefined,
1718
): OpenAI.Chat.ChatCompletionTool[] {
1819
const config = getModeConfig(mode, clineProviderState?.customModes)
1920

@@ -75,28 +76,39 @@ export function getAllowedJSONToolsForMode(
7576
tools.delete("run_slash_command")
7677
}
7778

78-
if (!clineProviderState?.browserToolEnabled || !supportsImages) {
79+
if (!clineProviderState?.browserToolEnabled || !model?.info.supportsImages) {
7980
tools.delete("browser_action")
8081
}
8182

8283
// Create a map of tool names to native tool definitions for quick lookup
8384
// Exclude apply_diff tools as they are handled specially below
8485
const allowedTools: OpenAI.Chat.ChatCompletionTool[] = []
8586

87+
let isReadFileToolAllowedForMode = false
8688
let isApplyDiffToolAllowedForMode = false
8789
for (const nativeTool of nativeTools) {
8890
const toolName = nativeTool.function.name
8991

9092
// If the tool is in the allowed set, add it.
9193
if (tools.has(toolName)) {
92-
if (toolName === "apply_diff") {
94+
if (toolName === "read_file") {
95+
isReadFileToolAllowedForMode = true
96+
} else if (toolName === "apply_diff") {
9397
isApplyDiffToolAllowedForMode = true
9498
} else {
9599
allowedTools.push(nativeTool)
96100
}
97101
}
98102
}
99103

104+
if (isReadFileToolAllowedForMode) {
105+
if (model?.id && shouldUseSingleFileRead(model?.id)) {
106+
allowedTools.push(read_file_single)
107+
} else {
108+
allowedTools.push(read_file_multi)
109+
}
110+
}
111+
100112
// Handle the "apply_diff" logic separately because the same tool has different
101113
// implementations depending on whether multi-file diffs are enabled, but the same name is used.
102114
if (isApplyDiffToolAllowedForMode && diffEnabled) {

src/core/prompts/tools/native-tools/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import insertContent from "./insert_content"
1111
import listCodeDefinitionNames from "./list_code_definition_names"
1212
import listFiles from "./list_files"
1313
import newTask from "./new_task"
14-
import readFile from "./read_file"
14+
import { read_file_single, read_file_multi } from "./read_file"
1515
import runSlashCommand from "./run_slash_command"
1616
import searchAndReplace from "./search_and_replace"
1717
import searchFiles from "./search_files"
@@ -35,7 +35,8 @@ export const nativeTools = [
3535
listCodeDefinitionNames,
3636
listFiles,
3737
newTask,
38-
readFile,
38+
read_file_single,
39+
read_file_multi,
3940
runSlashCommand,
4041
searchAndReplace,
4142
searchFiles,

src/core/prompts/tools/native-tools/read_file.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type OpenAI from "openai"
22

3-
export default {
3+
export const read_file_multi = {
44
type: "function",
55
function: {
66
name: "read_file",
@@ -42,3 +42,24 @@ export default {
4242
},
4343
},
4444
} satisfies OpenAI.Chat.ChatCompletionTool
45+
46+
export const read_file_single = {
47+
type: "function",
48+
function: {
49+
name: "read_file",
50+
description:
51+
'Request to read the contents of a file. The tool outputs line-numbered content (e.g. "1 | const x = 1") for easy reference when discussing code.',
52+
strict: true,
53+
parameters: {
54+
type: "object",
55+
properties: {
56+
path: {
57+
type: "string",
58+
description: "Path to the file to read, relative to the workspace",
59+
},
60+
},
61+
required: ["path"],
62+
additionalProperties: false,
63+
},
64+
},
65+
} satisfies OpenAI.Chat.ChatCompletionTool

src/core/task/Task.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2964,7 +2964,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
29642964
undefined, // codeIndexManager is private, not accessible here
29652965
providerState,
29662966
this.diffEnabled,
2967-
this.api?.getModel()?.info?.supportsImages ?? false,
2967+
this.api?.getModel(),
29682968
)
29692969

29702970
metadata.allowedTools = allowedTools

0 commit comments

Comments
 (0)