Class: Legion::CLI::Chat::Tools::SearchMemory

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/legion/cli/chat/tools/search_memory.rb

Constant Summary collapse

DEFAULT_PORT =
4567
DEFAULT_HOST =
'127.0.0.1'

Instance Method Summary collapse

Instance Method Details

#execute(query:) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/legion/cli/chat/tools/search_memory.rb', line 19

def execute(query:)
  require 'legion/cli/chat/memory_store'
  sections = []

  memory_results = MemoryStore.search(query)
  unless memory_results.empty?
    lines = memory_results.map { |r| "- #{r[:text]}" }
    sections << "Memory matches (#{memory_results.size}):\n#{lines.join("\n")}"
  end

  apollo_results = search_apollo(query)
  if apollo_results&.any?
    lines = apollo_results.map { |r| "- [#{r[:type] || 'fact'}] #{r[:content]} (confidence: #{r[:confidence] || 'n/a'})" }
    sections << "Apollo knowledge (#{apollo_results.size}):\n#{lines.join("\n")}"
  end

  return 'No matching memories or knowledge found.' if sections.empty?

  sections.join("\n\n")
rescue StandardError => e
  Legion::Logging.warn("SearchMemory#execute failed: #{e.message}") if defined?(Legion::Logging)
  "Error searching memory: #{e.message}"
end