Class: Legion::Extensions::Agentic::Inference::UncertaintyTolerance::Helpers::Decision

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description:, domain:, certainty_level:, tolerance_at_time:) ⇒ Decision

Returns a new instance of Decision.



16
17
18
19
20
21
22
23
24
25
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb', line 16

def initialize(description:, domain:, certainty_level:, tolerance_at_time:)
  @id                      = SecureRandom.uuid
  @description             = description
  @domain                  = domain
  @certainty_level         = certainty_level.clamp(0.0, 1.0)
  @tolerance_at_time       = tolerance_at_time
  @actual_outcome          = nil
  @acted_despite_uncertainty = certainty_level < tolerance_at_time
  @created_at = Time.now.utc
end

Instance Attribute Details

#acted_despite_uncertaintyObject (readonly)

Returns the value of attribute acted_despite_uncertainty.



12
13
14
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb', line 12

def acted_despite_uncertainty
  @acted_despite_uncertainty
end

#actual_outcomeObject

Returns the value of attribute actual_outcome.



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

def actual_outcome
  @actual_outcome
end

#certainty_levelObject (readonly)

Returns the value of attribute certainty_level.



12
13
14
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb', line 12

def certainty_level
  @certainty_level
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb', line 12

def created_at
  @created_at
end

#descriptionObject (readonly)

Returns the value of attribute description.



12
13
14
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb', line 12

def description
  @description
end

#domainObject (readonly)

Returns the value of attribute domain.



12
13
14
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb', line 12

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb', line 12

def id
  @id
end

#tolerance_at_timeObject (readonly)

Returns the value of attribute tolerance_at_time.



12
13
14
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb', line 12

def tolerance_at_time
  @tolerance_at_time
end

Instance Method Details

#decision_typeObject



40
41
42
43
44
45
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb', line 40

def decision_type
  Constants::CERTAINTY_THRESHOLDS.each do |type, threshold|
    return type if @certainty_level >= threshold
  end
  :unknown
end

#resolve!(outcome:) ⇒ Object



27
28
29
30
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb', line 27

def resolve!(outcome:)
  @actual_outcome = outcome
  self
end

#risky?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb', line 36

def risky?
  @certainty_level < 0.4
end

#successful?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb', line 32

def successful?
  @actual_outcome == :success
end

#to_hObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb', line 47

def to_h
  {
    id:                        @id,
    description:               @description,
    domain:                    @domain,
    certainty_level:           @certainty_level,
    actual_outcome:            @actual_outcome,
    tolerance_at_time:         @tolerance_at_time,
    decision_type:             decision_type,
    acted_despite_uncertainty: @acted_despite_uncertainty,
    created_at:                @created_at
  }
end