Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ use tool_runtime::fs::document::{
is_supported_document_path, DocumentPageSelection, DocumentPagination, PdfTextCoverage,
};
use tool_runtime::fs::read_file::{
build_read_file_presentation, read_file_from_reader, read_file_tail_from_reader, ReadFileResult,
build_read_file_presentation_with_budget, read_file_from_reader, read_file_tail_from_reader,
ReadCallBudget, ReadFileResult, DEFAULT_READ_MAX_LINES,
};
#[cfg(any(feature = "document-read", feature = "tools-miniapp"))]
use tool_runtime::fs::read_file::{read_text, read_text_tail};
Expand All @@ -44,7 +45,8 @@ pub struct FileReadTool {
}

/// Default cap on characters returned by a single Read call (excluding wrapper text).
pub const DEFAULT_READ_MAX_TOTAL_CHARS: usize = 64_000;
pub const DEFAULT_READ_MAX_TOTAL_CHARS: usize =
tool_runtime::fs::read_file::DEFAULT_READ_MAX_TOTAL_CHARS;
// Coverage metadata remains complete; a tiny line window must not emit an unbounded gap list.
const MAX_PDF_OCR_PAGE_RANGES: usize = 32;
#[cfg(feature = "document-read")]
Expand Down Expand Up @@ -75,7 +77,7 @@ impl Default for FileReadTool {
impl FileReadTool {
pub fn new() -> Self {
Self {
default_max_lines_to_read: 2000,
default_max_lines_to_read: DEFAULT_READ_MAX_LINES,
max_line_chars: 2000,
max_total_chars: DEFAULT_READ_MAX_TOTAL_CHARS,
}
Expand All @@ -93,6 +95,10 @@ impl FileReadTool {
}
}

fn call_budget(&self) -> ReadCallBudget {
ReadCallBudget::new(self.default_max_lines_to_read, self.max_total_chars)
}

fn already_served_result(
logical_path: &str,
coverage: crate::agentic::session::ReviewReadCoverage,
Expand Down Expand Up @@ -356,9 +362,11 @@ Use pages to select units after inspecting page_kind/page_count, especially when

Ok(format!(
r#"Read a file from the active workspace, including a remote workspace. Use LS/Glob for directories and an image tool for images.
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.
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.
{document_guidance}"#,
self.default_max_lines_to_read, self.max_line_chars, self.max_total_chars
max_lines = self.default_max_lines_to_read,
max_total_chars = self.max_total_chars,
max_line_chars = self.max_line_chars,
))
}

Expand Down Expand Up @@ -387,7 +395,7 @@ Returns numbered lines (line number, tab, text). Choose the window needed for th
},
"limit": {
"type": "number",
"description": "Positive integer number of lines to return. Choose a window that covers the relevant context."
"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."
}
},
"required": ["file_path"],
Expand Down Expand Up @@ -679,8 +687,11 @@ Returns numbered lines (line number, tab, text). Choose the window needed for th
)
}
.map_err(OpenBitFunError::tool)?;
let presentation =
build_read_file_presentation(&resolved.logical_path, &read_file_result);
let presentation = build_read_file_presentation_with_budget(
&resolved.logical_path,
&read_file_result,
self.call_budget(),
);
return Ok(vec![ToolResult::Result {
data: json!({
"file_path": resolved.logical_path,
Expand Down Expand Up @@ -832,7 +843,11 @@ Returns numbered lines (line number, tab, text). Choose the window needed for th
}
}

let presentation = build_read_file_presentation(&resolved.logical_path, &read_file_result);
let presentation = build_read_file_presentation_with_budget(
&resolved.logical_path,
&read_file_result,
self.call_budget(),
);
let mut result_for_assistant = presentation.result_for_assistant;

let mut data = json!({
Expand Down Expand Up @@ -920,7 +935,7 @@ Returns numbered lines (line number, tab, text). Choose the window needed for th
} else {
"keep pages omitted".to_string()
};
format!("To continue this extraction, {same_selection} and use offset={next_offset}; or choose a narrower pages range starting at offset=1.")
format!("To continue this extraction, {same_selection} and use offset={next_offset} without limit; or choose a narrower pages range starting at offset=1.")
} else {
"Choose another pages range if more context is needed.".to_string()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ use openbitfun_agent_tools::{DEFAULT_MAX_TOOL_RESULT_CHARS, PERSISTED_OUTPUT_TAG
use std::collections::HashSet;
use std::path::Path;

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

const READ_TOOL_NAME: &str = "Read";

Expand Down
Loading
Loading