Skip to content

fix(adk): avoid reduction/filesystem read_file loops on large tool results - #1093

Open
014-code wants to merge 2 commits into
cloudwego:mainfrom
014-code:issue-860-reduction-filesystem-conflict
Open

fix(adk): avoid reduction/filesystem read_file loops on large tool results#1093
014-code wants to merge 2 commits into
cloudwego:mainfrom
014-code:issue-860-reduction-filesystem-conflict

Conversation

@014-code

Copy link
Copy Markdown

Summary

This fixes the conflict between reduction and filesystem middleware described in #860.

When a large tool result is truncated or offloaded and the agent uses read_file to fetch it back, the returned content should not be truncated, cleared, or offloaded again by default. This change also adds column-based pagination to read_file so very long single-line content can be read incrementally.

What changed

  • exclude read_file from default reduction truncation and clearing
  • exclude read_file from legacy large tool result offloading paths
  • add column_offset and column_limit to read_file
  • paginate long single-line content with continuation hints
  • update English and Chinese prompts/tool descriptions to document column-based reads
  • normalize virtual in-memory/offload paths to slash-based filesystem paths across platforms

Tests

New coverage added:

  • TestReadFileTool_LongSingleLineColumnPagination
  • TestToolResultOffloading_ExcludeTools
  • TestNewToolResultMiddleware_ExcludesReadFileFromClear
  • TestToolResultOffloading_SkipReadFileTool
  • TestReductionMiddlewareTrunc/read_file tool is not truncated by default
  • TestReductionMiddlewareClear/read_file tool is not cleared by default

Passed:

  • go test ./adk/middlewares/filesystem ./adk/middlewares/reduction

Also checked:

  • gofmt on modified files
  • git diff --check

Notes

A full go test ./... run still reports unrelated failures in other packages on this Windows environment, including:

  • adk/middlewares/agentsmd
  • adk/middlewares/plantask
  • adk/middlewares/skill
  • components/document/parser

Those failures are not introduced by this change and are outside the scope of #860.

Exclude read_file results from default truncation and clearing so offloaded
content can be read back without being re-offloaded or cleared again.

Add column-based pagination to the filesystem read_file tool to make very long
single-line files readable in chunks, and update the tool prompts to document
column_offset and column_limit.

Also normalize in-memory backend and default reduction offload paths to use
slash-based virtual filesystem paths consistently across platforms.
@CLAassistant

CLAassistant commented Jun 21, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.75000% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.23%. Comparing base (e8832e2) to head (a2062af).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
adk/middlewares/filesystem/filesystem.go 78.18% 6 Missing and 6 partials ⚠️
adk/filesystem/backend_inmemory.go 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1093      +/-   ##
==========================================
+ Coverage   83.11%   83.23%   +0.12%     
==========================================
  Files         162      162              
  Lines       23134    23191      +57     
==========================================
+ Hits        19228    19304      +76     
+ Misses       2640     2618      -22     
- Partials     1266     1269       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

… cases

Rename the sliced read_file line variable to avoid shadowing in
formatLineNumbers.

Add coverage for column pagination edge cases, including disabled column
limits, out-of-range offsets, empty lines, and windows-style path
normalization in the in-memory backend.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants