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.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 13

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.



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

def action
  @action
end

#agent_idObject (readonly)

Returns the value of attribute agent_id.



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

def agent_id
  @agent_id
end

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



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

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#observation_countObject

Returns the value of attribute observation_count.



11
12
13
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 11

def observation_count
  @observation_count
end

#outcomeObject (readonly)

Returns the value of attribute outcome.



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

def outcome
  @outcome
end

#resonanceObject

Returns the value of attribute resonance.



11
12
13
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 11

def resonance
  @resonance
end

Instance Method Details

#boost_familiarityObject



30
31
32
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 30

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

#decayObject



34
35
36
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 34

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

#faded?Boolean

Returns:

  • (Boolean)


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

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

#labelObject



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

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

#observe_againObject



25
26
27
28
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 25

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

#to_hObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb', line 47

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