Module: Legion::Extensions::Agentic::Learning::PreferenceLearning::Runners::PreferenceLearning
- Includes:
- Helpers::Lex
- Included in:
- Client
- Defined in:
- lib/legion/extensions/agentic/learning/preference_learning/runners/preference_learning.rb
Instance Method Summary collapse
- #predict_preference_outcome(option_a_id:, option_b_id:) ⇒ Object
- #preference_learning_stats ⇒ Object
- #preference_stability_report ⇒ Object
- #record_preference_comparison(winner_id:, loser_id:) ⇒ Object
- #register_preference_option(label:, domain: :general) ⇒ Object
- #top_preferences_report(domain: nil, limit: 5) ⇒ Object
- #update_preference_learning ⇒ Object
Instance Method Details
#predict_preference_outcome(option_a_id:, option_b_id:) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/runners/preference_learning.rb', line 33 def predict_preference_outcome(option_a_id:, option_b_id:, **) result = preference_engine.predict_preference(option_a_id: option_a_id, option_b_id: option_b_id) if result[:error] log.warn "[preference_learning] predict failed: #{result[:error]}" else log.debug "[preference_learning] predict: preferred=#{result[:preferred_label]} confidence=#{result[:confidence].round(2)}" end result end |
#preference_learning_stats ⇒ Object
62 63 64 65 66 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/runners/preference_learning.rb', line 62 def preference_learning_stats(**) engine_hash = preference_engine.to_h log.debug "[preference_learning] stats: total_options=#{engine_hash[:total_options]} comparisons=#{engine_hash[:comparisons]}" engine_hash.merge(stability_label: preference_engine_stability_label) end |
#preference_stability_report ⇒ Object
49 50 51 52 53 54 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/runners/preference_learning.rb', line 49 def preference_stability_report(**) stability = preference_engine.preference_stability label = stability < 0.1 ? :stable : :variable log.debug "[preference_learning] stability=#{stability.round(4)} label=#{label}" { stability: stability, label: label } end |
#record_preference_comparison(winner_id:, loser_id:) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/runners/preference_learning.rb', line 23 def record_preference_comparison(winner_id:, loser_id:, **) result = preference_engine.record_comparison(winner_id: winner_id, loser_id: loser_id) if result[:error] log.warn "[preference_learning] comparison failed: #{result[:error]}" else log.info "[preference_learning] comparison: winner=#{winner_id} loser=#{loser_id} total=#{result[:comparisons]}" end result end |
#register_preference_option(label:, domain: :general) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/runners/preference_learning.rb', line 13 def register_preference_option(label:, domain: :general, **) result = preference_engine.register_option(label: label, domain: domain) if result[:error] log.warn "[preference_learning] register failed: #{result[:error]}" else log.debug "[preference_learning] registered option id=#{result[:id]} label=#{label} domain=#{domain}" end result end |
#top_preferences_report(domain: nil, limit: 5) ⇒ Object
43 44 45 46 47 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/runners/preference_learning.rb', line 43 def top_preferences_report(domain: nil, limit: 5, **) = preference_engine.top_preferences(domain: domain, limit: limit) log.debug "[preference_learning] top #{limit} preferences domain=#{domain.inspect} count=#{.size}" { domain: domain, limit: limit, options: } end |
#update_preference_learning ⇒ Object
56 57 58 59 60 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/runners/preference_learning.rb', line 56 def update_preference_learning(**) count = preference_engine.decay_all log.debug "[preference_learning] decay cycle: options_updated=#{count}" { decayed: count } end |