Class: Legion::Extensions::Agentic::Executive::Flexibility::Helpers::TaskSet

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

Constant Summary

Constants included from Constants

Constants::ADAPTATION_ALPHA, Constants::DEFAULT_FLEXIBILITY, Constants::FLEXIBILITY_FLOOR, Constants::FLEXIBILITY_LABELS, Constants::MAX_RULES_PER_SET, Constants::MAX_SWITCH_HISTORY, Constants::MAX_TASK_SETS, Constants::PERSEVERATION_THRESHOLD, Constants::RULE_TYPES, Constants::SWITCH_COST_BASE, Constants::SWITCH_COST_DECAY

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, domain: :general, activation: 0.5) ⇒ TaskSet

Returns a new instance of TaskSet.



15
16
17
18
19
20
21
22
23
# File 'lib/legion/extensions/agentic/executive/flexibility/helpers/task_set.rb', line 15

def initialize(id:, name:, domain: :general, activation: 0.5)
  @id         = id
  @name       = name
  @domain     = domain
  @rules      = []
  @activation = activation.to_f.clamp(0.0, 1.0)
  @created_at = Time.now.utc
  @use_count  = 0
end

Instance Attribute Details

#activationObject

Returns the value of attribute activation.



13
14
15
# File 'lib/legion/extensions/agentic/executive/flexibility/helpers/task_set.rb', line 13

def activation
  @activation
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/executive/flexibility/helpers/task_set.rb', line 12

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



12
13
14
# File 'lib/legion/extensions/agentic/executive/flexibility/helpers/task_set.rb', line 12

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/executive/flexibility/helpers/task_set.rb', line 12

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/legion/extensions/agentic/executive/flexibility/helpers/task_set.rb', line 12

def name
  @name
end

#rulesObject (readonly)

Returns the value of attribute rules.



12
13
14
# File 'lib/legion/extensions/agentic/executive/flexibility/helpers/task_set.rb', line 12

def rules
  @rules
end

#use_countObject (readonly)

Returns the value of attribute use_count.



12
13
14
# File 'lib/legion/extensions/agentic/executive/flexibility/helpers/task_set.rb', line 12

def use_count
  @use_count
end

Instance Method Details

#activate(amount = 0.2) ⇒ Object



34
35
36
37
# File 'lib/legion/extensions/agentic/executive/flexibility/helpers/task_set.rb', line 34

def activate(amount = 0.2)
  @activation = [@activation + amount, 1.0].min
  @use_count += 1
end

#active?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/legion/extensions/agentic/executive/flexibility/helpers/task_set.rb', line 43

def active?
  @activation >= 0.5
end

#add_rule(type:, condition:, action:) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/legion/extensions/agentic/executive/flexibility/helpers/task_set.rb', line 25

def add_rule(type:, condition:, action:)
  return nil unless RULE_TYPES.include?(type)
  return nil if @rules.size >= MAX_RULES_PER_SET

  rule = { type: type, condition: condition, action: action }
  @rules << rule
  rule
end

#deactivate(amount = 0.2) ⇒ Object



39
40
41
# File 'lib/legion/extensions/agentic/executive/flexibility/helpers/task_set.rb', line 39

def deactivate(amount = 0.2)
  @activation = [@activation - amount, 0.0].max
end

#dominant?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/legion/extensions/agentic/executive/flexibility/helpers/task_set.rb', line 47

def dominant?
  @activation >= PERSEVERATION_THRESHOLD
end

#to_hObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/legion/extensions/agentic/executive/flexibility/helpers/task_set.rb', line 51

def to_h
  {
    id:         @id,
    name:       @name,
    domain:     @domain,
    activation: @activation.round(4),
    active:     active?,
    dominant:   dominant?,
    rule_count: @rules.size,
    use_count:  @use_count
  }
end