Skip to content

agent: Offload oversized tool results to a temp file#59228

Open
ebertn wants to merge 1 commit into
zed-industries:mainfrom
ebertn:agent-offload-large-tool-output
Open

agent: Offload oversized tool results to a temp file#59228
ebertn wants to merge 1 commit into
zed-industries:mainfrom
ebertn:agent-offload-large-tool-output

Conversation

@ebertn

@ebertn ebertn commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

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_limit setting (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 to grep/sed/cat the file).

Details:

  • 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 output (raw output used for the UI/replay) is left untouched.
  • A limit of 0 disables offloading and always sends full tool output inline.
  • 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 (previously they silently did nothing), so the offloaded temp file and other out-of-project mentions open on click.
  • Files are written under 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_file falls back to an outline above 16 KiB, the terminal tool has its own byte limit, grep paginates).

Screenshot 2026-06-12 at 4 49 13 PM

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content adheres to Zed's UI standards (UX/UI and icon guidelines)
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Added an agent.tool_output_inline_limit setting 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.

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jun 12, 2026
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.
@ebertn ebertn force-pushed the agent-offload-large-tool-output branch from 93adbdc to 2f6d0c4 Compare June 12, 2026 23:50
@ebertn ebertn marked this pull request as ready for review June 12, 2026 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant