Skip to content

Add git_diff tool; truncate patch in changed_files to cut LLM cost#2552

Merged
hiroshinishio merged 1 commit intomainfrom
wes
Apr 18, 2026
Merged

Add git_diff tool; truncate patch in changed_files to cut LLM cost#2552
hiroshinishio merged 1 commit intomainfrom
wes

Conversation

@hiroshinishio
Copy link
Copy Markdown
Collaborator

@hiroshinishio hiroshinishio commented Apr 18, 2026

Summary

  • Add git_diff tool so the agent can fetch diffs on demand per file instead of embedding the full patch in every LLM message (was 101K+ chars repeated across 30+ calls)
  • Truncate patch field in changed_files to 1,000 chars before serializing to the first LLM message in check_suite_handler
  • Together these changes target the root cause of a $56 single-PR cost blow-up (foxcom-forms Schedule: Add unit tests to services/webhook/utils/create_test_selection_comment.py #1152)

Social Media Post (GitAuto)

New: git_diff tool for on-demand diffs

  • Agent now fetches file diffs only when needed instead of carrying the full patch in every message
  • Large patches are truncated before entering the LLM conversation to keep costs proportional to PR size

Social Media Post (Wes)

One PR cost us $56 yesterday. Traced it to a 101K-char diff copy-pasted into every single LLM call, 30 times. The fix: let the agent pull diffs on demand instead of front-loading everything. Obvious in hindsight.

- New git_diff tool lets the agent fetch diffs on demand per file
  instead of embedding the full patch (101K+) in every LLM message
- Truncate patch field in changed_files to 1000 chars in
  check_suite_handler before serializing to the first LLM message
- Add tests for git_diff, patch truncation, and tool registration
@hiroshinishio hiroshinishio self-assigned this Apr 18, 2026
@hiroshinishio hiroshinishio merged commit 41b84af into main Apr 18, 2026
1 check passed
@hiroshinishio hiroshinishio deleted the wes branch April 18, 2026 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant