Skip to content

Feature Request: Universal Tool Result Budgeting for Large Outputs #2818

@chinesepowered

Description

@chinesepowered

What would you like to be added?

Feature Request: Universal Tool Result Budgeting for Large Outputs

Problem

Currently, only run_shell_command and MCP tools truncate oversized outputs before they enter the chat history. Other tools like grep_search, glob, read_file, and edit can return arbitrarily large results that consume significant context window space. This wastes tokens and can push conversations toward compression sooner than necessary.

The existing truncateToolOutput() utility in utils/truncation.ts already handles threshold checking, head/tail extraction, disk persistence, and telemetry logging -- but it's only wired into shell and MCP tool paths.

Proposed Solution

Add a single universal truncation integration point in coreToolScheduler.ts, after a tool's execute() returns but before convertToFunctionResponse() builds the chat history entry:

  • Check if the tool result is a string and exceeds the configured threshold (default 25,000 chars / 1,000 lines)
  • If so, save the full result to a temp file and replace it with a truncated head/tail preview plus a pointer to the full output file
  • Tools that already self-truncate (shell, MCP) pass through harmlessly since their output is already under the threshold
  • Only applies to string llmContent -- media results (images, PDFs) are unaffected
  • Respects existing user-configurable thresholds: tools.truncateToolOutputThreshold and tools.truncateToolOutputLines

Scope

  • Changes to packages/core/src/core/coreToolScheduler.ts (add universal truncation + import)

Impact

High (better context management). Medium effort. Single-file change.

Why is this needed?

Currently, only run_shell_command and MCP tools truncate oversized outputs before they enter the chat history. Other tools like grep_search, glob, read_file, and edit can return arbitrarily large results that consume significant context window space. This wastes tokens and can push conversations toward compression sooner than necessary.

The existing truncateToolOutput() utility in utils/truncation.ts already handles threshold checking, head/tail extraction, disk persistence, and telemetry logging -- but it's only wired into shell and MCP tool paths.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions