summaryrefslogtreecommitdiff
path: root/packages/core/src/tools/read-file.ts
diff options
context:
space:
mode:
authorjoshualitt <[email protected]>2025-08-06 13:52:04 -0700
committerGitHub <[email protected]>2025-08-06 20:52:04 +0000
commit43510ed212ea29b7bd752277de525f7821551b22 (patch)
treeb49f31ec75804e2b742b2651714066211421c3ab /packages/core/src/tools/read-file.ts
parentad5d2af4e34fd23391bb6a0270cc320a0e56ba88 (diff)
bug(core): Prompt engineering for truncated read_file. (#5161)
Diffstat (limited to 'packages/core/src/tools/read-file.ts')
-rw-r--r--packages/core/src/tools/read-file.ts24
1 files changed, 21 insertions, 3 deletions
diff --git a/packages/core/src/tools/read-file.ts b/packages/core/src/tools/read-file.ts
index 3a05da06..7ef9d2b5 100644
--- a/packages/core/src/tools/read-file.ts
+++ b/packages/core/src/tools/read-file.ts
@@ -14,7 +14,7 @@ import {
ToolLocation,
ToolResult,
} from './tools.js';
-import { Type } from '@google/genai';
+import { PartUnion, Type } from '@google/genai';
import {
processSingleFileContent,
getSpecificMimeType,
@@ -84,6 +84,24 @@ class ReadFileToolInvocation
};
}
+ let llmContent: PartUnion;
+ if (result.isTruncated) {
+ const [start, end] = result.linesShown!;
+ const total = result.originalLineCount!;
+ const nextOffset = this.params.offset
+ ? this.params.offset + end - start + 1
+ : end;
+ llmContent = `
+IMPORTANT: The file content has been truncated.
+Status: Showing lines ${start}-${end} of ${total} total lines.
+Action: To read more of the file, you can use the 'offset' and 'limit' parameters in a subsequent 'read_file' call. For example, to read the next section of the file, use offset: ${nextOffset}.
+
+--- FILE CONTENT (truncated) ---
+${result.llmContent}`;
+ } else {
+ llmContent = result.llmContent || '';
+ }
+
const lines =
typeof result.llmContent === 'string'
? result.llmContent.split('\n').length
@@ -98,7 +116,7 @@ class ReadFileToolInvocation
);
return {
- llmContent: result.llmContent || '',
+ llmContent,
returnDisplay: result.returnDisplay || '',
};
}
@@ -117,7 +135,7 @@ export class ReadFileTool extends BaseDeclarativeTool<
super(
ReadFileTool.Name,
'ReadFile',
- 'Reads and returns the content of a specified file from the local filesystem. Handles text, images (PNG, JPG, GIF, WEBP, SVG, BMP), and PDF files. For text files, it can read specific line ranges.',
+ `Reads and returns the content of a specified file. If the file is large, the content will be truncated. The tool's response will clearly indicate if truncation has occurred and will provide details on how to read more of the file using the 'offset' and 'limit' parameters. Handles text, images (PNG, JPG, GIF, WEBP, SVG, BMP), and PDF files. For text files, it can read specific line ranges.`,
Icon.FileSearch,
{
properties: {