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

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/self/narrative_self/helpers/autobiography.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

#initializeAutobiography

Returns a new instance of Autobiography.



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

def initialize
  @episodes     = []
  @threads      = []
  @self_concept = {}
end

Instance Attribute Details

#episodesObject (readonly)

Returns the value of attribute episodes.



12
13
14
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/autobiography.rb', line 12

def episodes
  @episodes
end

#self_conceptObject (readonly)

Returns the value of attribute self_concept.



12
13
14
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/autobiography.rb', line 12

def self_concept
  @self_concept
end

#threadsObject (readonly)

Returns the value of attribute threads.



12
13
14
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/autobiography.rb', line 12

def threads
  @threads
end

Instance Method Details

#create_thread(theme:, domain: :general) ⇒ Object



58
59
60
61
62
63
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/autobiography.rb', line 58

def create_thread(theme:, domain: :general)
  thread = NarrativeThread.new(theme: theme, domain: domain)
  @threads << thread
  trim_threads
  thread
end

#decay_allObject



96
97
98
99
100
101
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/autobiography.rb', line 96

def decay_all
  @episodes.each(&:decay)
  @episodes.reject!(&:faded?)
  @threads.each(&:decay)
  @threads.reject!(&:weak?)
end

#episodes_by_type(episode_type) ⇒ Object



50
51
52
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/autobiography.rb', line 50

def episodes_by_type(episode_type)
  @episodes.select { |e| e.episode_type == episode_type }
end

#episodes_in_domain(domain) ⇒ Object



54
55
56
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/autobiography.rb', line 54

def episodes_in_domain(domain)
  @episodes.select { |e| e.domain == domain }
end

#find_episode(id) ⇒ Object



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

def find_episode(id)
  @episodes.find { |e| e.id == id }
end

#find_thread(id) ⇒ Object



65
66
67
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/autobiography.rb', line 65

def find_thread(id)
  @threads.find { |t| t.id == id }
end

#find_threads_by_theme(theme) ⇒ Object



69
70
71
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/autobiography.rb', line 69

def find_threads_by_theme(theme)
  @threads.select { |t| t.theme == theme }
end

#recent_episodes(count = 10) ⇒ Object



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

def recent_episodes(count = 10)
  @episodes.last(count)
end

#record_episode(description:, episode_type: :insight, domain: :general, significance: nil, emotional_valence: 0.0, tags: []) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/autobiography.rb', line 20

def record_episode(description:, episode_type: :insight, domain: :general,
                   significance: nil, emotional_valence: 0.0, tags: [])
  episode = Episode.new(
    description:       description,
    episode_type:      episode_type,
    domain:            domain,
    significance:      significance,
    emotional_valence: emotional_valence,
    tags:              tags
  )
  @episodes << episode
  auto_link_threads(episode)
  update_self_concept(episode)
  trim_episodes
  episode
end

#self_summaryObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/autobiography.rb', line 81

def self_summary
  top_types = episode_type_distribution.first(3).map(&:first)
  top_domains = domain_distribution.first(3).map(&:first)
  top_threads = strongest_threads(3).map(&:theme)
  {
    total_episodes:     @episodes.size,
    dominant_types:     top_types,
    dominant_domains:   top_domains,
    active_threads:     top_threads,
    self_concept:       @self_concept.dup,
    pivotal_count:      @episodes.count { |e| e.label == :pivotal },
    narrative_richness: narrative_richness
  }
end

#significant_episodes(min_significance: 0.6) ⇒ Object



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

def significant_episodes(min_significance: 0.6)
  @episodes.select { |e| e.significance >= min_significance }
           .sort_by { |e| -e.significance }
end

#strongest_threads(count = 5) ⇒ Object



73
74
75
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/autobiography.rb', line 73

def strongest_threads(count = 5)
  @threads.sort_by { |t| -t.strength }.first(count)
end

#timeline(window: MAX_TIMELINE_WINDOW) ⇒ Object



77
78
79
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/autobiography.rb', line 77

def timeline(window: MAX_TIMELINE_WINDOW)
  @episodes.last(window).map(&:to_h)
end

#to_hObject



103
104
105
106
107
108
109
110
111
112
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/autobiography.rb', line 103

def to_h
  {
    episode_count:    @episodes.size,
    thread_count:     @threads.size,
    self_concept:     @self_concept.dup,
    by_type:          @episodes.group_by(&:episode_type).transform_values(&:size),
    by_domain:        @episodes.group_by(&:domain).transform_values(&:size),
    avg_significance: avg_significance
  }
end