feat(environment): stream lines in ReadFileTool to prevent OOM on large files
@sanketpatil06 ci sta già lavorando.
Dal 16/9/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Required Information
Is your feature request related to a specific problem?
Currently, ReadFileTool loads an entire file into memory as bytes via await self._environment.read_file(path) and then splits lines across the whole payload before slicing the requested range (start_line to end_line).
For very large files (hundreds of megabytes or gigabytes), reading the entire file into memory risks high memory usage or Out-Of-Memory (OOM) crashes in the agent environment, even when the caller only requests a small range of lines. There is an explicit TODO in src/google/adk/tools/environment/_read_file_tool.py:
# TODO: Avoid loading the entire file into memory to prevent OOM on large files.
Describe the Solution You'd Like
- Add a
read_file_lines(path, start_line, end_line)method toBaseEnvironmentwith a backward-compatible default fallback that callsread_file. - Implement an optimized, streaming
read_file_linesonLocalEnvironmentthat iterates through the file lazily line-by-line in $O(1)$ memory, only collecting the requested range. - Update
ReadFileTool.run_asyncto callread_file_lines, eliminating the need to buffer the entire file into memory.
Impact on your work
Improves stability and performance of file inspection tools in agent environments handling large log files, datasets, and source files.
Willingness to contribute
Yes, I have an implementation ready with unit tests and pre-commit checks passing.
Recommended Information
Proposed API / Implementation
# BaseEnvironment
async def read_file_lines(
self,
path: str | Path,
start_line: int = 1,
end_line: int | None = None,
) -> tuple[list[bytes], int]: ...
# LocalEnvironment
@staticmethod
def _sync_read_lines(
path: Path, start_line: int, end_line: int | None = None
) -> tuple[list[bytes], int]:
selected_lines: list[bytes] = []
total_lines = 0
with open(path, 'rb') as f:
for line in f:
total_lines += 1
if start_line <= total_lines and (
end_line is None or total_lines <= end_line
):
selected_lines.append(line)
return selected_lines, total_lines
- Lingua principale
- Python
- Stelle
- 21.6k
- Fork
- 4k
- Merge medio
- 13h 49m
- PR unite (30g)
- 10
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di google/adk-python
-
mcp
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
google/adk-python#7217 · 2 commenti · 1 assegnatario ·
-
tools
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
google/adk-python#7206 · 1 commento · 1 assegnatario ·
-
tools
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
google/adk-python#7205 · 1 commento · 1 assegnatario ·
-
mcp
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
google/adk-python#7196 · 1 commento · 1 assegnatario ·
-
eval request clarification
Difficoltà 1/5 1-3 ore Idoneità per principianti 86/100
google/adk-python#7146 · 2 commenti · 1 assegnatario ·
Tutte le issue di google/adk-python
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
use-agent-os/agent-os#3314 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
BasedHardware/omi#15662 · 1 commento ·
-
documentation help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
AiursoftWeb/AnduinOS-2#19 ·