Module: Legion::Extensions::Agentic::Inference::UncertaintyTolerance::Runners::UncertaintyTolerance
- Includes:
- Helpers::Lex
- Included in:
- Client
- Defined in:
- lib/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance.rb
Instance Method Summary collapse
- #decisions_under_uncertainty_report(threshold: nil) ⇒ Object
- #domain_tolerance_report(domain:) ⇒ Object
- #record_uncertain_decision(description:, certainty_level:, domain: :general) ⇒ Object
- #resolve_uncertain_decision(decision_id:, outcome:) ⇒ Object
- #should_act_assessment(certainty:) ⇒ Object
- #uncertainty_profile ⇒ Object
- #uncertainty_tolerance_stats ⇒ Object
- #update_uncertainty_tolerance(tolerance:) ⇒ Object
Instance Method Details
#decisions_under_uncertainty_report(threshold: nil) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance.rb', line 71 def decisions_under_uncertainty_report(threshold: nil, **) decisions = engine.decisions_under_uncertainty(threshold: threshold) log.debug "[uncertainty_tolerance] under_uncertainty: count=#{decisions.size}" { decisions: decisions.map(&:to_h), count: decisions.size, threshold: threshold || engine.current_tolerance } end |
#domain_tolerance_report(domain:) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance.rb', line 81 def domain_tolerance_report(domain:, **) avg = engine.domain_tolerance(domain: domain) log.debug "[uncertainty_tolerance] domain_tolerance: domain=#{domain} avg=#{avg&.round(3)}" { domain: domain, average_certainty: avg, found: !avg.nil? } end |
#record_uncertain_decision(description:, certainty_level:, domain: :general) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance.rb', line 13 def record_uncertain_decision(description:, certainty_level:, domain: :general, **) decision = engine.record_decision( description: description, domain: domain, certainty_level: certainty_level ) log.debug "[uncertainty_tolerance] recorded decision: id=#{decision.id[0..7]} " \ "domain=#{domain} certainty=#{certainty_level.round(2)} " \ "type=#{decision.decision_type}" { decision_id: decision.id, domain: domain, certainty_level: certainty_level, decision_type: decision.decision_type, acted_despite_uncertainty: decision.acted_despite_uncertainty, current_tolerance: engine.current_tolerance } end |
#resolve_uncertain_decision(decision_id:, outcome:) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance.rb', line 32 def resolve_uncertain_decision(decision_id:, outcome:, **) decision = engine.resolve_decision(decision_id: decision_id, outcome: outcome) unless decision log.debug "[uncertainty_tolerance] resolve failed: #{decision_id[0..7]} not found" return { resolved: false, reason: :not_found } end log.info "[uncertainty_tolerance] resolved: id=#{decision_id[0..7]} " \ "outcome=#{outcome} tolerance=#{engine.current_tolerance.round(3)}" { resolved: true, decision_id: decision_id, outcome: outcome, current_tolerance: engine.current_tolerance, tolerance_label: engine.tolerance_label } end |
#should_act_assessment(certainty:) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance.rb', line 50 def should_act_assessment(certainty:, **) act = engine.should_act?(certainty: certainty) gap = (certainty - engine.current_tolerance).round(3) log.debug "[uncertainty_tolerance] should_act? certainty=#{certainty.round(2)} " \ "tolerance=#{engine.current_tolerance.round(2)} act=#{act}" { should_act: act, certainty: certainty, current_tolerance: engine.current_tolerance, tolerance_label: engine.tolerance_label, gap: gap } end |
#uncertainty_profile ⇒ Object
64 65 66 67 68 69 |
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance.rb', line 64 def uncertainty_profile(**) profile = engine.to_h log.debug "[uncertainty_tolerance] profile: tolerance=#{profile[:current_tolerance].round(3)} " \ "label=#{profile[:tolerance_label]} decisions=#{profile[:total_decisions]}" profile end |
#uncertainty_tolerance_stats ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance.rb', line 106 def uncertainty_tolerance_stats(**) { current_tolerance: engine.current_tolerance, tolerance_label: engine.tolerance_label, total_decisions: engine.decisions.size, successful_uncertain_count: engine.successful_uncertain_decisions.size, risk_profile: engine.risk_profile, comfort_zone_expansion_rate: engine.comfort_zone_expansion_rate, history_count: engine.history.size } end |
#update_uncertainty_tolerance(tolerance:) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance.rb', line 91 def update_uncertainty_tolerance(tolerance:, **) clamped = tolerance.clamp( Helpers::Constants::TOLERANCE_FLOOR, Helpers::Constants::TOLERANCE_CEILING ) engine.instance_variable_set(:@current_tolerance, clamped) log.info "[uncertainty_tolerance] tolerance updated: #{clamped.round(3)} " \ "label=#{engine.tolerance_label}" { updated: true, current_tolerance: clamped, tolerance_label: engine.tolerance_label } end |