Class: Legion::Extensions::Agentic::Defense::ErrorMonitoring::Helpers::ErrorSignal

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/defense/error_monitoring/helpers/error_signal.rb

Constant Summary

Constants included from Constants

Constants::CONFIDENCE_ALPHA, Constants::CONFLICT_ALPHA, Constants::CONFLICT_THRESHOLD, Constants::CORRECTION_BOOST, Constants::DEFAULT_CONFIDENCE, Constants::DEFAULT_CONFLICT_LEVEL, Constants::DEFAULT_ERROR_RATE, Constants::ERROR_RATE_ALPHA, Constants::ERROR_SEVERITY_LABELS, Constants::MAX_CONFLICT_LOG, Constants::MAX_CORRECTIONS, Constants::MAX_ERROR_LOG, Constants::MAX_SLOWDOWN, Constants::MONITORING_STATE_LABELS, Constants::POST_ERROR_SLOWDOWN, Constants::SEVERE_ERROR_THRESHOLD, Constants::SLOWDOWN_DECAY

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action:, domain:, intended:, actual:, severity:) ⇒ ErrorSignal

Returns a new instance of ErrorSignal.



14
15
16
17
18
19
20
21
22
# File 'lib/legion/extensions/agentic/defense/error_monitoring/helpers/error_signal.rb', line 14

def initialize(action:, domain:, intended:, actual:, severity:)
  @action      = action
  @domain      = domain
  @intended    = intended
  @actual      = actual
  @severity    = severity.to_f.clamp(0.0, 1.0)
  @detected_at = Time.now.utc
  @corrected   = false
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



12
13
14
# File 'lib/legion/extensions/agentic/defense/error_monitoring/helpers/error_signal.rb', line 12

def action
  @action
end

#actualObject (readonly)

Returns the value of attribute actual.



12
13
14
# File 'lib/legion/extensions/agentic/defense/error_monitoring/helpers/error_signal.rb', line 12

def actual
  @actual
end

#correctedObject (readonly)

Returns the value of attribute corrected.



12
13
14
# File 'lib/legion/extensions/agentic/defense/error_monitoring/helpers/error_signal.rb', line 12

def corrected
  @corrected
end

#detected_atObject (readonly)

Returns the value of attribute detected_at.



12
13
14
# File 'lib/legion/extensions/agentic/defense/error_monitoring/helpers/error_signal.rb', line 12

def detected_at
  @detected_at
end

#domainObject (readonly)

Returns the value of attribute domain.



12
13
14
# File 'lib/legion/extensions/agentic/defense/error_monitoring/helpers/error_signal.rb', line 12

def domain
  @domain
end

#intendedObject (readonly)

Returns the value of attribute intended.



12
13
14
# File 'lib/legion/extensions/agentic/defense/error_monitoring/helpers/error_signal.rb', line 12

def intended
  @intended
end

#severityObject (readonly)

Returns the value of attribute severity.



12
13
14
# File 'lib/legion/extensions/agentic/defense/error_monitoring/helpers/error_signal.rb', line 12

def severity
  @severity
end

Instance Method Details

#ageObject



32
33
34
# File 'lib/legion/extensions/agentic/defense/error_monitoring/helpers/error_signal.rb', line 32

def age
  Time.now.utc - @detected_at
end

#labelObject



36
37
38
39
# File 'lib/legion/extensions/agentic/defense/error_monitoring/helpers/error_signal.rb', line 36

def label
  ERROR_SEVERITY_LABELS.each { |range, lbl| return lbl if range.cover?(@severity) }
  :trivial
end

#mark_correctedObject



24
25
26
# File 'lib/legion/extensions/agentic/defense/error_monitoring/helpers/error_signal.rb', line 24

def mark_corrected
  @corrected = true
end

#severe?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/legion/extensions/agentic/defense/error_monitoring/helpers/error_signal.rb', line 28

def severe?
  @severity >= SEVERE_ERROR_THRESHOLD
end

#to_hObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/legion/extensions/agentic/defense/error_monitoring/helpers/error_signal.rb', line 41

def to_h
  {
    action:      @action,
    domain:      @domain,
    intended:    @intended,
    actual:      @actual,
    severity:    @severity.round(4),
    label:       label,
    detected_at: @detected_at,
    corrected:   @corrected,
    age:         age.round(2)
  }
end