Tool output compaction
Tool output compaction
Section titled “Tool output compaction”Tool output compaction is a model-context optimization for terminal-heavy tool results. It reduces large stdout/stderr payloads before they become prompt debt, while preserving status, exit codes, and repair-critical diagnostics.
This is separate from both:
- context compression, which prunes older conversation history; and
- TOON context encoding, which serializes structured JSON-shaped prompt context.
Pilot boundary
Section titled “Pilot boundary”The first Gormes slice is intentionally narrow:
- reducer code lives in
internal/toolcompact execute_codeandterminalstdout/stderr are wired- compaction is enabled for the built-in registry through internal tool configuration
full_output: truebypasses compaction for exact output- provider HTTP bodies, public APIs, persisted storage, and config formats stay JSON and unchanged
The model-visible tool result keeps the existing result shape and adds
structured compaction evidence only when a stream is reduced. Evidence records
the reducer, original byte count, compacted byte count, and stable reason codes.
Reducers
Section titled “Reducers”The first reducers are compiled Go code rather than user/project rule files:
go_testcounts passing package walls and keeps failing tests, package failures, panic lines, andfile.go:linediagnostics.build_diagnosticskeeps compiler/build package headers,file:linediagnostics, failures, panic lines, and error lines while dropping repeated dependency or cache noise.git_statussummarizes branch state and file status counts while keeping conflicted files and a bounded sample list.head_tailkeeps bounded leading and trailing context for unknown oversized text output.
This keeps the pilot deterministic and testable. A future rule layer should only be added after reducer knobs, evidence codes, and safety boundaries stabilize.
Raw output
Section titled “Raw output”Compaction is not a substitute for exact bytes. Callers that need exact command
output must request full_output: true before execution. Raw artifact storage
is deferred for these terminal-style tools until a session-scoped output
directory is available at the call site.