Module: RubynCode::Learning::Injector

Defined in:
lib/rubyn_code/learning/injector.rb

Overview

Injects relevant learned instincts into the system prompt so the agent can leverage past experience for the current project and context.

Constant Summary collapse

MIN_CONFIDENCE =

Minimum confidence score for an instinct to be included.

0.3
DEFAULT_MAX_INSTINCTS =

Default maximum number of instincts to inject.

10
INSTINCTS_TABLE =
'instincts'

Class Method Summary collapse

Class Method Details

.build_and_filter(rows, context_tags, max_instincts) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/rubyn_code/learning/injector.rb', line 37

def build_and_filter(rows, context_tags, max_instincts)
  now = Time.now
  instincts = rows
              .map { |row| InstinctMethods.apply_decay(row_to_instinct(row), now) }
              .select { |inst| inst.confidence >= MIN_CONFIDENCE }

  instincts = filter_by_tags(instincts, context_tags) unless context_tags.empty?

  instincts.sort_by { |inst| -inst.confidence }.first(max_instincts)
end

.call(db:, project_path:, context_tags: [], max_instincts: DEFAULT_MAX_INSTINCTS) ⇒ String

Queries and formats relevant instincts for system prompt injection.

Parameters:

  • db (DB::Connection)

    the database connection

  • project_path (String)

    the project root path

  • context_tags (Array<String>) (defaults to: [])

    optional tags to filter by

  • max_instincts (Integer) (defaults to: DEFAULT_MAX_INSTINCTS)

    maximum number of instincts to include

Returns:

  • (String)

    formatted instincts block, or empty string if none found



27
28
29
30
31
32
33
34
35
# File 'lib/rubyn_code/learning/injector.rb', line 27

def call(db:, project_path:, context_tags: [], max_instincts: DEFAULT_MAX_INSTINCTS)
  rows = fetch_instincts(db, project_path)
  return '' if rows.empty?

  instincts = build_and_filter(rows, context_tags, max_instincts)
  return '' if instincts.empty?

  format_instincts(instincts)
end