-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat: add line_range support to simpleReadFileTool and improve truncation notices #10240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…tion notices This PR addresses Issue #10239 by: 1. Adding line_range parameter support to simpleReadFileTool - Models using the simple read_file tool can now use <line_range>start-end</line_range> - Enables incremental file reading for models that previously could not continue reading truncated files 2. Improving truncation notices across both tools to include: - The exact next line number to continue from - A concrete example of the syntax to use (e.g., <line_range>501-1000</line_range>) 3. Updated tool description in simple-read-file.ts to document the new parameter Files modified: - src/core/prompts/tools/simple-read-file.ts - src/core/tools/simpleReadFileTool.ts - src/core/tools/ReadFileTool.ts - src/shared/tools.ts (added line_range to toolParamNames)
Review complete. No issues found. The latest commit addresses @pwilkin's feedback by always including Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
src/core/tools/ReadFileTool.ts
Outdated
| ) | ||
| if (defResult) { | ||
| const notice = `Showing only ${maxReadFileLine} of ${totalLines} total lines. Use line_range if you need to read more lines` | ||
| const notice = `Showing only definitions of ${totalLines} total lines. To read actual content, use the read_file tool again with the line_range parameter (e.g., line_ranges: [[1, 500]])` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roomote Seems like you have an error in the new message here:
const notice = Showing only definitions of ${totalLines} total lines. To read actual content, use the read_file tool again with the line_range parameter (e.g., line_ranges: [[1, 500]])
Fixed the parameter name inconsistency: changed "line_range parameter" to "line_ranges parameter" in all 3 truncation notice messages to match the example syntax. All local checks passed. |
|
@roomote Also, can you please check the logic for src/core/prompts/tools/read-file.ts whether the partialReads parameter is always enabled when there is a context limit? Because another reason I can imagine this error happening is if the tool description doesn't actually mention the line_range parameter. |
Fixed the reported issue. The |
The tool description now always includes line_range information regardless of the partialReadsEnabled setting. This fixes an issue where files could be truncated due to context/token budget limits but the tool description would not mention line_range if maxReadFileLine was set to -1 (unlimited). This ensures models always know how to continue reading truncated files, whether the truncation was due to line limits or context budget constraints.
This PR attempts to address Issue #10239.
Summary
This PR adds
line_rangeparameter support tosimpleReadFileTooland improves truncation notices across both read file tools to provide clearer instructions for incremental file reading.Problem
As identified in the issue,
simpleReadFileTool(used by models that only support single file reads) did NOT support line ranges. This was explicitly stated in the code comments:When files were truncated, the tool would suggest using
line_rangebut the tool could not actually process that parameter, causing models to repeatedly re-read from line 1.Changes
1. Added
line_rangeparameter support tosimpleReadFileToolparseLineRange()helper function to parse "start-end" formatline_rangetotoolParamNamesinsrc/shared/tools.tsreadLinesfunctionsimple-read-file.tswith examples2. Improved truncation notices
Updated truncation messages across both tools to include:
Before:
After:
Files Modified
src/core/prompts/tools/simple-read-file.ts- Updated tool description with line_range parametersrc/core/tools/simpleReadFileTool.ts- Added line_range parsing and handlingsrc/core/tools/ReadFileTool.ts- Improved truncation noticessrc/shared/tools.ts- Added line_range to toolParamNamesTesting
Feedback and guidance are welcome!