Class: Legion::Extensions::Agentic::Self::SelfModel::Helpers::Capability

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/self/self_model/helpers/capability.rb

Constant Summary

Constants included from Constants

Legion::Extensions::Agentic::Self::SelfModel::Helpers::Constants::CALIBRATION_ALPHA, Legion::Extensions::Agentic::Self::SelfModel::Helpers::Constants::CALIBRATION_LABELS, Legion::Extensions::Agentic::Self::SelfModel::Helpers::Constants::CAPABILITY_STATES, Legion::Extensions::Agentic::Self::SelfModel::Helpers::Constants::COMPETENCE_CEILING, Legion::Extensions::Agentic::Self::SelfModel::Helpers::Constants::COMPETENCE_FLOOR, Legion::Extensions::Agentic::Self::SelfModel::Helpers::Constants::CONFIDENCE_LABELS, Legion::Extensions::Agentic::Self::SelfModel::Helpers::Constants::DEFAULT_COMPETENCE, Legion::Extensions::Agentic::Self::SelfModel::Helpers::Constants::KNOWLEDGE_STATES, Legion::Extensions::Agentic::Self::SelfModel::Helpers::Constants::MAX_CAPABILITIES, Legion::Extensions::Agentic::Self::SelfModel::Helpers::Constants::MAX_HISTORY, Legion::Extensions::Agentic::Self::SelfModel::Helpers::Constants::MAX_KNOWLEDGE_DOMAINS, Legion::Extensions::Agentic::Self::SelfModel::Helpers::Constants::OVERCONFIDENCE_THRESHOLD, Legion::Extensions::Agentic::Self::SelfModel::Helpers::Constants::UNDERCONFIDENCE_THRESHOLD

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, domain: :general, competence: DEFAULT_COMPETENCE) ⇒ Capability

Returns a new instance of Capability.



14
15
16
17
18
19
20
21
22
23
# File 'lib/legion/extensions/agentic/self/self_model/helpers/capability.rb', line 14

def initialize(id:, name:, domain: :general, competence: DEFAULT_COMPETENCE)
  @id                = id
  @name              = name
  @domain            = domain
  @competence        = competence.to_f.clamp(COMPETENCE_FLOOR, COMPETENCE_CEILING)
  @attempts          = 0
  @successes         = 0
  @calibration_error = 0.0
  @state             = compute_state
end

Instance Attribute Details

#attemptsObject (readonly)

Returns the value of attribute attempts.



12
13
14
# File 'lib/legion/extensions/agentic/self/self_model/helpers/capability.rb', line 12

def attempts
  @attempts
end

#calibration_errorObject (readonly)

Returns the value of attribute calibration_error.



12
13
14
# File 'lib/legion/extensions/agentic/self/self_model/helpers/capability.rb', line 12

def calibration_error
  @calibration_error
end

#competenceObject (readonly)

Returns the value of attribute competence.



12
13
14
# File 'lib/legion/extensions/agentic/self/self_model/helpers/capability.rb', line 12

def competence
  @competence
end

#domainObject (readonly)

Returns the value of attribute domain.



12
13
14
# File 'lib/legion/extensions/agentic/self/self_model/helpers/capability.rb', line 12

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/self/self_model/helpers/capability.rb', line 12

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/legion/extensions/agentic/self/self_model/helpers/capability.rb', line 12

def name
  @name
end

#stateObject (readonly)

Returns the value of attribute state.



12
13
14
# File 'lib/legion/extensions/agentic/self/self_model/helpers/capability.rb', line 12

def state
  @state
end

#successesObject (readonly)

Returns the value of attribute successes.



12
13
14
# File 'lib/legion/extensions/agentic/self/self_model/helpers/capability.rb', line 12

def successes
  @successes
end

Instance Method Details

#calibrated?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/legion/extensions/agentic/self/self_model/helpers/capability.rb', line 45

def calibrated?
  @calibration_error.abs < 0.15
end

#competence_labelObject



40
41
42
43
# File 'lib/legion/extensions/agentic/self/self_model/helpers/capability.rb', line 40

def competence_label
  CONFIDENCE_LABELS.each { |range, lbl| return lbl if range.cover?(@competence) }
  :very_low
end

#overconfident?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/legion/extensions/agentic/self/self_model/helpers/capability.rb', line 49

def overconfident?
  @calibration_error > OVERCONFIDENCE_THRESHOLD
end

#record_attempt(predicted_success:, actual_success:) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/legion/extensions/agentic/self/self_model/helpers/capability.rb', line 25

def record_attempt(predicted_success:, actual_success:)
  @attempts += 1
  @successes += 1 if actual_success

  prediction = predicted_success ? 1.0 : 0.0
  outcome    = actual_success    ? 1.0 : 0.0

  error = prediction - outcome
  @calibration_error += CALIBRATION_ALPHA * (error - @calibration_error)

  @competence += CALIBRATION_ALPHA * (outcome - @competence)
  @competence  = @competence.clamp(COMPETENCE_FLOOR, COMPETENCE_CEILING)
  @state       = compute_state
end

#to_hObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/legion/extensions/agentic/self/self_model/helpers/capability.rb', line 57

def to_h
  {
    id:                @id,
    name:              @name,
    domain:            @domain,
    competence:        @competence.round(4),
    competence_label:  competence_label,
    state:             @state,
    attempts:          @attempts,
    successes:         @successes,
    calibration_error: @calibration_error.round(4),
    calibrated:        calibrated?,
    overconfident:     overconfident?,
    underconfident:    underconfident?
  }
end

#underconfident?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/legion/extensions/agentic/self/self_model/helpers/capability.rb', line 53

def underconfident?
  @calibration_error < UNDERCONFIDENCE_THRESHOLD
end