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

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/attention/switching/helpers/switch_event.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(from_task_id:, to_task_id:, switch_cost:, residual_interference:, warmup_needed:) ⇒ SwitchEvent

Returns a new instance of SwitchEvent.



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

def initialize(from_task_id:, to_task_id:, switch_cost:, residual_interference:, warmup_needed:)
  @id                    = SecureRandom.uuid
  @from_task_id          = from_task_id
  @to_task_id            = to_task_id
  @switch_cost           = switch_cost.to_f.clamp(0.0, 1.0).round(10)
  @residual_interference = residual_interference.to_f.clamp(0.0, 1.0).round(10)
  @warmup_needed         = warmup_needed.to_f.clamp(0.0, 1.0).round(10)
  @created_at            = Time.now.utc
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#from_task_idObject (readonly)

Returns the value of attribute from_task_id.



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

def from_task_id
  @from_task_id
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#residual_interferenceObject (readonly)

Returns the value of attribute residual_interference.



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

def residual_interference
  @residual_interference
end

#switch_costObject (readonly)

Returns the value of attribute switch_cost.



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

def switch_cost
  @switch_cost
end

#to_task_idObject (readonly)

Returns the value of attribute to_task_id.



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

def to_task_id
  @to_task_id
end

#warmup_neededObject (readonly)

Returns the value of attribute warmup_needed.



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

def warmup_needed
  @warmup_needed
end

Instance Method Details

#cheap?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/legion/extensions/agentic/attention/switching/helpers/switch_event.rb', line 31

def cheap?
  @switch_cost <= LOW_COST_THRESHOLD
end

#cost_labelObject



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

def cost_label
  match = COST_LABELS.find { |range, _| range.cover?(@switch_cost) }
  match ? match.last : :negligible
end

#costly?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/legion/extensions/agentic/attention/switching/helpers/switch_event.rb', line 27

def costly?
  @switch_cost >= HIGH_COST_THRESHOLD
end

#to_hObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/legion/extensions/agentic/attention/switching/helpers/switch_event.rb', line 40

def to_h
  {
    id:                    @id,
    from_task_id:          @from_task_id,
    to_task_id:            @to_task_id,
    switch_cost:           @switch_cost,
    cost_label:            cost_label,
    costly:                costly?,
    cheap:                 cheap?,
    residual_interference: @residual_interference,
    warmup_needed:         @warmup_needed,
    created_at:            @created_at
  }
end