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():
- When tool output exceeds a configurable threshold (e.g., 8KB), replace in-context content with a summary + file path reference
- Write original output to
{session_dir}/tool_outputs/{tool_call_id}.raw
- Generate a compression manifest (
tool_outputs/manifest.toml) for replay
- 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)
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
collect_agent_outputring buffer)spool_filein session dir)Constraints (must not break)
csa session result/logs)ReturnPacketprotocol)output/index.tomlmanifestProposed Direction
Add an optional summary-replacement layer after
collect_agent_output():{session_dir}/tool_outputs/{tool_call_id}.rawtool_outputs/manifest.toml) for replaycsa session tool-output <id>if neededPre-requisites
References