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

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

Constant Summary

Constants included from Constants

Constants::ATTENTION_THRESHOLD, Constants::DEFAULT_PRESTIGE, Constants::LEARNING_STAGES, Constants::MAX_BEHAVIORS, Constants::MAX_HISTORY, Constants::MAX_MODELS, Constants::MAX_OBSERVATIONS, Constants::MODEL_LABELS, Constants::OUTCOME_TYPES, Constants::PRESTIGE_CEILING, Constants::PRESTIGE_FLOOR, Constants::PRESTIGE_LEARNING_RATE, Constants::PUNISHMENT_PENALTY, Constants::REINFORCEMENT_BOOST, Constants::REPRODUCTION_CONFIDENCE, Constants::RETENTION_DECAY, Constants::STALE_THRESHOLD

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_agent_id:, action:, domain:, outcome:, context: {}) ⇒ ObservedBehavior

Returns a new instance of ObservedBehavior.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/legion/extensions/agentic/social/social_learning/helpers/observed_behavior.rb', line 18

def initialize(model_agent_id:, action:, domain:, outcome:, context: {})
  @id             = SecureRandom.uuid
  @model_agent_id = model_agent_id
  @action         = action
  @domain         = domain
  @context        = context
  @outcome        = outcome
  @retention      = 1.0
  @reproduced     = false
  @created_at     = Time.now.utc
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



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

def action
  @action
end

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/social/social_learning/helpers/observed_behavior.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/social_learning/helpers/observed_behavior.rb', line 14

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#model_agent_idObject (readonly)

Returns the value of attribute model_agent_id.



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

def model_agent_id
  @model_agent_id
end

#outcomeObject (readonly)

Returns the value of attribute outcome.



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

def outcome
  @outcome
end

#reproducedObject

Returns the value of attribute reproduced.



16
17
18
# File 'lib/legion/extensions/agentic/social/social_learning/helpers/observed_behavior.rb', line 16

def reproduced
  @reproduced
end

#retentionObject

Returns the value of attribute retention.



16
17
18
# File 'lib/legion/extensions/agentic/social/social_learning/helpers/observed_behavior.rb', line 16

def retention
  @retention
end

Instance Method Details

#decay_retention!Object



30
31
32
33
34
35
# File 'lib/legion/extensions/agentic/social/social_learning/helpers/observed_behavior.rb', line 30

def decay_retention!
  @retention = (@retention - Constants::RETENTION_DECAY).clamp(
    Constants::PRESTIGE_FLOOR,
    Constants::PRESTIGE_CEILING
  )
end

#retained?Boolean

Returns:

  • (Boolean)


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

def retained?
  @retention >= Constants::REPRODUCTION_CONFIDENCE
end

#to_hObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/legion/extensions/agentic/social/social_learning/helpers/observed_behavior.rb', line 41

def to_h
  {
    id:             @id,
    model_agent_id: @model_agent_id,
    action:         @action,
    domain:         @domain,
    context:        @context,
    outcome:        @outcome,
    retention:      @retention.round(4),
    reproduced:     @reproduced,
    retained:       retained?,
    created_at:     @created_at
  }
end