Class: Legion::Extensions::Agentic::Social::Entrainment::Helpers::Pairing

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb

Constant Summary

Constants included from Constants

Constants::COUPLING_RATE, Constants::DECOUPLING_RATE, Constants::DEFAULT_SYNC, Constants::ENTRAINED_THRESHOLD, Constants::MAX_HISTORY, Constants::MAX_PAIRINGS, Constants::MAX_SIGNALS, Constants::NATURAL_DRIFT, Constants::PARTIAL_THRESHOLD, Constants::SIGNAL_TYPES, Constants::SYNC_CEILING, Constants::SYNC_FLOOR, Constants::SYNC_LABELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent_a:, agent_b:, domain:) ⇒ Pairing

Returns a new instance of Pairing.



17
18
19
20
21
22
23
24
25
26
# File 'lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb', line 17

def initialize(agent_a:, agent_b:, domain:)
  @id                 = SecureRandom.uuid
  @agent_a            = agent_a
  @agent_b            = agent_b
  @domain             = domain
  @synchrony          = DEFAULT_SYNC
  @interaction_count  = 0
  @created_at         = Time.now.utc
  @last_interaction_at = @created_at
end

Instance Attribute Details

#agent_aObject (readonly)

Returns the value of attribute agent_a.



14
15
16
# File 'lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb', line 14

def agent_a
  @agent_a
end

#agent_bObject (readonly)

Returns the value of attribute agent_b.



14
15
16
# File 'lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb', line 14

def agent_b
  @agent_b
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb', line 14

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



14
15
16
# File 'lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb', line 14

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb', line 14

def id
  @id
end

#interaction_countObject (readonly)

Returns the value of attribute interaction_count.



14
15
16
# File 'lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb', line 14

def interaction_count
  @interaction_count
end

#last_interaction_atObject (readonly)

Returns the value of attribute last_interaction_at.



14
15
16
# File 'lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb', line 14

def last_interaction_at
  @last_interaction_at
end

#synchronyObject (readonly)

Returns the value of attribute synchrony.



14
15
16
# File 'lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb', line 14

def synchrony
  @synchrony
end

Instance Method Details

#drift!Object



39
40
41
# File 'lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb', line 39

def drift!
  @synchrony = (@synchrony - NATURAL_DRIFT).clamp(SYNC_FLOOR, SYNC_CEILING)
end

#entrained?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb', line 43

def entrained?
  @synchrony >= ENTRAINED_THRESHOLD
end

#interact!(aligned:) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb', line 28

def interact!(aligned:)
  @interaction_count  += 1
  @last_interaction_at = Time.now.utc

  @synchrony = if aligned
                 (@synchrony + COUPLING_RATE).clamp(SYNC_FLOOR, SYNC_CEILING)
               else
                 (@synchrony - DECOUPLING_RATE).clamp(SYNC_FLOOR, SYNC_CEILING)
               end
end

#involves?(agent_id) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb', line 55

def involves?(agent_id)
  [@agent_a, @agent_b].include?(agent_id)
end

#partially_entrained?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb', line 47

def partially_entrained?
  @synchrony >= PARTIAL_THRESHOLD && @synchrony < ENTRAINED_THRESHOLD
end

#partner_of(agent_id) ⇒ Object



59
60
61
62
63
64
# File 'lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb', line 59

def partner_of(agent_id)
  return @agent_b if @agent_a == agent_id
  return @agent_a if @agent_b == agent_id

  nil
end

#sync_labelObject



51
52
53
# File 'lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb', line 51

def sync_label
  SYNC_LABELS.find { |range, _| range.cover?(@synchrony) }&.last || :unknown
end

#to_hObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb', line 66

def to_h
  {
    id:                  @id,
    agent_a:             @agent_a,
    agent_b:             @agent_b,
    domain:              @domain,
    synchrony:           @synchrony,
    sync_label:          sync_label,
    entrained:           entrained?,
    interaction_count:   @interaction_count,
    created_at:          @created_at,
    last_interaction_at: @last_interaction_at
  }
end