feat(tools): add universal tool result budgeting for large outputs#2814
Open
chinesepowered wants to merge 1 commit intoQwenLM:mainfrom
Open
feat(tools): add universal tool result budgeting for large outputs#2814chinesepowered wants to merge 1 commit intoQwenLM:mainfrom
chinesepowered wants to merge 1 commit intoQwenLM:mainfrom
Conversation
Apply truncation to all tool results in the core scheduler, not just shell and MCP tools. When a tool returns output exceeding the configured threshold, the full result is persisted to disk and a truncated version with head/tail preview + file path is sent to the model.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Apply universal tool result budgeting so all tools benefit from large output truncation and disk persistence, not just shell and MCP.
TLDR
Adds universal tool result truncation in the core tool scheduler. Previously, only
run_shell_commandand MCP tools truncated oversized outputs. Now ALL tool results (grep, glob, read_file, edit, etc.) are subject to the same budgeting: when output exceeds the configured threshold (default 25,000 chars / 1,000 lines), the full result is saved to a temp file and a truncated head/tail preview with a file path pointer is sent to the model.Screenshots / Video Demo
N/A — no user-facing UI change. The behavior is the same truncation users already see for shell output, now applied universally.
Dive Deeper
coreToolScheduler.ts(line ~1481) — afterexecute()returns but beforeconvertToFunctionResponse()builds the chat history entrytruncateToolOutput()utility fromutils/truncation.tswhich handles threshold checking, head/tail extraction, disk persistence, and telemetry loggingtools.truncateToolOutputThresholdandtools.truncateToolOutputLinesllmContent— media results (images, PDFs) are unaffectedModified files:
packages/core/src/core/coreToolScheduler.ts— Added universal truncation + importReviewer Test Plan
read_fileon the temp file path — verify full content is accessiblenpx vitest run src/core/coreToolScheduler.test.ts(all 53 pass)Testing Matrix
Linked issues / bugs
New feature to prevent context window waste from oversized tool outputs.
Fixes #2818