Skip to content

Design: Tool Result Compression for context budget optimization #443

@RyderFreeman4Logos

Description

@RyderFreeman4Logos

Problem

Large tool outputs consume context budget disproportionately. When agents invoke tools that produce verbose output (e.g., large git diffs, compilation errors, search results), the raw output fills the context window, forcing premature compaction and degrading reasoning quality.

Current Mitigations

  • Tail buffer: 1 MiB (collect_agent_output ring buffer)
  • Spool: 32 MiB per session (spool_file in session dir)
  • Event ring buffer: 10K events
  • CSA:SECTION markers for structured output parsing

Constraints (must not break)

  • Session replay (csa session result/logs)
  • Fork-call-return (ReturnPacket protocol)
  • CSA:SECTION markers parsing
  • output/index.toml manifest

Proposed Direction

Add an optional summary-replacement layer after collect_agent_output():

  1. When tool output exceeds a configurable threshold (e.g., 8KB), replace in-context content with a summary + file path reference
  2. Write original output to {session_dir}/tool_outputs/{tool_call_id}.raw
  3. Generate a compression manifest (tool_outputs/manifest.toml) for replay
  4. Agent can request full output via csa session tool-output <id> if needed

Pre-requisites

  • Phase C passive evaluation data (quantifies which tools produce the largest outputs and how frequently)
  • Analysis of current tool output size distribution across projects

References

  • HiTw93 article: context engineering and tool result management
  • Cursor A/B test: 46.9% token reduction from dynamic tool discovery (analogous principle)

Metadata

Metadata

Assignees

No one assigned

    Labels

    design-neededNeeds design discussion before implementationenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions