Class: Botiasloop::Commands::Compact
- Defined in:
- lib/botiasloop/commands/compact.rb
Overview
Compact command - compresses conversation by summarizing older messages
Constant Summary collapse
- KEEP_RECENT =
5- MIN_MESSAGES =
10
Instance Method Summary collapse
Methods inherited from Base
command, description, inherited
Instance Method Details
#execute(context, _args = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/botiasloop/commands/compact.rb', line 15 def execute(context, _args = nil) conversation = context.conversation config = Config.instance = conversation.history if .length < MIN_MESSAGES return "Need at least #{MIN_MESSAGES} messages to compact. Current: #{messages.length}" end # Split messages: older ones to summarize, recent ones to keep = [0...-KEEP_RECENT] = .last(KEEP_RECENT) # Generate summary using LLM summary = (, config) # Replace conversation history conversation.compact!(summary, ) compacted_count = .length summary_preview = (summary.length > 100) ? "#{summary[0..100]}..." : summary "Conversation #{conversation.uuid} compacted.\n" \ "#{compacted_count} messages summarized, #{recent_messages.length} recent messages kept.\n" \ "Summary: #{summary_preview}" end |