Class: Legion::Extensions::Agentic::Attention::Switching::Helpers::TaskSet

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb

Constant Summary

Constants included from Constants

Constants::CONTEXT_RESTORATION_COST, Constants::COST_LABELS, Constants::DEFAULT_SWITCH_COST, Constants::HIGH_COST_THRESHOLD, Constants::LOW_COST_THRESHOLD, Constants::MAX_SWITCH_EVENTS, Constants::MAX_TASK_SETS, Constants::PRACTICE_REDUCTION, Constants::READINESS_LABELS, Constants::READY_THRESHOLD, Constants::RESIDUAL_DECAY_RATE, Constants::RESIDUAL_LABELS, Constants::TASK_SET_TYPES, Constants::WARMUP_RATE

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, task_type: :analytical, complexity: 0.5) ⇒ TaskSet

Returns a new instance of TaskSet.



17
18
19
20
21
22
23
24
25
26
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 17

def initialize(name:, task_type: :analytical, complexity: 0.5)
  @id                  = SecureRandom.uuid
  @name                = name.to_s
  @task_type           = task_type.to_sym
  @complexity          = complexity.to_f.clamp(0.0, 1.0).round(10)
  @readiness           = 0.0
  @residual_activation = 0.0
  @activation_count    = 0
  @created_at          = Time.now.utc
end

Instance Attribute Details

#activation_countObject (readonly)

Returns the value of attribute activation_count.



14
15
16
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 14

def activation_count
  @activation_count
end

#complexityObject (readonly)

Returns the value of attribute complexity.



14
15
16
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 14

def complexity
  @complexity
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 14

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 14

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 14

def name
  @name
end

#readinessObject (readonly)

Returns the value of attribute readiness.



14
15
16
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 14

def readiness
  @readiness
end

#residual_activationObject (readonly)

Returns the value of attribute residual_activation.



14
15
16
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 14

def residual_activation
  @residual_activation
end

#task_typeObject (readonly)

Returns the value of attribute task_type.



14
15
16
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 14

def task_type
  @task_type
end

Instance Method Details

#activate!Object



28
29
30
31
32
33
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 28

def activate!
  @readiness = 1.0
  @residual_activation = 0.0
  @activation_count += 1
  self
end

#deactivate!Object



35
36
37
38
39
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 35

def deactivate!
  @residual_activation = @readiness
  @readiness = 0.0
  self
end

#decay_residual!Object



46
47
48
49
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 46

def decay_residual!
  @residual_activation = (@residual_activation - RESIDUAL_DECAY_RATE).clamp(0.0, 1.0).round(10)
  self
end

#readiness_labelObject



59
60
61
62
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 59

def readiness_label
  match = READINESS_LABELS.find { |range, _| range.cover?(@readiness) }
  match ? match.last : :unprepared
end

#ready?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 51

def ready?
  @readiness >= READY_THRESHOLD
end

#residual?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 55

def residual?
  @residual_activation > 0.1
end

#residual_labelObject



64
65
66
67
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 64

def residual_label
  match = RESIDUAL_LABELS.find { |range, _| range.cover?(@residual_activation) }
  match ? match.last : :negligible
end

#to_hObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 69

def to_h
  {
    id:                  @id,
    name:                @name,
    task_type:           @task_type,
    complexity:          @complexity,
    readiness:           @readiness,
    readiness_label:     readiness_label,
    residual_activation: @residual_activation,
    residual_label:      residual_label,
    ready:               ready?,
    has_residual:        residual?,
    activation_count:    @activation_count,
    created_at:          @created_at
  }
end

#warmup!(amount: WARMUP_RATE) ⇒ Object



41
42
43
44
# File 'lib/legion/extensions/agentic/attention/switching/helpers/task_set.rb', line 41

def warmup!(amount: WARMUP_RATE)
  @readiness = (@readiness + amount).clamp(0.0, 1.0).round(10)
  self
end