Class: Legion::Extensions::Agentic::Social::Entrainment::Helpers::Pairing
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Social::Entrainment::Helpers::Pairing
- 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
-
#agent_a ⇒ Object
readonly
Returns the value of attribute agent_a.
-
#agent_b ⇒ Object
readonly
Returns the value of attribute agent_b.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#interaction_count ⇒ Object
readonly
Returns the value of attribute interaction_count.
-
#last_interaction_at ⇒ Object
readonly
Returns the value of attribute last_interaction_at.
-
#synchrony ⇒ Object
readonly
Returns the value of attribute synchrony.
Instance Method Summary collapse
- #drift! ⇒ Object
- #entrained? ⇒ Boolean
-
#initialize(agent_a:, agent_b:, domain:) ⇒ Pairing
constructor
A new instance of Pairing.
- #interact!(aligned:) ⇒ Object
- #involves?(agent_id) ⇒ Boolean
- #partially_entrained? ⇒ Boolean
- #partner_of(agent_id) ⇒ Object
- #sync_label ⇒ Object
- #to_h ⇒ Object
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_a ⇒ Object (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_b ⇒ Object (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_at ⇒ Object (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 |
#domain ⇒ Object (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 |
#id ⇒ Object (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_count ⇒ Object (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_at ⇒ Object (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 |
#synchrony ⇒ Object (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
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
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
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_label ⇒ Object
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_h ⇒ Object
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 |