bug(core): Prompt engineering for truncated read_file. (#5161)

This commit is contained in:
joshualitt
2025-08-06 13:52:04 -07:00
committed by GitHub
parent ad5d2af4e3
commit 43510ed212
6 changed files with 77 additions and 36 deletions

View File

@@ -222,7 +222,7 @@ describe('ReadFileTool', () => {
});
});
it('should pass offset and limit to read a slice of a text file', async () => {
it('should return a structured message when a slice of a text file is read', async () => {
const filePath = path.join(tempRootDir, 'paginated.txt');
const fileContent = Array.from(
{ length: 20 },
@@ -240,15 +240,22 @@ describe('ReadFileTool', () => {
ToolResult
>;
expect(await invocation.execute(abortSignal)).toEqual({
llmContent: [
'[File content truncated: showing lines 6-8 of 20 total lines. Use offset/limit parameters to view more.]',
'Line 6',
'Line 7',
'Line 8',
].join('\n'),
returnDisplay: 'Read lines 6-8 of 20 from paginated.txt',
});
const result = await invocation.execute(abortSignal);
const expectedLlmContent = `
IMPORTANT: The file content has been truncated.
Status: Showing lines 6-8 of 20 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: 8.
--- FILE CONTENT (truncated) ---
Line 6
Line 7
Line 8`;
expect(result.llmContent).toEqual(expectedLlmContent);
expect(result.returnDisplay).toBe(
'Read lines 6-8 of 20 from paginated.txt',
);
});
describe('with .geminiignore', () => {