Module: Legion::Extensions::Agentic::Self::NarrativeIdentity::Runners::NarrativeIdentity
- Extended by:
- NarrativeIdentity
- Includes:
- Helpers::Lex
- Included in:
- Client, NarrativeIdentity
- Defined in:
- lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb
Instance Method Summary collapse
- #add_theme(name:, theme_type:, engine: nil) ⇒ Object
- #assign_episode_to_chapter(episode_id:, chapter_id:, engine: nil) ⇒ Object
- #close_chapter(chapter_id:, engine: nil) ⇒ Object
- #create_chapter(title:, label:, engine: nil) ⇒ Object
- #current_chapter(engine: nil) ⇒ Object
- #decay_themes(engine: nil) ⇒ Object
- #identity_summary(engine: nil) ⇒ Object
- #life_story(engine: nil) ⇒ Object
- #link_theme(episode_id:, theme_id:, engine: nil) ⇒ Object
- #most_defining_episodes(limit: 5, engine: nil) ⇒ Object
- #narrative_coherence(engine: nil) ⇒ Object
- #narrative_report(engine: nil) ⇒ Object
- #prominent_themes(engine: nil) ⇒ Object
- #record_episode(content:, episode_type:, emotional_valence:, significance:, domain:, engine: nil) ⇒ Object
- #reinforce_theme(theme_id:, amount:, engine: nil) ⇒ Object
Instance Method Details
#add_theme(name:, theme_type:, engine: nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb', line 54 def add_theme(name:, theme_type:, engine: nil, **) return { success: false, error: "unknown theme_type: #{theme_type.inspect}" } unless Helpers::Constants::THEME_TYPES.include?(theme_type) theme = resolve_engine(engine).add_theme(name: name, theme_type: theme_type) log.debug "[narrative_identity] added theme #{theme.id[0..7]} type=#{theme_type}" { success: true, theme: theme.to_h } rescue StandardError => e { success: false, error: e. } end |
#assign_episode_to_chapter(episode_id:, chapter_id:, engine: nil) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb', line 27 def assign_episode_to_chapter(episode_id:, chapter_id:, engine: nil, **) result = resolve_engine(engine).assign_to_chapter(episode_id: episode_id, chapter_id: chapter_id) log.debug "[narrative_identity] assign episode=#{episode_id[0..7]} ok=#{result}" { success: result, episode_id: episode_id, chapter_id: chapter_id } rescue StandardError => e { success: false, error: e. } end |
#close_chapter(chapter_id:, engine: nil) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb', line 46 def close_chapter(chapter_id:, engine: nil, **) result = resolve_engine(engine).close_chapter(chapter_id: chapter_id) log.debug "[narrative_identity] close_chapter #{chapter_id[0..7]} ok=#{result}" { success: result, chapter_id: chapter_id } rescue StandardError => e { success: false, error: e. } end |
#create_chapter(title:, label:, engine: nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb', line 35 def create_chapter(title:, label:, engine: nil, **) return { success: false, error: "unknown chapter label: #{label.inspect}" } unless Helpers::Constants::CHAPTER_LABELS.include?(label) chapter = resolve_engine(engine).create_chapter(title: title, label: label) log.debug "[narrative_identity] created chapter #{chapter.id[0..7]} label=#{label}" { success: true, chapter: chapter.to_h } rescue StandardError => e { success: false, error: e. } end |
#current_chapter(engine: nil) ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb', line 121 def current_chapter(engine: nil, **) chapter = resolve_engine(engine).current_chapter log.debug "[narrative_identity] current_chapter=#{chapter&.id&.slice(0..7)}" { success: true, chapter: chapter&.to_h } rescue StandardError => e { success: false, error: e. } end |
#decay_themes(engine: nil) ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb', line 129 def decay_themes(engine: nil, **) resolve_engine(engine).decay_all_themes! log.debug '[narrative_identity] theme decay applied' { success: true } rescue StandardError => e { success: false, error: e. } end |
#identity_summary(engine: nil) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb', line 89 def identity_summary(engine: nil, **) summary = resolve_engine(engine).identity_summary log.debug '[narrative_identity] identity_summary requested' { success: true, summary: summary } rescue StandardError => e { success: false, error: e. } end |
#life_story(engine: nil) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb', line 97 def life_story(engine: nil, **) story = resolve_engine(engine).life_story log.debug "[narrative_identity] life_story chapters=#{story.size}" { success: true, life_story: story } rescue StandardError => e { success: false, error: e. } end |
#link_theme(episode_id:, theme_id:, engine: nil) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb', line 65 def link_theme(episode_id:, theme_id:, engine: nil, **) result = resolve_engine(engine).link_theme(episode_id: episode_id, theme_id: theme_id) log.debug "[narrative_identity] link theme=#{theme_id[0..7]} episode=#{episode_id[0..7]} ok=#{result}" { success: result, episode_id: episode_id, theme_id: theme_id } rescue StandardError => e { success: false, error: e. } end |
#most_defining_episodes(limit: 5, engine: nil) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb', line 105 def most_defining_episodes(limit: 5, engine: nil, **) episodes = resolve_engine(engine).most_defining_episodes(limit: limit) log.debug "[narrative_identity] defining_episodes count=#{episodes.size}" { success: true, episodes: episodes.map(&:to_h) } rescue StandardError => e { success: false, error: e. } end |
#narrative_coherence(engine: nil) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb', line 81 def narrative_coherence(engine: nil, **) score = resolve_engine(engine).narrative_coherence log.debug "[narrative_identity] coherence=#{score}" { success: true, coherence: score } rescue StandardError => e { success: false, error: e. } end |
#narrative_report(engine: nil) ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb', line 137 def narrative_report(engine: nil, **) report = resolve_engine(engine).narrative_report log.debug '[narrative_identity] narrative_report generated' { success: true, report: report } rescue StandardError => e { success: false, error: e. } end |
#prominent_themes(engine: nil) ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb', line 113 def prominent_themes(engine: nil, **) themes = resolve_engine(engine).prominent_themes log.debug "[narrative_identity] prominent_themes count=#{themes.size}" { success: true, themes: themes.map(&:to_h) } rescue StandardError => e { success: false, error: e. } end |
#record_episode(content:, episode_type:, emotional_valence:, significance:, domain:, engine: nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb', line 12 def record_episode(content:, episode_type:, emotional_valence:, significance:, domain:, engine: nil, **) return { success: false, error: "unknown episode_type: #{episode_type.inspect}" } unless Helpers::Constants::EPISODE_TYPES.include?(episode_type) episode = resolve_engine(engine).add_episode( content: content, episode_type: episode_type, emotional_valence: emotional_valence, significance: significance, domain: domain ) log.debug "[narrative_identity] recorded episode #{episode.id[0..7]} type=#{episode_type}" { success: true, episode: episode.to_h } rescue StandardError => e { success: false, error: e. } end |
#reinforce_theme(theme_id:, amount:, engine: nil) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb', line 73 def reinforce_theme(theme_id:, amount:, engine: nil, **) result = resolve_engine(engine).reinforce_theme(theme_id: theme_id, amount: amount) log.debug "[narrative_identity] reinforce theme=#{theme_id[0..7]} amount=#{amount} ok=#{result}" { success: result, theme_id: theme_id, amount: amount } rescue StandardError => e { success: false, error: e. } end |