Module: Legion::Extensions::Agentic::Memory::Consolidation::Helpers::Extractor
- Defined in:
- lib/legion/extensions/agentic/memory/consolidation/helpers/extractor.rb
Constant Summary collapse
- CATEGORY_PATTERNS =
{ decisions: /\b(decided|decision|went with|choose|chosen|locked in|settled on)\b/i, preferences: /\b(always|never|prefer|preference|use .* by default|do not|don't)\b/i, milestones: /\b(worked|fixed|green|merged|shipped|completed|breakthrough|finally)\b/i, problems: /\b(bug|failed|failing|failure|broken|error|crash|root cause|regression|blocked)\b/i, discoveries: /\b(found|learned|discovered|turns out|confirmed|observed)\b/i }.freeze
Class Method Summary collapse
- .entry_text(entry) ⇒ Object
- .extract(transcript) ⇒ Object
- .session_messages(session) ⇒ Object
- .transcript_lines(transcript) ⇒ Object
- .transcript_text(transcript) ⇒ Object
Class Method Details
.entry_text(entry) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/legion/extensions/agentic/memory/consolidation/helpers/extractor.rb', line 54 def entry_text(entry) return entry if entry.is_a?(String) if entry.respond_to?(:to_h) hash = entry.to_h return hash[:content] || hash['content'] || hash[:text] || hash['text'] || hash.to_s end entry.respond_to?(:content) ? entry.content.to_s : entry.to_s end |
.extract(transcript) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/legion/extensions/agentic/memory/consolidation/helpers/extractor.rb', line 20 def extract(transcript) lines = transcript_lines(transcript) CATEGORY_PATTERNS.each_with_object({}) do |(category, pattern), summary| summary[category] = lines.grep(pattern).uniq end end |
.session_messages(session) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/legion/extensions/agentic/memory/consolidation/helpers/extractor.rb', line 45 def (session) return [] unless session return session.transcript if session.respond_to?(:transcript) return session. if session.respond_to?(:messages) return session.chat. if session.respond_to?(:chat) && session.chat.respond_to?(:messages) [] end |
.transcript_lines(transcript) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/legion/extensions/agentic/memory/consolidation/helpers/extractor.rb', line 27 def transcript_lines(transcript) text = transcript_text(transcript) text.split(/[\r\n]+|(?<=[.!?])\s+/) .map { |line| line.strip.gsub(/\s+/, ' ') } .reject(&:empty?) end |
.transcript_text(transcript) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/legion/extensions/agentic/memory/consolidation/helpers/extractor.rb', line 34 def transcript_text(transcript) case transcript when String transcript when Array transcript.map { |entry| entry_text(entry) }.join("\n") else (transcript).map { |entry| entry_text(entry) }.join("\n") end end |