Skip to content

feat: add per-file byte cap and budget-aware truncation to agentsmd - #1235

Merged
mrh997 merged 1 commit into
mainfrom
fix/mrh/agentsmd
Sep 1, 2026
Merged

mrh997 merged 1 commit into
mainfrom
fix/mrh/agentsmd

Conversation

@mrh997

@mrh997 mrh997 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

The agentsmd middleware previously always loaded each individual AGENTS.md file in full and only skipped later files once the cumulative budget was exceeded, so a single oversized file could blow past AllAgentsMDMaxBytes unbounded. This change makes the byte limits authoritative: content is now truncated to fit the budget rather than admitted whole, and the model is told what was cut or omitted.

API Changes

  1. Added: Config.PerAgentsMDMaxBytes — caps the byte size of each individual AGENTS.md file (including @imported ones); a larger file is truncated to the limit with a notice appended. 0 means no per-file limit.

Key Changes

  1. AllAgentsMDMaxBytes now applies to every file, including the first. When loading a file would cross the cumulative budget, it is truncated to the remaining budget if at least 500 bytes remain, otherwise dropped whole; either way no further files load.
  2. Truncation happens on UTF-8 rune boundaries, so multibyte (e.g. Chinese) characters are never split.
  3. A truncated file gets a bracketed notice reporting bytes cut and original size; top-level files skipped because the budget ran out are listed in a summary line before the footer.
  4. A truncated file is not scanned for @imports, since pulling in more content would defeat the cap it just hit.
  5. Fixed an incorrect error string (AllAgentMDDocsMaxBytes → AllAgentsMDMaxBytes) and added validation for the new field.

@mrh997 mrh997 changed the title feat(agentsmd): add per-file byte cap and budget-aware truncation feat: add per-file byte cap and budget-aware truncation to agentsmd Sep 1, 2026
@codecov

codecov Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.78%. Comparing base (60e1d99) to head (9cc93f6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1235      +/-   ##
==========================================
+ Coverage   83.71%   83.78%   +0.06%     
==========================================
  Files         162      162              
  Lines       23887    23940      +53     
==========================================
+ Hits        19998    20057      +59     
+ Misses       2628     2623       -5     
+ Partials     1261     1260       -1     

☔ 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.

Comment thread adk/middlewares/agentsmd/loader.go
Comment thread adk/middlewares/agentsmd/loader.go
Comment thread adk/middlewares/agentsmd/agentsmd.go Outdated
Add PerAgentsMDMaxBytes to cap each AGENTS.md file individually, make
AllAgentsMDMaxBytes apply to the first file too, and truncate (or drop)
the file that crosses the cumulative budget instead of skipping it wholesale.
Truncated files carry a notice and dropped files are summarized at the end.
@mrh997
mrh997 merged commit 9d983b3 into main Sep 1, 2026
19 checks passed
@mrh997
mrh997 deleted the fix/mrh/agentsmd branch September 1, 2026 12:38
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.

3 participants