Class: Rubino::Context::ToolResultPruner

Inherits:
Object
  • Object
show all
Defined in:
lib/rubino/context/tool_result_pruner.rb

Overview

Cheap, LLM-free pre-pass over the compressible middle before the paid summary call (#415d, ported from Hermes _prune_old_tool_results).

The middle segment is fed verbatim into the summarizer prompt; raw tool output (file reads, terminal dumps, repeated greps) dominates its token count and is exactly the noise the summary discards anyway. Pruning it first shrinks the paid summary call without losing signal:

- identical tool results (e.g. the same file read 5x) are deduped,
  keeping only the most recent full copy;
- large tool results are replaced with a 1-line descriptor
  ([tool_name] N chars) so the summarizer still sees that the call
  happened and roughly how big it was.

Operates on the duck-typed message shape SummaryBuilder consumes (objects responding to #role/#content/#tool_name, or symbol-keyed hashes), and returns plain hashes — the middle is summarized then dropped, never re-persisted, so a lossy representation here is safe.

Constant Summary collapse

MIN_PRUNE_CHARS =

Tool results below this many characters are cheap enough to leave intact.

200

Instance Method Summary collapse

Instance Method Details

#prune(messages) ⇒ Object



28
29
30
31
32
33
# File 'lib/rubino/context/tool_result_pruner.rb', line 28

def prune(messages)
  rows = messages.map { |m| to_row(m) }

  deduped = dedupe_tool_results(rows)
  summarize_large_results(deduped)
end