Class: Legion::Extensions::Agentic::Learning::Scaffolding::Helpers::Scaffold

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

Constant Summary

Constants included from Constants

Constants::COMPETENCE_CEILING, Constants::COMPETENCE_FLOOR, Constants::DECAY_RATE, Constants::DEFAULT_COMPETENCE, Constants::FADING_RATE, Constants::FAILURE_SETBACK, Constants::FRUSTRATION_THRESHOLD, Constants::LEARNING_GAIN, Constants::MASTERY_THRESHOLD, Constants::MAX_HISTORY, Constants::MAX_SCAFFOLDS, Constants::MAX_TASKS, Constants::SUPPORT_LEVELS, Constants::ZONE_LABELS, Constants::ZPD_LOWER, Constants::ZPD_UPPER

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(skill_name:, domain:, competence: DEFAULT_COMPETENCE) ⇒ Scaffold

Returns a new instance of Scaffold.



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

def initialize(skill_name:, domain:, competence: DEFAULT_COMPETENCE)
  @id               = SecureRandom.uuid
  @skill_name       = skill_name
  @domain           = domain
  @competence       = competence.to_f.clamp(COMPETENCE_FLOOR, COMPETENCE_CEILING)
  @support_level    = initial_support_level
  @task_history     = []
  @practice_count   = 0
  @created_at       = Time.now.utc
  @last_practiced_at = nil
end

Instance Attribute Details

#competenceObject (readonly)

Returns the value of attribute competence.



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

def competence
  @competence
end

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



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

def last_practiced_at
  @last_practiced_at
end

#practice_countObject (readonly)

Returns the value of attribute practice_count.



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

def practice_count
  @practice_count
end

#skill_nameObject (readonly)

Returns the value of attribute skill_name.



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

def skill_name
  @skill_name
end

#support_levelObject (readonly)

Returns the value of attribute support_level.



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

def support_level
  @support_level
end

#task_historyObject (readonly)

Returns the value of attribute task_history.



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

def task_history
  @task_history
end

Instance Method Details

#attempt_task(difficulty:, success:) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/legion/extensions/agentic/learning/scaffolding/helpers/scaffold.rb', line 29

def attempt_task(difficulty:, success:)
  diff = difficulty.to_f.clamp(COMPETENCE_FLOOR, COMPETENCE_CEILING)
  delta = compute_delta(difficulty: diff, success: success)
  @competence = (@competence + delta).clamp(COMPETENCE_FLOOR, COMPETENCE_CEILING)
  @practice_count   += 1
  @last_practiced_at = Time.now.utc

  record_task(difficulty: diff, success: success)
  adjust_support(success)
  @competence
end

#current_zoneObject



41
42
43
44
45
46
# File 'lib/legion/extensions/agentic/learning/scaffolding/helpers/scaffold.rb', line 41

def current_zone
  ZONE_LABELS.each do |range, label|
    return label if range.cover?(@competence)
  end
  :beyond_reach
end

#fade_support!Object



52
53
54
55
56
57
# File 'lib/legion/extensions/agentic/learning/scaffolding/helpers/scaffold.rb', line 52

def fade_support!
  idx = SUPPORT_LEVELS.index(@support_level) || 0
  return if idx >= SUPPORT_LEVELS.size - 1

  @support_level = SUPPORT_LEVELS[idx + 1]
end

#in_zpd?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/legion/extensions/agentic/learning/scaffolding/helpers/scaffold.rb', line 70

def in_zpd?
  @competence >= ZPD_LOWER && @competence < ZPD_UPPER
end

#increase_support!Object



59
60
61
62
63
64
# File 'lib/legion/extensions/agentic/learning/scaffolding/helpers/scaffold.rb', line 59

def increase_support!
  idx = SUPPORT_LEVELS.index(@support_level) || (SUPPORT_LEVELS.size - 1)
  return if idx <= 0

  @support_level = SUPPORT_LEVELS[idx - 1]
end

#mastered?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/legion/extensions/agentic/learning/scaffolding/helpers/scaffold.rb', line 66

def mastered?
  @competence >= MASTERY_THRESHOLD
end


48
49
50
# File 'lib/legion/extensions/agentic/learning/scaffolding/helpers/scaffold.rb', line 48

def recommended_difficulty
  (@competence + ((ZPD_UPPER - @competence) * 0.5)).clamp(COMPETENCE_FLOOR, COMPETENCE_CEILING)
end

#to_hObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/legion/extensions/agentic/learning/scaffolding/helpers/scaffold.rb', line 74

def to_h
  {
    id:                @id,
    skill_name:        @skill_name,
    domain:            @domain,
    competence:        @competence.round(4),
    support_level:     @support_level,
    current_zone:      current_zone,
    practice_count:    @practice_count,
    mastered:          mastered?,
    in_zpd:            in_zpd?,
    created_at:        @created_at,
    last_practiced_at: @last_practiced_at,
    task_history_size: @task_history.size
  }
end