Skip to content

Commit 68ef238

Browse files
committed
docs(read_file): improve tool descriptions following Anthropic guidelines
- Add explicit 'when to use' guidance for slice and indentation modes - Add indentation mode example alongside existing slice example - Fix confusing 'indentation.anchor_line' text in mode description - Add 'when NOT to use' guidance in anchor_line description - Enhance descriptions to help non-OpenAI models choose appropriate mode This follows Anthropic's documented best practices for tool descriptions: - Explain what the tool does - Specify when to use and when NOT to use - Describe parameter impact - Aim for 3-4+ sentences
1 parent 5785b36 commit 68ef238

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ export function createReadFileTool(options: ReadFileToolOptions = {}): OpenAI.Ch
6464
const descriptionIntro =
6565
"Read a file and return its contents with line numbers for diffing or discussion. IMPORTANT: This tool reads exactly one file per call. If you need multiple files, issue multiple parallel read_file calls."
6666

67-
const modeDescription = ` Supports two modes: 'slice' (default) reads lines sequentially with offset/limit; 'indentation' extracts semantic code blocks around an anchor line based on indentation hierarchy.`
67+
const modeDescription =
68+
` Supports two modes: 'slice' (default) reads lines sequentially with offset/limit; 'indentation' extracts semantic code blocks around an anchor line based on indentation hierarchy.` +
69+
` Use slice mode when exploring a file from the beginning, reading configuration files, or when you don't have a specific line number to target.` +
70+
` Use indentation mode when you have a specific line number from search results, error messages, or definition lookups and want the full containing function/class without truncation.`
6871

6972
const limitNote = ` By default, returns up to ${DEFAULT_LINE_LIMIT} lines per file. Lines longer than ${MAX_LINE_LENGTH} characters are truncated.`
7073

@@ -74,13 +77,14 @@ export function createReadFileTool(options: ReadFileToolOptions = {}): OpenAI.Ch
7477
limitNote +
7578
" " +
7679
getReadFileSupportsNote(supportsImages) +
77-
` Example: { path: 'src/app.ts' }`
80+
` Example: { path: 'src/app.ts' }` +
81+
` Example (indentation mode): { path: 'src/app.ts', mode: 'indentation', indentation: { anchor_line: 42 } }`
7882

7983
const indentationProperties: Record<string, unknown> = {
8084
anchor_line: {
8185
type: "integer",
8286
description:
83-
"1-based line number to anchor indentation extraction (indentation mode). The block containing this line will be extracted with its context.",
87+
"1-based line number to anchor the extraction (required for indentation mode). The complete containing function, method, or class will be extracted with proper context. Typically obtained from search results, error stack traces, or definition lookups. If you don't have a specific line number, use slice mode instead.",
8488
},
8589
max_levels: {
8690
type: "integer",
@@ -112,7 +116,7 @@ export function createReadFileTool(options: ReadFileToolOptions = {}): OpenAI.Ch
112116
type: "string",
113117
enum: ["slice", "indentation"],
114118
description:
115-
"Reading mode. 'slice' (default): read lines sequentially with offset/limit. 'indentation': extract semantic code block around indentation.anchor_line based on indentation.",
119+
"Reading mode. 'slice' (default): read lines sequentially with offset/limit - use for general file exploration or when you don't have a target line number. 'indentation': extract complete semantic code blocks containing anchor_line - use when you have a line number and want the full function/class without truncation.",
116120
},
117121
offset: {
118122
type: "integer",

0 commit comments

Comments
 (0)