Module: Legion::Extensions::Agentic::Inference::ExpectationViolation::Runners::ExpectationViolation
- Includes:
- Helpers::Lex
- Included in:
- Helpers::Client
- Defined in:
- lib/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation.rb
Instance Method Summary collapse
- #adapt_expectation_value(expectation_id:, actual_value:) ⇒ Object
- #create_expectation(context:, domain:, expected_value: nil, tolerance: 0.2) ⇒ Object
- #evaluate_expectation(expectation_id:, actual_value:) ⇒ Object
- #expectation_violation_stats ⇒ Object
- #most_violated_expectations(limit: 5) ⇒ Object
- #recent_violations_report(limit: 10) ⇒ Object
- #violations_by_type_report(type:) ⇒ Object
Instance Method Details
#adapt_expectation_value(expectation_id:, actual_value:) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation.rb', line 32 def adapt_expectation_value(expectation_id:, actual_value:, **) result = engine.adapt_expectation(expectation_id: expectation_id, actual_value: actual_value) log.debug "[expectation_violation] adapt id=#{expectation_id[0..7]} " \ "new=#{result[:new_expected]}" result end |
#create_expectation(context:, domain:, expected_value: nil, tolerance: 0.2) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation.rb', line 13 def create_expectation(context:, domain:, expected_value: nil, tolerance: 0.2, **) exp = engine.create_expectation( context: context, domain: domain.to_sym, expected_value: expected_value || Helpers::Constants::DEFAULT_EXPECTATION, tolerance: tolerance ) log.debug "[expectation_violation] create id=#{exp.id[0..7]} " \ "ctx=#{context} expected=#{exp.expected_value}" { success: true, expectation: exp.to_h } end |
#evaluate_expectation(expectation_id:, actual_value:) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation.rb', line 25 def evaluate_expectation(expectation_id:, actual_value:, **) result = engine.evaluate_against(expectation_id: expectation_id, actual_value: actual_value) log.debug "[expectation_violation] evaluate id=#{expectation_id[0..7]} " \ "violated=#{result[:violated]} type=#{result[:type]}" result end |
#expectation_violation_stats ⇒ Object
58 59 60 61 62 63 |
# File 'lib/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation.rb', line 58 def expectation_violation_stats(**) stats = engine.to_h log.debug '[expectation_violation] stats ' \ "total=#{stats[:total_expectations]}" { success: true }.merge(stats) end |
#most_violated_expectations(limit: 5) ⇒ Object
52 53 54 55 56 |
# File 'lib/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation.rb', line 52 def most_violated_expectations(limit: 5, **) exps = engine.most_violated(limit: limit) log.debug "[expectation_violation] most_violated count=#{exps.size}" { success: true, expectations: exps.map(&:to_h), count: exps.size } end |
#recent_violations_report(limit: 10) ⇒ Object
39 40 41 42 43 |
# File 'lib/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation.rb', line 39 def recent_violations_report(limit: 10, **) violations = engine.recent_violations(limit: limit) log.debug "[expectation_violation] recent count=#{violations.size}" { success: true, violations: violations, count: violations.size } end |
#violations_by_type_report(type:) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation.rb', line 45 def violations_by_type_report(type:, **) violations = engine.violations_by_type(type: type.to_sym) log.debug '[expectation_violation] by_type ' \ "type=#{type} count=#{violations.size}" { success: true, violations: violations, count: violations.size } end |