Skip to content

feat: tool result reducer for relayed tool outputs - #10

Open
Shifat7 wants to merge 1 commit into
clutchpbcfo:mainfrom
Shifat7:pr-03-tool-result-reducer
Open

Shifat7 wants to merge 1 commit into
clutchpbcfo:mainfrom
Shifat7:pr-03-tool-result-reducer

Conversation

@Shifat7

@Shifat7 Shifat7 commented Aug 22, 2026

Copy link
Copy Markdown

What changed

Adds reduceToolOutput(output, config) (src/protocol.mjs), applied inside input normalisation before per-turn truncation to function_call_output and custom_tool_call_output items when enableToolResultReducer is on:

  • ANSI escapes and progress-bar/install noise stripped; repeated blank lines collapsed.
  • Successful shell output keeps its last N meaningful lines (default 20).
  • Failed runs keep the first clear error block (assertion diffs, file paths with line/column, failing test names) plus the last N lines (default 80); discontinuities marked with [...].
  • Search/grep output capped at 5 matches per file with a +N more matches in <file> note.
  • Every reduction ends with an inline marker: [tool output reduced by Hyperagent Codex Bridge: N lines -> M].

User prose and assistant turns are never reduced — only typed tool-output items. Config: enableToolResultReducer (default true), maxSuccessfulCommandLines, maxFailedCommandLines, maxSearchMatchesPerFile.

Why it saves credits

Tool results are re-sent inside every subsequent turn of a tool loop; noisy logs multiply across turns.

Measured locally (synthetic 184-line failing npm test log):

Before: 6,339 chars (184 lines)
After:    204 chars (6 lines) — error block and assertion diff retained

Testing

npm test: 79 pass, 0 fail (3 pre-existing skips). New tests cover ANSI stripping, successful-tail retention, failure-block preservation, per-file search caps, prose immunity, and disable-flag pass-through.

Add reduceToolOutput() applied to function_call_output and
custom_tool_call_output items during input normalisation: ANSI and
progress noise stripped, successful output capped to its last
meaningful lines, failures keep the first error block plus tail lines,
and search output is capped per file with remainder notes. Reductions
are marked inline; user prose is never reduced.

Defaults: on, 20 successful lines, 80 failure lines, 5 matches/file.
Set enableToolResultReducer false for byte-identical prior behaviour.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant