Module: Legion::Extensions::Agentic::Learning::Curiosity::Helpers::Wonder
- Defined in:
- lib/legion/extensions/agentic/learning/curiosity/helpers/wonder.rb
Class Method Summary collapse
- .decay_salience(wonder, hours_elapsed: 1.0) ⇒ Object
- .explorable?(wonder) ⇒ Boolean
- .new_wonder(question:, domain: :general, gap_type: :unknown, salience: 0.5, information_gain: 0.5, source_trace_ids: [], emotional_valence: {}) ⇒ Object
- .score(wonder) ⇒ Object
- .stale?(wonder) ⇒ Boolean
Class Method Details
.decay_salience(wonder, hours_elapsed: 1.0) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/legion/extensions/agentic/learning/curiosity/helpers/wonder.rb', line 61 def decay_salience(wonder, hours_elapsed: 1.0) return wonder if wonder[:resolved] decayed = wonder[:salience] - (Constants::WONDER_DECAY_RATE * hours_elapsed) wonder.merge(salience: [decayed, 0.0].max) end |
.explorable?(wonder) ⇒ Boolean
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/legion/extensions/agentic/learning/curiosity/helpers/wonder.rb', line 49 def explorable?(wonder) return false if wonder[:resolved] return false if wonder[:attempts] >= Constants::MAX_EXPLORATION_ATTEMPTS if wonder[:last_explored_at] cooldown = Constants::EXPLORATION_COOLDOWN * (2**[wonder[:attempts] - 1, 0].max) return false if (Time.now.utc - wonder[:last_explored_at]) < cooldown end true end |
.new_wonder(question:, domain: :general, gap_type: :unknown, salience: 0.5, information_gain: 0.5, source_trace_ids: [], emotional_valence: {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/legion/extensions/agentic/learning/curiosity/helpers/wonder.rb', line 14 def new_wonder(question:, domain: :general, gap_type: :unknown, salience: 0.5, information_gain: 0.5, source_trace_ids: [], emotional_valence: {}) raise ArgumentError, "invalid gap_type: #{gap_type}" unless Constants::GAP_TYPES.include?(gap_type) { wonder_id: SecureRandom.uuid, question: question, domain: domain.to_sym, gap_type: gap_type, salience: salience.clamp(0.0, 1.0), information_gain: information_gain.clamp(0.0, 1.0), attempts: 0, created_at: Time.now.utc, last_explored_at: nil, resolved: false, resolution: nil, source_trace_ids: Array(source_trace_ids), emotional_valence: emotional_valence } end |
.score(wonder) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/legion/extensions/agentic/learning/curiosity/helpers/wonder.rb', line 36 def score(wonder) return 0.0 if wonder[:resolved] base = (wonder[:salience] * 0.6) + (wonder[:information_gain] * 0.4) attempt_penalty = [wonder[:attempts] * 0.1, 0.5].min base - attempt_penalty end |
.stale?(wonder) ⇒ Boolean
44 45 46 47 |
# File 'lib/legion/extensions/agentic/learning/curiosity/helpers/wonder.rb', line 44 def stale?(wonder) age = Time.now.utc - wonder[:created_at] age > Constants::WONDER_STALE_THRESHOLD end |