Class: LLM::Compactor
- Inherits:
-
Object
- Object
- LLM::Compactor
- Defined in:
- lib/llm/compactor.rb,
lib/llm/compactor/null.rb,
lib/llm/compactor/truncate.rb
Overview
LLM::Compactor is the superclass for context compaction strategies in llm.rb.
A compactor is bound to a context and decides whether and how to compact the conversation history when #call is invoked. Each subclass implements a different strategy: Truncate drops the oldest messages, and Null is a no-op (the default).
The compactor does not have a separate compact? predicate. It inspects
the context internally and returns nil when nothing needs to happen.
Callers invoke #call unconditionally.
Defined Under Namespace
Instance Attribute Summary collapse
- #ctx ⇒ LLM::Context readonly
Instance Method Summary collapse
- #call(**opts) ⇒ Object? abstract
- #initialize(ctx) ⇒ LLM::Compactor constructor
Constructor Details
#initialize(ctx) ⇒ LLM::Compactor
27 28 29 |
# File 'lib/llm/compactor.rb', line 27 def initialize(ctx) @ctx = LLM::Agent === ctx ? ctx.instance_variable_get(:@ctx) : ctx end |
Instance Attribute Details
Instance Method Details
#call(**opts) ⇒ Object?
This method is abstract.
35 36 37 |
# File 'lib/llm/compactor.rb', line 35 def call(**opts) raise NotImplementedError end |