Class: Phronomy::Memory::Compression::ToolOutputPruner
- Defined in:
- lib/phronomy/memory/compression/tool_output_pruner.rb
Overview
Compression strategy that truncates oversized tool-call result messages.
Large tool outputs — such as a full web-page dump or a massive JSON response — can consume a significant fraction of the context window. This compressor truncates the content of any :tool message whose character count exceeds max_chars, appending a note that the output was truncated.
Unlike Summary, this is a stateless compressor: it does not accumulate state across calls and requires no thread_id bookkeeping.
Constant Summary collapse
- TRUNCATION_NOTE =
"\n[... output truncated ...]"
Instance Method Summary collapse
-
#compress(thread_id:, messages:, seq_offset: 0) ⇒ Hash
Truncate oversized :tool messages in-place (non-destructive — returns new array).
-
#initialize(max_chars: 4000) ⇒ ToolOutputPruner
constructor
A new instance of ToolOutputPruner.
Constructor Details
#initialize(max_chars: 4000) ⇒ ToolOutputPruner
Returns a new instance of ToolOutputPruner.
29 30 31 |
# File 'lib/phronomy/memory/compression/tool_output_pruner.rb', line 29 def initialize(max_chars: 4000) @max_chars = max_chars end |
Instance Method Details
#compress(thread_id:, messages:, seq_offset: 0) ⇒ Hash
Truncate oversized :tool messages in-place (non-destructive — returns new array). Content pruning does not produce a compaction record; :compaction is always nil.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/phronomy/memory/compression/tool_output_pruner.rb', line 40 def compress(thread_id:, messages:, seq_offset: 0) pruned = .map do |msg| next msg unless msg.role.to_sym == :tool next msg if msg.content.to_s.length <= @max_chars truncated = msg.content.to_s[0, @max_chars] + TRUNCATION_NOTE (msg, truncated) end {messages: pruned, compaction: nil} end |