Simplify view file tool. Limit viewing upto 50 lines at a time

We were previously truncating by characters. Limiting by max lines
allows model to control line ranges they request
This commit is contained in:
Debanjum
2025-08-19 16:37:32 -07:00
parent f5a4d106d1
commit f483a626b8
2 changed files with 25 additions and 29 deletions

View File

@@ -2916,9 +2916,6 @@ async def view_file_content(
raw_text = file_object.raw_text raw_text = file_object.raw_text
# Apply line range filtering if specified # Apply line range filtering if specified
if start_line is None and end_line is None:
filtered_text = raw_text
else:
lines = raw_text.split("\n") lines = raw_text.split("\n")
start_line = start_line or 1 start_line = start_line or 1
end_line = end_line or len(lines) end_line = end_line or len(lines)
@@ -2939,15 +2936,14 @@ async def view_file_content(
start_idx = max(0, start_line - 1) start_idx = max(0, start_line - 1)
end_idx = min(len(lines), end_line) end_idx = min(len(lines), end_line)
selected_lines = lines[start_idx:end_idx] # Limit to first 50 lines if more than 50 lines are requested
filtered_text = "\n".join(selected_lines) truncation_message = ""
if end_idx - start_idx > 50:
truncation_message = "\n\n[Truncated after 50 lines! Use narrower line range to view complete section.]"
end_idx = start_idx + 50
# Truncate the text if it's too long selected_lines = lines[start_idx:end_idx]
if len(filtered_text) > 10000: filtered_text = "\n".join(selected_lines) + truncation_message
filtered_text = (
filtered_text[:10000]
+ "\n\n[Truncated after first 10K characters! Use narrower line range to view complete section.]"
)
# Format the result as a document reference # Format the result as a document reference
document_results = [ document_results = [

View File

@@ -567,7 +567,7 @@ tools_for_research_llm = {
To view the contents of specific note or document in the user's personal knowledge base. To view the contents of specific note or document in the user's personal knowledge base.
Especially helpful if the question expects context from the user's notes or documents. Especially helpful if the question expects context from the user's notes or documents.
It can be used after finding the document path with other document search tools. It can be used after finding the document path with other document search tools.
Specify a line range to view only specific sections of files. Especially useful to read large files. Specify a line range to efficiently read relevant sections of a file. You can view up to 50 lines at a time.
""" """
).strip(), ).strip(),
schema={ schema={