Class: Legion::Extensions::Agentic::Integration::Context::Helpers::Frame

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/integration/context/helpers/frame.rb

Constant Summary

Constants included from Constants

Constants::DEFAULT_FAMILIARITY, Constants::FAMILIARITY_ALPHA, Constants::FRAME_DECAY, Constants::FRAME_LABELS, Constants::FRAME_STRENGTH_FLOOR, Constants::MAX_CUES_PER_FRAME, Constants::MAX_FRAMES, Constants::MAX_FRAME_STACK, Constants::MAX_HISTORY, Constants::RELEVANCE_THRESHOLD, Constants::SWITCH_COOLDOWN, Constants::SWITCH_COST

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, domain: :general, cues: []) ⇒ Frame

Returns a new instance of Frame.



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

def initialize(name:, domain: :general, cues: [])
  @id               = SecureRandom.uuid
  @name             = name
  @domain           = domain
  @cues             = cues.first(MAX_CUES_PER_FRAME)
  @strength         = 1.0
  @familiarity      = DEFAULT_FAMILIARITY
  @created_at       = Time.now.utc
  @last_activated   = @created_at
  @activation_count = 0
end

Instance Attribute Details

#activation_countObject (readonly)

Returns the value of attribute activation_count.



14
15
16
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 14

def activation_count
  @activation_count
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 14

def created_at
  @created_at
end

#cuesObject (readonly)

Returns the value of attribute cues.



14
15
16
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 14

def cues
  @cues
end

#domainObject (readonly)

Returns the value of attribute domain.



14
15
16
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 14

def domain
  @domain
end

#familiarityObject (readonly)

Returns the value of attribute familiarity.



14
15
16
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 14

def familiarity
  @familiarity
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 14

def id
  @id
end

#last_activatedObject (readonly)

Returns the value of attribute last_activated.



14
15
16
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 14

def last_activated
  @last_activated
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 14

def name
  @name
end

#strengthObject (readonly)

Returns the value of attribute strength.



14
15
16
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 14

def strength
  @strength
end

Instance Method Details

#activateObject



29
30
31
32
33
34
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 29

def activate
  @last_activated = Time.now.utc
  @activation_count += 1
  @strength = [@strength + 0.1, 1.0].min
  update_familiarity(1.0)
end

#add_cue(cue) ⇒ Object



51
52
53
54
55
56
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 51

def add_cue(cue)
  return if @cues.include?(cue)

  @cues << cue
  @cues.shift if @cues.size > MAX_CUES_PER_FRAME
end

#deactivateObject



36
37
38
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 36

def deactivate
  update_familiarity(0.0)
end

#decayObject



40
41
42
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 40

def decay
  @strength = [(@strength - FRAME_DECAY), 0.0].max
end

#labelObject



62
63
64
65
66
67
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 62

def label
  FRAME_LABELS.each do |range, lbl|
    return lbl if range.cover?(@strength)
  end
  :fading
end

#match_score(input_cues) ⇒ Object



44
45
46
47
48
49
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 44

def match_score(input_cues)
  return 0.0 if @cues.empty? || input_cues.empty?

  overlap = (@cues & input_cues).size
  overlap.to_f / @cues.size
end

#remove_cue(cue) ⇒ Object



58
59
60
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 58

def remove_cue(cue)
  @cues.delete(cue)
end

#stale?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 69

def stale?
  @strength < FRAME_STRENGTH_FLOOR
end

#to_hObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/legion/extensions/agentic/integration/context/helpers/frame.rb', line 73

def to_h
  {
    id:               @id,
    name:             @name,
    domain:           @domain,
    strength:         @strength,
    familiarity:      @familiarity,
    label:            label,
    cues:             @cues.dup,
    activation_count: @activation_count,
    created_at:       @created_at,
    last_activated:   @last_activated
  }
end