Class: Phronomy::Context::TriggerContext
- Inherits:
-
Object
- Object
- Phronomy::Context::TriggerContext
- Defined in:
- lib/phronomy/context/trigger_context.rb
Overview
Read-only context passed to the +on_compaction_trigger+ callback.
The callback inspects the current message list and budget, then returns a truthy value to trigger compaction or a falsy value to skip it.
No mutations are allowed through this object; use CompactionContext (passed to +on_compact+) for actual modifications.
Instance Attribute Summary collapse
-
#budget ⇒ Phronomy::Context::TokenBudget?
readonly
Token budget for this invocation.
-
#message_elements ⇒ Array<Hash>
readonly
Frozen snapshot of message elements each element: { seq: Integer, message: Object, tokens: Integer, role: Symbol }.
-
#total_tokens ⇒ Integer
readonly
Total estimated token count of all message elements.
Instance Method Summary collapse
-
#initialize(message_elements:, budget:) ⇒ TriggerContext
constructor
A new instance of TriggerContext.
Constructor Details
#initialize(message_elements:, budget:) ⇒ TriggerContext
Returns a new instance of TriggerContext.
31 32 33 34 35 |
# File 'lib/phronomy/context/trigger_context.rb', line 31 def initialize(message_elements:, budget:) @message_elements = .dup.freeze @budget = budget @total_tokens = .sum { |e| e[:tokens] } end |
Instance Attribute Details
#budget ⇒ Phronomy::Context::TokenBudget? (readonly)
Returns token budget for this invocation.
24 25 26 |
# File 'lib/phronomy/context/trigger_context.rb', line 24 def budget @budget end |
#message_elements ⇒ Array<Hash> (readonly)
Returns frozen snapshot of message elements each element: { seq: Integer, message: Object, tokens: Integer, role: Symbol }.
21 22 23 |
# File 'lib/phronomy/context/trigger_context.rb', line 21 def @message_elements end |
#total_tokens ⇒ Integer (readonly)
Returns total estimated token count of all message elements.
27 28 29 |
# File 'lib/phronomy/context/trigger_context.rb', line 27 def total_tokens @total_tokens end |