Class: Legion::Extensions::Agentic::Attention::FeatureBinding::Helpers::BoundObject

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

Constant Summary

Constants included from Constants

Constants::ATTENTION_BOOST, Constants::BINDING_ALPHA, Constants::BINDING_CONFIRMATION_THRESHOLD, Constants::BINDING_DECAY, Constants::BINDING_STATE_LABELS, Constants::BINDING_STRENGTH_FLOOR, Constants::DEFAULT_BINDING_STRENGTH, Constants::FEATURE_DIMENSIONS, Constants::FEATURE_SALIENCE_FLOOR, Constants::ILLUSORY_CONJUNCTION_THRESHOLD, Constants::MAX_BINDINGS, Constants::MAX_BINDING_HISTORY, Constants::MAX_FEATURES, Constants::MAX_OBJECTS, Constants::STRENGTH_LABELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, feature_ids:, binding_strength: DEFAULT_BINDING_STRENGTH) ⇒ BoundObject

Returns a new instance of BoundObject.



15
16
17
18
19
20
21
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/bound_object.rb', line 15

def initialize(id:, feature_ids:, binding_strength: DEFAULT_BINDING_STRENGTH)
  @id               = id
  @feature_ids      = Array(feature_ids).uniq
  @binding_strength = binding_strength.to_f.clamp(0.0, 1.0)
  @bound_at         = Time.now.utc
  @confirmed_at     = nil
end

Instance Attribute Details

#binding_strengthObject

Returns the value of attribute binding_strength.



13
14
15
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/bound_object.rb', line 13

def binding_strength
  @binding_strength
end

#bound_atObject (readonly)

Returns the value of attribute bound_at.



12
13
14
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/bound_object.rb', line 12

def bound_at
  @bound_at
end

#confirmed_atObject (readonly)

Returns the value of attribute confirmed_at.



12
13
14
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/bound_object.rb', line 12

def confirmed_at
  @confirmed_at
end

#feature_idsObject (readonly)

Returns the value of attribute feature_ids.



12
13
14
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/bound_object.rb', line 12

def feature_ids
  @feature_ids
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/bound_object.rb', line 12

def id
  @id
end

Instance Method Details

#confirmObject



23
24
25
26
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/bound_object.rb', line 23

def confirm
  @confirmed_at = Time.now.utc
  @binding_strength = [@binding_strength + ATTENTION_BOOST, 1.0].min
end

#confirmed?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/bound_object.rb', line 28

def confirmed?
  !@confirmed_at.nil?
end

#decayObject



36
37
38
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/bound_object.rb', line 36

def decay
  @binding_strength = [@binding_strength - BINDING_DECAY, 0.0].max
end

#dissolved?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/bound_object.rb', line 40

def dissolved?
  @binding_strength <= BINDING_STRENGTH_FLOOR
end

#feature_countObject



56
57
58
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/bound_object.rb', line 56

def feature_count
  @feature_ids.size
end

#includes_feature?(feature_id) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/bound_object.rb', line 60

def includes_feature?(feature_id)
  @feature_ids.include?(feature_id)
end

#stateObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/bound_object.rb', line 44

def state
  if @binding_strength >= BINDING_CONFIRMATION_THRESHOLD && confirmed?
    :bound
  elsif @binding_strength >= ILLUSORY_CONJUNCTION_THRESHOLD
    :tentative
  elsif @binding_strength > BINDING_STRENGTH_FLOOR
    :illusory
  else
    :unbound
  end
end

#strength_labelObject



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

def strength_label
  STRENGTH_LABELS.each { |range, lbl| return lbl if range.cover?(@binding_strength) }
  :dissolving
end

#strengthen(amount = ATTENTION_BOOST) ⇒ Object



32
33
34
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/bound_object.rb', line 32

def strengthen(amount = ATTENTION_BOOST)
  @binding_strength = [@binding_strength + amount, 1.0].min
end

#to_hObject



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

def to_h
  {
    id:               @id,
    features:         @feature_ids.dup,
    feature_count:    feature_count,
    binding_strength: @binding_strength.round(4),
    strength_label:   strength_label,
    state:            state,
    state_label:      BINDING_STATE_LABELS[state],
    confirmed:        confirmed?,
    bound_at:         @bound_at,
    confirmed_at:     @confirmed_at
  }
end