Class: Legion::CLI::Chat::Tools::Reflect

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

Constant Summary collapse

DEFAULT_PORT =
4567
DEFAULT_HOST =
'127.0.0.1'
EXTRACTION_PROMPT =
<<~PROMPT
  Extract discrete, reusable knowledge entries from the following text.
  Each entry should be a standalone fact, pattern, decision, or procedure
  that would be useful in future conversations.

  Rules:
  - One entry per line, prefixed with "- "
  - Be specific and actionable, not vague
  - Include context (file paths, module names, patterns)
  - Skip trivial observations
  - Maximum 5 entries

  Return ONLY the entries, no headers or commentary.
PROMPT

Instance Method Summary collapse

Instance Method Details

#execute(text:, domain: nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/legion/cli/chat/tools/reflect.rb', line 44

def execute(text:, domain: nil)
  entries = extract_entries(text)
  return 'No actionable knowledge found to reflect on.' if entries.empty?

  results = ingest_entries(entries, domain)
  format_results(entries, results)
rescue StandardError => e
  Legion::Logging.warn("Reflect#execute failed: #{e.message}") if defined?(Legion::Logging)
  "Error during reflection: #{e.message}"
end