feat: built-in large tool output handling#2728
Open
yunus25jmi1 wants to merge 1 commit intodocker:mainfrom
Open
feat: built-in large tool output handling#2728yunus25jmi1 wants to merge 1 commit intodocker:mainfrom
yunus25jmi1 wants to merge 1 commit intodocker:mainfrom
Conversation
19c03e4 to
1771f43
Compare
1771f43 to
b657530
Compare
Add a new builtin hook that automatically handles large tool responses.
When enabled, tool responses exceeding the threshold are saved to disk
and replaced with a pointer that the agent can read back using shell
tools. This prevents large MCP tool responses from exhausting the
model's context window while still allowing the agent to access the
full data.
The feature is configured at the agent level:
handle_large_tool_output:
enabled: true
threshold: 5000 # characters (default)
output_dir: /tmp # default: os.TempDir()
preview_size: 3000 # chars in preview (default)
This is a root-cause fix for docker#2722 - it addresses both the lack of
MCP output limits and context window overflow issues.
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.
Summary
Add a new builtin hook that automatically handles large tool responses. When enabled, tool responses exceeding the threshold are saved to disk and replaced with a pointer that the agent can read back using shell tools.
This is a root-cause fix for issue #2722.
Problem
When an MCP tool returns a large response the agent breaks in one of two ways:
With default
max_old_tool_call_tokensbudget: A single large result eats the entire budget and all earlier tool results in the session get silently replaced with[content truncated].With
max_old_tool_call_tokens: -1: The full response stays in the session but overflows the model's context window. Auto-compaction can't help because the oversized result is in the most recent messages, so the agent gets stuck.Worth noting: builtin tools (shell, openapi, api) each have a hardcoded 30,000-char per-result limit. MCP tools have no per-result limit at all.
Root Cause
MCP tools have no output limit, unlike builtin tools (shell, openapi, api) which all have a hardcoded 30,000-char limit. When MCP returns large responses, they flow into the session unmodified.
Solution
Added a new builtin hook
handle_large_tool_outputthat:EventToolResponseTransformConfiguration
Files Changed
agent-schema.jsonhandle_large_tool_outputconfigpkg/config/latest/types.goHandleLargeToolOutputConfigstructpkg/agent/agent.gopkg/agent/opts.goWithHandleLargeToolOutputoptionpkg/teamloader/teamloader.gopkg/hooks/builtins/handle_large_tool_output.gopkg/hooks/builtins/builtins.gopkg/runtime/hooks.goTesting
Fixes #2722