Class: Legion::Extensions::Agentic::Attention::Schema::Helpers::SchemaItem

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/attention/schema/helpers/schema_item.rb

Constant Summary

Constants included from Constants

Constants::ATTENTION_STATE_LABELS, Constants::AWARENESS_BOOST, Constants::AWARENESS_DECAY, Constants::AWARENESS_FLOOR, Constants::AWARENESS_LABELS, Constants::DEFAULT_AWARENESS, Constants::DRIFT_THRESHOLD, Constants::HYPERFOCUS_THRESHOLD, Constants::MAX_HISTORY, Constants::MAX_SCHEMA_ITEMS, Constants::MAX_SOCIAL_MODELS, Constants::META_ATTENTION_ALPHA, Constants::SCHEMA_UPDATE_ALPHA

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target:, domain:, reason:, source:, awareness_level: DEFAULT_AWARENESS) ⇒ SchemaItem

Returns a new instance of SchemaItem.



15
16
17
18
19
20
21
22
# File 'lib/legion/extensions/agentic/attention/schema/helpers/schema_item.rb', line 15

def initialize(target:, domain:, reason:, source:, awareness_level: DEFAULT_AWARENESS)
  @target          = target
  @domain          = domain
  @reason          = reason
  @source          = source
  @awareness_level = awareness_level.clamp(0.0, 1.0)
  @created_at      = Time.now.utc
end

Instance Attribute Details

#awareness_levelObject

Returns the value of attribute awareness_level.



13
14
15
# File 'lib/legion/extensions/agentic/attention/schema/helpers/schema_item.rb', line 13

def awareness_level
  @awareness_level
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/attention/schema/helpers/schema_item.rb', line 12

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



12
13
14
# File 'lib/legion/extensions/agentic/attention/schema/helpers/schema_item.rb', line 12

def domain
  @domain
end

#reasonObject (readonly)

Returns the value of attribute reason.



12
13
14
# File 'lib/legion/extensions/agentic/attention/schema/helpers/schema_item.rb', line 12

def reason
  @reason
end

#sourceObject (readonly)

Returns the value of attribute source.



12
13
14
# File 'lib/legion/extensions/agentic/attention/schema/helpers/schema_item.rb', line 12

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



12
13
14
# File 'lib/legion/extensions/agentic/attention/schema/helpers/schema_item.rb', line 12

def target
  @target
end

Instance Method Details

#boostObject

Apply a one-time boost (re-focus event)



30
31
32
# File 'lib/legion/extensions/agentic/attention/schema/helpers/schema_item.rb', line 30

def boost
  @awareness_level = [@awareness_level + AWARENESS_BOOST, 1.0].min
end

#decayObject

Apply per-tick decay



35
36
37
# File 'lib/legion/extensions/agentic/attention/schema/helpers/schema_item.rb', line 35

def decay
  @awareness_level = [@awareness_level - AWARENESS_DECAY, AWARENESS_FLOOR].max
end

#durationObject

Duration in seconds since this item entered the schema



25
26
27
# File 'lib/legion/extensions/agentic/attention/schema/helpers/schema_item.rb', line 25

def duration
  Time.now.utc - @created_at
end

#faded?Boolean

True when awareness has dropped to the pruning floor

Returns:

  • (Boolean)


40
41
42
# File 'lib/legion/extensions/agentic/attention/schema/helpers/schema_item.rb', line 40

def faded?
  @awareness_level <= AWARENESS_FLOOR
end

#labelObject

Symbolic label describing current awareness intensity



45
46
47
48
# File 'lib/legion/extensions/agentic/attention/schema/helpers/schema_item.rb', line 45

def label
  AWARENESS_LABELS.each { |range, lbl| return lbl if range.cover?(@awareness_level) }
  :unconscious
end

#to_hObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/legion/extensions/agentic/attention/schema/helpers/schema_item.rb', line 50

def to_h
  {
    target:          @target,
    domain:          @domain,
    awareness_level: @awareness_level.round(4),
    label:           label,
    reason:          @reason,
    source:          @source,
    duration:        duration.round(2),
    created_at:      @created_at
  }
end