Reduce ToolReturn.attachments under ToolOutputLimits

Closed
KU
4d ago
+274-34

Summary

  • Apply ToolOutputLimits bands to each text item in ToolReturn.attachments (nested-tool content such as Code Mode's), independently of return_value / content.
  • Keep each attachment's tool_call_id, tool_name, and capability_id; put the truncation or spill note on that attachment. File attachments pass through. Spilled attachments record overflow_attachment_handles in metadata.
  • Docs and skill text updated to match.

Closes #15002.
Follow-up to #14479 (this PR is stacked on tool-return-content-carrier).

Test plan

  • uv run --no-sync pytest -p no:cacheprovider tests/harness/tool_output_limits
  • New TestAttachmentReduction cases (truncate, spill, only-attachments, per-item, TextContent, file passthrough, combined)
  • Docs parity for tool-output-limits
  • Ruff + basedpyright on changed paths

Summary by cubic

Reduces oversized text in ToolReturn.attachments so nested-tool content, such as Code Mode's, no longer reaches the model unreduced. Text attachments are now measured and reduced independently with the same ToolOutputLimits bands used for return_value and content, while preserving each attachment's tool_call_id, tool_name, and capability_id. Truncation or spill notes are placed on the attachment itself; file attachments pass through unchanged. Spilled attachments record overflow_attachment_handles in ToolReturn.metadata, keyed per attachment's tool_call_id. Docs and skill references updated to match. Closes #15002.