Class: Legion::Extensions::Agentic::Inference::Counterfactual::Helpers::Scenario

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb

Constant Summary

Constants included from Constants

Constants::COUNTERFACTUAL_TYPES, Constants::DEFAULT_REGRET, Constants::DOWNWARD_WEIGHT, Constants::EMOTIONAL_RESPONSES, Constants::MAX_ALTERNATIVES, Constants::MAX_HISTORY, Constants::MAX_SCENARIOS, Constants::MUTATION_TYPES, Constants::PLAUSIBILITY_THRESHOLD, Constants::REGRET_CEILING, Constants::REGRET_DECAY, Constants::REGRET_FLOOR, Constants::RELEVANCE_THRESHOLD, Constants::UPWARD_WEIGHT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scenario_type:, mutation_type:, actual_outcome:, counterfactual_outcome:, antecedent:, domain:, plausibility:, regret_magnitude: 0.5) ⇒ Scenario

Returns a new instance of Scenario.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 20

def initialize(scenario_type:, mutation_type:, actual_outcome:,
               counterfactual_outcome:, antecedent:, domain:,
               plausibility:, regret_magnitude: 0.5)
  @id = SecureRandom.uuid
  @scenario_type          = scenario_type
  @mutation_type          = mutation_type
  @actual_outcome         = actual_outcome
  @counterfactual_outcome = counterfactual_outcome
  @antecedent             = antecedent
  @domain                 = domain
  @plausibility           = plausibility.to_f.clamp(0.0, 1.0)
  @regret_magnitude       = regret_magnitude.to_f.clamp(0.0, 1.0)
  @emotional_valence      = compute_emotional_valence
  @lesson                 = nil
  @resolved               = false
  @created_at             = Time.now.utc
  @resolved_at            = nil
end

Instance Attribute Details

#actual_outcomeObject (readonly)

Returns the value of attribute actual_outcome.



14
15
16
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 14

def actual_outcome
  @actual_outcome
end

#antecedentObject (readonly)

Returns the value of attribute antecedent.



14
15
16
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 14

def antecedent
  @antecedent
end

#counterfactual_outcomeObject (readonly)

Returns the value of attribute counterfactual_outcome.



14
15
16
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 14

def counterfactual_outcome
  @counterfactual_outcome
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 14

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



14
15
16
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 14

def domain
  @domain
end

#emotional_valenceObject (readonly)

Returns the value of attribute emotional_valence.



14
15
16
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 14

def emotional_valence
  @emotional_valence
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 14

def id
  @id
end

#lessonObject (readonly)

Returns the value of attribute lesson.



14
15
16
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 14

def lesson
  @lesson
end

#mutation_typeObject (readonly)

Returns the value of attribute mutation_type.



14
15
16
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 14

def mutation_type
  @mutation_type
end

#plausibilityObject (readonly)

Returns the value of attribute plausibility.



14
15
16
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 14

def plausibility
  @plausibility
end

#regret_magnitudeObject (readonly)

Returns the value of attribute regret_magnitude.



14
15
16
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 14

def regret_magnitude
  @regret_magnitude
end

#resolvedObject (readonly)

Returns the value of attribute resolved.



14
15
16
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 14

def resolved
  @resolved
end

#resolved_atObject (readonly)

Returns the value of attribute resolved_at.



14
15
16
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 14

def resolved_at
  @resolved_at
end

#scenario_typeObject (readonly)

Returns the value of attribute scenario_type.



14
15
16
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 14

def scenario_type
  @scenario_type
end

Instance Method Details

#downward?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 43

def downward?
  @scenario_type == :downward
end

#emotional_responseObject



51
52
53
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 51

def emotional_response
  EMOTIONAL_RESPONSES.fetch(@scenario_type, :neutral)
end

#prefactual?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 47

def prefactual?
  @scenario_type == :prefactual
end

#resolve(lesson:) ⇒ Object



55
56
57
58
59
60
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 55

def resolve(lesson:)
  @lesson      = lesson
  @resolved    = true
  @resolved_at = Time.now.utc
  self
end

#to_hObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 62

def to_h
  {
    id:                     @id,
    scenario_type:          @scenario_type,
    mutation_type:          @mutation_type,
    actual_outcome:         @actual_outcome,
    counterfactual_outcome: @counterfactual_outcome,
    antecedent:             @antecedent,
    domain:                 @domain,
    plausibility:           @plausibility,
    emotional_valence:      @emotional_valence,
    regret_magnitude:       @regret_magnitude,
    emotional_response:     emotional_response,
    lesson:                 @lesson,
    resolved:               @resolved,
    created_at:             @created_at,
    resolved_at:            @resolved_at
  }
end

#upward?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb', line 39

def upward?
  @scenario_type == :upward
end