Class: Legion::Extensions::Agentic::Self::NarrativeSelf::Helpers::NarrativeThread

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/self/narrative_self/helpers/narrative_thread.rb

Constant Summary

Constants included from Constants

Constants::DEFAULT_SIGNIFICANCE, Constants::EMOTIONAL_BOOST, Constants::EPISODE_DECAY, Constants::EPISODE_TYPES, Constants::MAX_CHAPTER_SIZE, Constants::MAX_EPISODES, Constants::MAX_SELF_CONCEPT_TRAITS, Constants::MAX_THREADS, Constants::MAX_TIMELINE_WINDOW, Constants::SIGNIFICANCE_ALPHA, Constants::SIGNIFICANCE_FLOOR, Constants::SIGNIFICANCE_LABELS, Constants::THREAD_DECAY, Constants::THREAD_MATCH_THRESHOLD, Constants::TRAIT_ALPHA

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theme:, domain: :general) ⇒ NarrativeThread

Returns a new instance of NarrativeThread.



16
17
18
19
20
21
22
23
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/narrative_thread.rb', line 16

def initialize(theme:, domain: :general)
  @id          = SecureRandom.uuid
  @theme       = theme
  @domain      = domain
  @strength    = 0.5
  @episode_ids = []
  @created_at  = Time.now.utc
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def domain
  @domain
end

#episode_idsObject (readonly)

Returns the value of attribute episode_ids.



14
15
16
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/narrative_thread.rb', line 14

def episode_ids
  @episode_ids
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/narrative_thread.rb', line 14

def id
  @id
end

#strengthObject (readonly)

Returns the value of attribute strength.



14
15
16
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/narrative_thread.rb', line 14

def strength
  @strength
end

#themeObject (readonly)

Returns the value of attribute theme.



14
15
16
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/narrative_thread.rb', line 14

def theme
  @theme
end

Instance Method Details

#add_episode(episode_id) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/narrative_thread.rb', line 25

def add_episode(episode_id)
  return if @episode_ids.include?(episode_id)

  @episode_ids << episode_id
  @episode_ids.shift if @episode_ids.size > MAX_CHAPTER_SIZE
  reinforce
end

#decayObject



37
38
39
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/narrative_thread.rb', line 37

def decay
  @strength = [(@strength - THREAD_DECAY), 0.0].max
end

#reinforceObject



33
34
35
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/narrative_thread.rb', line 33

def reinforce
  @strength = [@strength + 0.1, 1.0].min
end

#sizeObject



45
46
47
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/narrative_thread.rb', line 45

def size
  @episode_ids.size
end

#to_hObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/narrative_thread.rb', line 49

def to_h
  {
    id:         @id,
    theme:      @theme,
    domain:     @domain,
    strength:   @strength,
    episodes:   @episode_ids.size,
    created_at: @created_at
  }
end

#weak?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/narrative_thread.rb', line 41

def weak?
  @strength < SIGNIFICANCE_FLOOR
end