Class: Legion::Extensions::Agentic::Social::MirrorSystem::Helpers::ObservedBehavior

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent_id:, action:, domain:, context: nil, outcome: nil, resonance: nil) ⇒ ObservedBehavior

Returns a new instance of ObservedBehavior.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 25

def initialize(agent_id:, action:, domain:, context: nil, outcome: nil, resonance: nil)
  @id                = SecureRandom.uuid
  @agent_id          = agent_id
  @action            = action
  @domain            = domain
  @context           = context
  @outcome           = outcome
  @resonance         = (resonance || Constants::DEFAULT_RESONANCE).clamp(0.0, Constants::MAX_RESONANCE)
  @observation_count = 1
  @created_at        = Time.now.utc
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



22
23
24
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 22

def action
  @action
end

#agent_idObject (readonly)

Returns the value of attribute agent_id.



22
23
24
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 22

def agent_id
  @agent_id
end

#contextObject (readonly)

Returns the value of attribute context.



22
23
24
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 22

def context
  @context
end

#created_atObject (readonly)

Returns the value of attribute created_at.



22
23
24
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 22

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



22
23
24
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 22

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



22
23
24
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 22

def id
  @id
end

#observation_countObject

Returns the value of attribute observation_count.



23
24
25
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 23

def observation_count
  @observation_count
end

#outcomeObject (readonly)

Returns the value of attribute outcome.



22
23
24
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 22

def outcome
  @outcome
end

#resonanceObject

Returns the value of attribute resonance.



23
24
25
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 23

def resonance
  @resonance
end

Instance Method Details

#boost_familiarityObject



42
43
44
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 42

def boost_familiarity
  @resonance = [@resonance + Constants::FAMILIARITY_BOOST, Constants::MAX_RESONANCE].min
end

#decayObject



46
47
48
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 46

def decay
  @resonance = [@resonance - Constants::RESONANCE_DECAY, Constants::RESONANCE_FLOOR].max
end

#faded?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 50

def faded?
  @resonance <= Constants::RESONANCE_FLOOR
end

#labelObject



54
55
56
57
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 54

def label
  Constants::RESONANCE_LABELS.each { |range, lbl| return lbl if range.cover?(@resonance) }
  :silent
end

#observe_againObject



37
38
39
40
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 37

def observe_again
  @observation_count += 1
  @resonance = [@resonance + Constants::REPETITION_BOOST, Constants::MAX_RESONANCE].min
end

#to_hObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 59

def to_h
  {
    id:                @id,
    agent_id:          @agent_id,
    action:            @action,
    domain:            @domain,
    context:           @context,
    outcome:           @outcome,
    resonance:         @resonance,
    observation_count: @observation_count,
    label:             label,
    created_at:        @created_at
  }
end