Module: Legion::Extensions::Agentic::Learning::Curiosity::Runners::Curiosity
- Includes:
- Helpers::Lex
- Included in:
- Client
- Defined in:
- lib/legion/extensions/agentic/learning/curiosity/runners/curiosity.rb
Overview
Runner methods for the curiosity engine: gap detection, wonder lifecycle, agenda formation.
Instance Method Summary collapse
- #curiosity_intensity ⇒ Object
- #decay_wonders(hours_elapsed: 1.0) ⇒ Object
- #detect_gaps(prior_results: {}) ⇒ Object
- #explore_wonder(wonder_id:) ⇒ Object
- #form_agenda ⇒ Object
- #generate_wonder(question:, domain: :general, gap_type: :unknown, salience: 0.5, information_gain: 0.5, source_trace_ids: []) ⇒ Object
- #resolve_wonder(wonder_id:, resolution:, actual_gain: 0.5) ⇒ Object
- #top_wonders(limit: 5) ⇒ Object
- #wonder_stats ⇒ Object
Instance Method Details
#curiosity_intensity ⇒ Object
55 56 57 58 59 60 |
# File 'lib/legion/extensions/agentic/learning/curiosity/runners/curiosity.rb', line 55 def curiosity_intensity(**) intensity = compute_intensity log.debug "[curiosity] intensity=#{intensity.round(3)}" { intensity: intensity, active_wonders: wonder_store.active_count, resolution_rate: wonder_store.resolution_rate.round(3), top_domain: top_curiosity_domain } end |
#decay_wonders(hours_elapsed: 1.0) ⇒ Object
80 81 82 83 84 |
# File 'lib/legion/extensions/agentic/learning/curiosity/runners/curiosity.rb', line 80 def decay_wonders(hours_elapsed: 1.0, **) pruned = wonder_store.decay_all(hours_elapsed: hours_elapsed) log.debug "[curiosity] decay: pruned=#{pruned} remaining=#{wonder_store.active_count}" { pruned: pruned, remaining: wonder_store.active_count } end |
#detect_gaps(prior_results: {}) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/legion/extensions/agentic/learning/curiosity/runners/curiosity.rb', line 14 def detect_gaps(prior_results: {}, **) gaps = Helpers::GapDetector.detect(prior_results) log.debug "[curiosity] detected #{gaps.size} knowledge gaps" created = create_wonders_from_gaps(gaps) build_detect_result(gaps, created) end |
#explore_wonder(wonder_id:) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/legion/extensions/agentic/learning/curiosity/runners/curiosity.rb', line 35 def explore_wonder(wonder_id:, **) wonder = wonder_store.get(wonder_id) return { error: :not_found } unless wonder return { error: :already_resolved } if wonder[:resolved] return { error: :not_explorable, reason: :max_attempts } unless Helpers::Wonder.explorable?(wonder) wonder_store.update(wonder_id, attempts: wonder[:attempts] + 1, last_explored_at: Time.now.utc) log.info "[curiosity] exploring: #{wonder[:question]} (attempt ##{wonder[:attempts] + 1})" { exploring: true, wonder_id: wonder_id, attempt: wonder[:attempts] + 1 } end |
#form_agenda ⇒ Object
68 69 70 71 72 |
# File 'lib/legion/extensions/agentic/learning/curiosity/runners/curiosity.rb', line 68 def form_agenda(**) wonders = wonder_store.top_balanced(limit: 5) log.debug "[curiosity] forming agenda from #{wonders.size} wonders" { agenda: wonders.map { |w| format_agenda_item(w) }, source: :curiosity } end |
#generate_wonder(question:, domain: :general, gap_type: :unknown, salience: 0.5, information_gain: 0.5, source_trace_ids: []) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/legion/extensions/agentic/learning/curiosity/runners/curiosity.rb', line 22 def generate_wonder(question:, domain: :general, gap_type: :unknown, salience: 0.5, information_gain: 0.5, source_trace_ids: [], **) wonder = Helpers::Wonder.new_wonder( question: question, domain: domain, gap_type: gap_type, salience: salience, information_gain: information_gain, source_trace_ids: source_trace_ids ) wonder_store.store(wonder) log.info "[curiosity] manually generated wonder: #{question}" wonder end |
#resolve_wonder(wonder_id:, resolution:, actual_gain: 0.5) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/legion/extensions/agentic/learning/curiosity/runners/curiosity.rb', line 46 def resolve_wonder(wonder_id:, resolution:, actual_gain: 0.5, **) wonder = wonder_store.get(wonder_id) return { error: :not_found } unless wonder return { error: :already_resolved } if wonder[:resolved] resolved = wonder_store.mark_resolved(wonder_id, resolution: resolution, actual_gain: actual_gain) build_resolve_result(wonder, resolved, actual_gain) end |
#top_wonders(limit: 5) ⇒ Object
62 63 64 65 66 |
# File 'lib/legion/extensions/agentic/learning/curiosity/runners/curiosity.rb', line 62 def top_wonders(limit: 5, **) wonders = wonder_store.top_balanced(limit: limit) log.debug "[curiosity] top #{wonders.size} wonders requested" { wonders: wonders.map { |w| format_wonder(w) } } end |
#wonder_stats ⇒ Object
74 75 76 77 78 |
# File 'lib/legion/extensions/agentic/learning/curiosity/runners/curiosity.rb', line 74 def wonder_stats(**) { total_generated: wonder_store.total_generated, active: wonder_store.active_count, resolved: wonder_store.resolved_count, resolution_rate: wonder_store.resolution_rate.round(3), intensity: compute_intensity.round(3), domains: wonder_store.domain_stats } end |