Class: Legion::Extensions::Agentic::Social::Attachment::Helpers::AttachmentModel

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/social/attachment/helpers/attachment_model.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent_id:) ⇒ AttachmentModel

Returns a new instance of AttachmentModel.



13
14
15
16
17
18
19
20
# File 'lib/legion/extensions/agentic/social/attachment/helpers/attachment_model.rb', line 13

def initialize(agent_id:)
  @agent_id             = agent_id
  @attachment_strength  = 0.0
  @attachment_style     = :secure
  @bond_stage           = :initial
  @separation_tolerance = Constants::BASE_SEPARATION_TOLERANCE
  @interaction_count    = 0
end

Instance Attribute Details

#agent_idObject (readonly)

Returns the value of attribute agent_id.



10
11
12
# File 'lib/legion/extensions/agentic/social/attachment/helpers/attachment_model.rb', line 10

def agent_id
  @agent_id
end

#attachment_strengthObject (readonly)

Returns the value of attribute attachment_strength.



10
11
12
# File 'lib/legion/extensions/agentic/social/attachment/helpers/attachment_model.rb', line 10

def attachment_strength
  @attachment_strength
end

#attachment_styleObject (readonly)

Returns the value of attribute attachment_style.



10
11
12
# File 'lib/legion/extensions/agentic/social/attachment/helpers/attachment_model.rb', line 10

def attachment_style
  @attachment_style
end

#bond_stageObject (readonly)

Returns the value of attribute bond_stage.



10
11
12
# File 'lib/legion/extensions/agentic/social/attachment/helpers/attachment_model.rb', line 10

def bond_stage
  @bond_stage
end

#interaction_countObject (readonly)

Returns the value of attribute interaction_count.



10
11
12
# File 'lib/legion/extensions/agentic/social/attachment/helpers/attachment_model.rb', line 10

def interaction_count
  @interaction_count
end

#separation_toleranceObject (readonly)

Returns the value of attribute separation_tolerance.



10
11
12
# File 'lib/legion/extensions/agentic/social/attachment/helpers/attachment_model.rb', line 10

def separation_tolerance
  @separation_tolerance
end

Class Method Details

.from_h(hash) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/legion/extensions/agentic/social/attachment/helpers/attachment_model.rb', line 76

def self.from_h(hash)
  model = new(agent_id: hash[:agent_id])
  model.instance_variable_set(:@attachment_strength, hash[:attachment_strength].to_f)
  model.instance_variable_set(:@attachment_style, hash[:attachment_style]&.to_sym || :secure)
  model.instance_variable_set(:@bond_stage, hash[:bond_stage]&.to_sym || :initial)
  model.instance_variable_set(:@separation_tolerance, hash[:separation_tolerance]&.to_i || 3)
  model.instance_variable_set(:@interaction_count, hash[:interaction_count].to_i)
  model
end

Instance Method Details

#derive_style!(opts = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/legion/extensions/agentic/social/attachment/helpers/attachment_model.rb', line 53

def derive_style!(opts = {})
  frequency_variance    = opts.fetch(:frequency_variance, 0.0)
  reciprocity_imbalance = opts.fetch(:reciprocity_imbalance, 0.0)
  frequency             = opts.fetch(:frequency, 0.0)
  direct_address_ratio  = opts.fetch(:direct_address_ratio, 0.0)
  thresholds = Constants::STYLE_THRESHOLDS
  @attachment_style = if frequency_variance > thresholds[:anxious_frequency_variance] &&
                         reciprocity_imbalance > thresholds[:anxious_reciprocity_imbalance]
                        :anxious
                      elsif frequency < thresholds[:avoidant_frequency] &&
                            direct_address_ratio < thresholds[:avoidant_direct_address]
                        :avoidant
                      else
                        :secure
                      end
end

#to_hObject



70
71
72
73
74
# File 'lib/legion/extensions/agentic/social/attachment/helpers/attachment_model.rb', line 70

def to_h
  { agent_id: @agent_id, attachment_strength: @attachment_strength,
    attachment_style: @attachment_style, bond_stage: @bond_stage,
    separation_tolerance: @separation_tolerance, interaction_count: @interaction_count }
end

#update_from_signals(opts = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/legion/extensions/agentic/social/attachment/helpers/attachment_model.rb', line 22

def update_from_signals(opts = {})
  frequency_score      = opts.fetch(:frequency_score, 0.0)
  reciprocity_score    = opts.fetch(:reciprocity_score, 0.0)
  prediction_accuracy  = opts.fetch(:prediction_accuracy, 0.0)
  direct_address_ratio = opts.fetch(:direct_address_ratio, 0.0)
  channel_consistency  = opts.fetch(:channel_consistency, 0.0)

  raw = (frequency_score * Constants::FREQUENCY_WEIGHT) +
        (reciprocity_score * Constants::RECIPROCITY_WEIGHT) +
        (prediction_accuracy * Constants::PREDICTION_ACCURACY_WEIGHT) +
        (direct_address_ratio * Constants::DIRECT_ADDRESS_WEIGHT) +
        (channel_consistency * Constants::CHANNEL_CONSISTENCY_WEIGHT)

  @attachment_strength = if @interaction_count.zero?
                           raw.clamp(0.0, 1.0)
                         else
                           alpha = Constants::STRENGTH_ALPHA
                           ((alpha * raw) + ((1.0 - alpha) * @attachment_strength)).clamp(0.0, 1.0)
                         end
  @interaction_count += 1
end

#update_stage!Object



44
45
46
47
48
49
50
51
# File 'lib/legion/extensions/agentic/social/attachment/helpers/attachment_model.rb', line 44

def update_stage!
  new_stage = derive_stage
  return if Constants::BOND_STAGES.index(new_stage) <= Constants::BOND_STAGES.index(@bond_stage)

  @bond_stage = new_stage
  @separation_tolerance = Constants::BASE_SEPARATION_TOLERANCE +
                          Constants::SEPARATION_TOLERANCE_GROWTH.fetch(@bond_stage, 0)
end