Skip to content

Commit f219bee

Browse files
authored
Merge pull request #3723 from Raing5Days/feat/read-continuation-guidance
perf(read): tell the model how much one more call can still return
2 parents 03dd599 + f6bf475 commit f219bee

3 files changed

Lines changed: 261 additions & 35 deletions

File tree

‎src/crates/assembly/core/src/agentic/tools/implementations/file_read_tool.rs‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ use tool_runtime::fs::document::{
3232
is_supported_document_path, DocumentPageSelection, DocumentPagination, PdfTextCoverage,
3333
};
3434
use tool_runtime::fs::read_file::{
35-
build_read_file_presentation, read_file_from_reader, read_file_tail_from_reader, ReadFileResult,
35+
build_read_file_presentation_with_budget, read_file_from_reader, read_file_tail_from_reader,
36+
ReadCallBudget, ReadFileResult, DEFAULT_READ_MAX_LINES,
3637
};
3738
#[cfg(any(feature = "document-read", feature = "tools-miniapp"))]
3839
use tool_runtime::fs::read_file::{read_text, read_text_tail};
@@ -44,7 +45,8 @@ pub struct FileReadTool {
4445
}
4546

4647
/// Default cap on characters returned by a single Read call (excluding wrapper text).
47-
pub const DEFAULT_READ_MAX_TOTAL_CHARS: usize = 64_000;
48+
pub const DEFAULT_READ_MAX_TOTAL_CHARS: usize =
49+
tool_runtime::fs::read_file::DEFAULT_READ_MAX_TOTAL_CHARS;
4850
// Coverage metadata remains complete; a tiny line window must not emit an unbounded gap list.
4951
const MAX_PDF_OCR_PAGE_RANGES: usize = 32;
5052
#[cfg(feature = "document-read")]
@@ -75,7 +77,7 @@ impl Default for FileReadTool {
7577
impl FileReadTool {
7678
pub fn new() -> Self {
7779
Self {
78-
default_max_lines_to_read: 2000,
80+
default_max_lines_to_read: DEFAULT_READ_MAX_LINES,
7981
max_line_chars: 2000,
8082
max_total_chars: DEFAULT_READ_MAX_TOTAL_CHARS,
8183
}
@@ -93,6 +95,10 @@ impl FileReadTool {
9395
}
9496
}
9597

98+
fn call_budget(&self) -> ReadCallBudget {
99+
ReadCallBudget::new(self.default_max_lines_to_read, self.max_total_chars)
100+
}
101+
96102
fn already_served_result(
97103
logical_path: &str,
98104
coverage: crate::agentic::session::ReviewReadCoverage,
@@ -356,9 +362,11 @@ Use pages to select units after inspecting page_kind/page_count, especially when
356362

357363
Ok(format!(
358364
r#"Read a file from the active workspace, including a remote workspace. Use LS/Glob for directories and an image tool for images.
359-
Returns numbered lines (line number, tab, text). Choose the window needed for the task; the default is up to {} lines. File content is capped at {} characters per line and {} characters per call. Follow next_offset for additional lines when useful. A truncated line needs another inspection method; rereading the same line window cannot recover its omitted characters. Use only complete source text for Edit.
365+
Returns numbered lines (line number, tab, text). Prefer one call per file: omit limit to use the whole per-call budget of up to {max_lines} lines and {max_total_chars} characters in total, which covers most files at once. Set offset/limit only for a range you already know, or after Grep located it in a file larger than that budget; do not page a large file window by window. The continuation note states how many lines remain and whether one more call can return all of them. Separately, each returned line is capped at {max_line_chars} characters and a longer line ends with [truncated]. A truncated line needs another inspection method; rereading the same line window cannot recover its omitted characters. Use only complete source text for Edit.
360366
{document_guidance}"#,
361-
self.default_max_lines_to_read, self.max_line_chars, self.max_total_chars
367+
max_lines = self.default_max_lines_to_read,
368+
max_total_chars = self.max_total_chars,
369+
max_line_chars = self.max_line_chars,
362370
))
363371
}
364372

@@ -387,7 +395,7 @@ Returns numbered lines (line number, tab, text). Choose the window needed for th
387395
},
388396
"limit": {
389397
"type": "number",
390-
"description": "Positive integer number of lines to return. Choose a window that covers the relevant context."
398+
"description": "Positive integer number of lines to return. Omit it to read up to the full per-call budget in one call; set it only when a specific range is enough."
391399
}
392400
},
393401
"required": ["file_path"],
@@ -679,8 +687,11 @@ Returns numbered lines (line number, tab, text). Choose the window needed for th
679687
)
680688
}
681689
.map_err(OpenBitFunError::tool)?;
682-
let presentation =
683-
build_read_file_presentation(&resolved.logical_path, &read_file_result);
690+
let presentation = build_read_file_presentation_with_budget(
691+
&resolved.logical_path,
692+
&read_file_result,
693+
self.call_budget(),
694+
);
684695
return Ok(vec![ToolResult::Result {
685696
data: json!({
686697
"file_path": resolved.logical_path,
@@ -832,7 +843,11 @@ Returns numbered lines (line number, tab, text). Choose the window needed for th
832843
}
833844
}
834845

835-
let presentation = build_read_file_presentation(&resolved.logical_path, &read_file_result);
846+
let presentation = build_read_file_presentation_with_budget(
847+
&resolved.logical_path,
848+
&read_file_result,
849+
self.call_budget(),
850+
);
836851
let mut result_for_assistant = presentation.result_for_assistant;
837852

838853
let mut data = json!({
@@ -920,7 +935,7 @@ Returns numbered lines (line number, tab, text). Choose the window needed for th
920935
} else {
921936
"keep pages omitted".to_string()
922937
};
923-
format!("To continue this extraction, {same_selection} and use offset={next_offset}; or choose a narrower pages range starting at offset=1.")
938+
format!("To continue this extraction, {same_selection} and use offset={next_offset} without limit; or choose a narrower pages range starting at offset=1.")
924939
} else {
925940
"Choose another pages range if more context is needed.".to_string()
926941
};

‎src/crates/assembly/core/src/agentic/tools/tool_result_storage.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ use openbitfun_agent_tools::{DEFAULT_MAX_TOOL_RESULT_CHARS, PERSISTED_OUTPUT_TAG
1919
use std::collections::HashSet;
2020
use std::path::Path;
2121

22-
/// Keep in sync with `FileReadTool::DEFAULT_READ_MAX_TOTAL_CHARS` plus wrapper overhead.
23-
pub(crate) const READ_MAX_TOOL_RESULT_CHARS: usize = 72_000;
22+
/// Read's own per-call content cap plus room for its wrapper text, so a full
23+
/// default Read window is returned inline instead of being persisted.
24+
pub(crate) const READ_MAX_TOOL_RESULT_CHARS: usize =
25+
crate::agentic::tools::implementations::file_read_tool::DEFAULT_READ_MAX_TOTAL_CHARS + 8_000;
2426

2527
const READ_TOOL_NAME: &str = "Read";
2628

0 commit comments

Comments
 (0)