agent: Offload oversized tool results to a temp file#59228
Open
ebertn wants to merge 1 commit into
Open
Conversation
Large tool results, commonly from MCP/context server tools, can overflow the model's context window and break the agent mid-turn. Cap how much tool result text is sent inline to the model. When a single tool result's text exceeds the new agent.tool_output_inline_limit setting (default 64 KiB), write the full output to a per-thread file under the OS temp directory (std::env::temp_dir()/zed-tool-output/<thread_id>/) and send the model a short notice with the file path and a preview instead. The agent can then inspect only what it needs (e.g. via the terminal tool). - Applied at the central Thread::run_tool choke point, so it covers every tool (built-in and MCP/context server tools). - Only the model-facing content is rewritten; image parts are preserved, and the raw output used for the UI/replay is left untouched. - A limit of 0 disables offloading. - The tool call card shows a notice that the output was cached plus a clickable link that opens the full output file. Agent panel file links now fall back to opening by absolute path when the file is outside any worktree, so the offloaded temp file and other out-of-project mentions open on click instead of doing nothing. - The OS reclaims the files via its normal temp cleanup.
93adbdc to
2f6d0c4
Compare
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.
Large tool results, commonly from MCP/context server tools, can overflow the model's context window and cause the agent to break mid-turn.
This caps how much tool result text is sent inline to the model. When a single tool result's text exceeds the new
agent.tool_output_inline_limitsetting (default 64 KiB), the full output is written to a per-thread file under the OS temp directory and the model instead receives a short notice containing the file path and a preview. The agent can then inspect only what it needs (for example, via the terminal tool togrep/sed/catthe file).Details:
Thread::run_toolchoke point, so it covers every tool (built-in and MCP/context server tools).contentis rewritten; image parts are preserved, and theoutput(raw output used for the UI/replay) is left untouched.0disables offloading and always sends full tool output inline.std::env::temp_dir()/zed-tool-output/<thread_id>/so the OS reclaims them via its normal temp cleanup.Built-in tools rarely trip the default because they already bound their output (e.g.
read_filefalls back to an outline above 16 KiB, the terminal tool has its own byte limit, grep paginates).Self-Review Checklist:
Release Notes:
agent.tool_output_inline_limitsetting that offloads oversized tool results (including from MCP servers) to a temporary file with a preview and a clickable link, instead of sending them inline and overflowing the model's context window.