Class: Legion::Extensions::Agentic::Learning::Procedural::Helpers::Skill

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb

Constant Summary

Constants included from Constants

Constants::AUTOMATION_THRESHOLD, Constants::COMPILATION_THRESHOLD, Constants::DECAY_RATE, Constants::DEFAULT_PROFICIENCY, Constants::MAX_HISTORY, Constants::MAX_PRODUCTIONS, Constants::MAX_SKILLS, Constants::PRACTICE_GAIN, Constants::PROFICIENCY_CEILING, Constants::PROFICIENCY_FLOOR, Constants::PROFICIENCY_LABELS, Constants::SKILL_STAGES, Constants::STAGE_LABELS, Constants::STALE_THRESHOLD

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, domain:) ⇒ Skill

Returns a new instance of Skill.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb', line 17

def initialize(name:, domain:)
  @id               = SecureRandom.uuid
  @name             = name
  @domain           = domain
  @proficiency      = DEFAULT_PROFICIENCY
  @practice_count   = 0
  @stage            = :declarative
  @productions      = []
  @created_at       = Time.now.utc
  @last_practiced_at = @created_at
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.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/learning/procedural/helpers/skill.rb', line 14

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb', line 14

def id
  @id
end

#last_practiced_atObject (readonly)

Returns the value of attribute last_practiced_at.



14
15
16
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb', line 14

def last_practiced_at
  @last_practiced_at
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb', line 14

def name
  @name
end

#practice_countObject (readonly)

Returns the value of attribute practice_count.



14
15
16
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb', line 14

def practice_count
  @practice_count
end

#productionsObject (readonly)

Returns the value of attribute productions.



14
15
16
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb', line 14

def productions
  @productions
end

#proficiencyObject (readonly)

Returns the value of attribute proficiency.



14
15
16
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb', line 14

def proficiency
  @proficiency
end

#stageObject (readonly)

Returns the value of attribute stage.



14
15
16
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb', line 14

def stage
  @stage
end

Instance Method Details

#add_production(production_id) ⇒ Object



37
38
39
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb', line 37

def add_production(production_id)
  @productions << production_id unless @productions.include?(production_id)
end

#autonomous?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb', line 45

def autonomous?
  @proficiency >= AUTOMATION_THRESHOLD
end

#compiled?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb', line 41

def compiled?
  @proficiency >= COMPILATION_THRESHOLD
end

#decay!Object



57
58
59
60
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb', line 57

def decay!
  @proficiency = (@proficiency - DECAY_RATE).clamp(PROFICIENCY_FLOOR, PROFICIENCY_CEILING)
  update_stage
end

#practice!(success:) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb', line 29

def practice!(success:)
  @practice_count    += 1
  @last_practiced_at  = Time.now.utc
  gain = success ? PRACTICE_GAIN : PRACTICE_GAIN * 0.3
  @proficiency = (@proficiency + gain).clamp(PROFICIENCY_FLOOR, PROFICIENCY_CEILING)
  update_stage
end

#proficiency_labelObject



53
54
55
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb', line 53

def proficiency_label
  PROFICIENCY_LABELS.find { |range, _| range.cover?(@proficiency) }&.last || :novice
end

#stage_labelObject



49
50
51
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb', line 49

def stage_label
  STAGE_LABELS.find { |range, _| range.cover?(@proficiency) }&.last || :declarative
end

#stale?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb', line 62

def stale?
  (Time.now.utc - @last_practiced_at) > STALE_THRESHOLD
end

#to_hObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/skill.rb', line 66

def to_h
  {
    id:                @id,
    name:              @name,
    domain:            @domain,
    proficiency:       @proficiency,
    proficiency_label: proficiency_label,
    stage:             @stage,
    stage_label:       stage_label,
    practice_count:    @practice_count,
    production_count:  @productions.size,
    compiled:          compiled?,
    autonomous:        autonomous?,
    created_at:        @created_at,
    last_practiced_at: @last_practiced_at
  }
end