Class: Ace::Review::Molecules::Strategies::AdaptiveStrategy
- Inherits:
-
Object
- Object
- Ace::Review::Molecules::Strategies::AdaptiveStrategy
- Defined in:
- lib/ace/review/molecules/strategies/adaptive_strategy.rb
Overview
Adaptive strategy - auto-selects full or chunked based on model capabilities
This strategy analyzes the subject size and model context limit to automatically select the most appropriate underlying strategy:
-
Full strategy when subject fits within model context (with headroom)
-
Chunked strategy when subject exceeds available context
Constant Summary collapse
- DEFAULT_HEADROOM =
Default headroom percentage for system prompt and output
0.15
Instance Method Summary collapse
-
#can_handle?(subject, model_context_limit) ⇒ Boolean
Check if this strategy can handle the given subject.
-
#initialize(config = {}) ⇒ AdaptiveStrategy
constructor
A new instance of AdaptiveStrategy.
-
#prepare(subject, context = {}) ⇒ Array<Hash>
Prepare the subject for review by selecting and delegating to appropriate strategy.
-
#select_strategy(subject, model_limit, model = nil) ⇒ Object
Select the appropriate strategy based on subject size and model limit.
-
#strategy_name ⇒ Symbol
Strategy name for logging and debugging.
Constructor Details
#initialize(config = {}) ⇒ AdaptiveStrategy
Returns a new instance of AdaptiveStrategy.
35 36 37 38 39 40 |
# File 'lib/ace/review/molecules/strategies/adaptive_strategy.rb', line 35 def initialize(config = {}) # Normalize keys to symbols for consistent access (supports YAML string keys) @config = normalize_config_keys(config) @headroom = @config[:headroom] || DEFAULT_HEADROOM @logger = @config[:logger] end |
Instance Method Details
#can_handle?(subject, model_context_limit) ⇒ Boolean
Check if this strategy can handle the given subject
Adaptive strategy can always handle any subject by delegating to the appropriate underlying strategy.
50 51 52 53 54 55 |
# File 'lib/ace/review/molecules/strategies/adaptive_strategy.rb', line 50 def can_handle?(subject, model_context_limit) return false if subject.nil? || subject.empty? return false if model_context_limit.nil? || model_context_limit <= 0 true end |
#prepare(subject, context = {}) ⇒ Array<Hash>
Prepare the subject for review by selecting and delegating to appropriate strategy
Analyzes the subject size against model context limit and selects:
-
FullStrategy if subject fits within available context
-
ChunkedStrategy if subject exceeds available context
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ace/review/molecules/strategies/adaptive_strategy.rb', line 68 def prepare(subject, context = {}) model = context[:model] || context["model"] explicit_limit = context[:model_context_limit] || context["model_context_limit"] # Resolve model context limit model_limit = explicit_limit || Atoms::ContextLimitResolver.resolve(model) # Select and delegate to appropriate strategy selected = select_strategy(subject, model_limit, model) selected.prepare(subject, context) end |
#select_strategy(subject, model_limit, model = nil) ⇒ Object
Select the appropriate strategy based on subject size and model limit
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ace/review/molecules/strategies/adaptive_strategy.rb', line 93 def select_strategy(subject, model_limit, model = nil) estimated_tokens = Atoms::TokenEstimator.estimate(subject) available = (model_limit * (1 - @headroom)).to_i if estimated_tokens < available log_selection( model: model, subject_tokens: estimated_tokens, model_limit: model_limit, available: available, selected: :full, reason: "subject fits within available context" ) build_full_strategy else log_selection( model: model, subject_tokens: estimated_tokens, model_limit: model_limit, available: available, selected: :chunked, reason: "subject exceeds available context" ) build_chunked_strategy end end |
#strategy_name ⇒ Symbol
Strategy name for logging and debugging
83 84 85 |
# File 'lib/ace/review/molecules/strategies/adaptive_strategy.rb', line 83 def strategy_name :adaptive end |