Class: Legion::Extensions::Agentic::Self::NarrativeSelf::Helpers::Episode
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Self::NarrativeSelf::Helpers::Episode
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/self/narrative_self/helpers/episode.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
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#emotional_valence ⇒ Object
readonly
Returns the value of attribute emotional_valence.
-
#episode_type ⇒ Object
readonly
Returns the value of attribute episode_type.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#significance ⇒ Object
readonly
Returns the value of attribute significance.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#thread_ids ⇒ Object
readonly
Returns the value of attribute thread_ids.
Instance Method Summary collapse
- #boost(amount) ⇒ Object
- #decay ⇒ Object
- #faded? ⇒ Boolean
-
#initialize(description:, episode_type: :insight, domain: :general, significance: nil, emotional_valence: 0.0, tags: []) ⇒ Episode
constructor
A new instance of Episode.
- #label ⇒ Object
- #link_thread(thread_id) ⇒ Object
- #matches_tags?(query_tags) ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(description:, episode_type: :insight, domain: :general, significance: nil, emotional_valence: 0.0, tags: []) ⇒ Episode
Returns a new instance of Episode.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb', line 17 def initialize(description:, episode_type: :insight, domain: :general, significance: nil, emotional_valence: 0.0, tags: []) @id = SecureRandom.uuid @description = description @episode_type = episode_type @domain = domain @significance = significance || DEFAULT_SIGNIFICANCE @emotional_valence = emotional_valence.clamp(-1.0, 1.0) @tags = @created_at = Time.now.utc @thread_ids = [] end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
14 15 16 |
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb', line 14 def created_at @created_at end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
14 15 16 |
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb', line 14 def description @description end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
14 15 16 |
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb', line 14 def domain @domain end |
#emotional_valence ⇒ Object (readonly)
Returns the value of attribute emotional_valence.
14 15 16 |
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb', line 14 def emotional_valence @emotional_valence end |
#episode_type ⇒ Object (readonly)
Returns the value of attribute episode_type.
14 15 16 |
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb', line 14 def episode_type @episode_type end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb', line 14 def id @id end |
#significance ⇒ Object (readonly)
Returns the value of attribute significance.
14 15 16 |
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb', line 14 def significance @significance end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
14 15 16 |
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb', line 14 def @tags end |
#thread_ids ⇒ Object (readonly)
Returns the value of attribute thread_ids.
14 15 16 |
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb', line 14 def thread_ids @thread_ids end |
Instance Method Details
#boost(amount) ⇒ Object
30 31 32 33 |
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb', line 30 def boost(amount) emotional_factor = @emotional_valence.abs * EMOTIONAL_BOOST @significance = [(@significance + amount + emotional_factor), 1.0].min end |
#decay ⇒ Object
35 36 37 |
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb', line 35 def decay @significance = [(@significance - EPISODE_DECAY), 0.0].max end |
#faded? ⇒ Boolean
39 40 41 |
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb', line 39 def faded? @significance < SIGNIFICANCE_FLOOR end |
#label ⇒ Object
43 44 45 46 47 48 |
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb', line 43 def label SIGNIFICANCE_LABELS.each do |range, lbl| return lbl if range.cover?(@significance) end :minor end |
#link_thread(thread_id) ⇒ Object
50 51 52 |
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb', line 50 def link_thread(thread_id) @thread_ids << thread_id unless @thread_ids.include?(thread_id) end |
#matches_tags?(query_tags) ⇒ Boolean
54 55 56 57 58 59 |
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb', line 54 def () return false if .empty? || @tags.empty? overlap = (@tags & ).size overlap.to_f / .size end |
#to_h ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb', line 61 def to_h { id: @id, description: @description, episode_type: @episode_type, domain: @domain, significance: @significance, emotional_valence: @emotional_valence, label: label, tags: @tags.dup, thread_ids: @thread_ids.dup, created_at: @created_at } end |