Class: RubynCode::Agent::Loop

Inherits:
Object
  • Object
show all
Includes:
BackgroundJobHandler, FeedbackHandler, LlmCaller, ResponseParser, SystemPromptBuilder, ToolProcessor
Defined in:
lib/rubyn_code/agent/loop.rb

Overview

rubocop:disable Metrics/ClassLength -- core agent loop: LLM calls, tool dispatch, recovery, hooks

Constant Summary collapse

MAX_ITERATIONS =
Config::Defaults::MAX_ITERATIONS
GOAL_MAX_ITERATIONS =
Config::Defaults::GOAL_MAX_ITERATIONS

Constants included from FeedbackHandler

FeedbackHandler::NEGATIVE_PATTERNS, FeedbackHandler::POSITIVE_PATTERNS

Constants included from ToolProcessor

ToolProcessor::CORE_TOOLS, ToolProcessor::PLAN_MODE_RISK_LEVELS

Constants included from UsageTracker

UsageTracker::TASK_BUDGET_TOTAL

Constants included from SystemPromptBuilder

SystemPromptBuilder::INSTRUCTION_FILES

Constants included from Prompts

Prompts::PLAN_MODE_PROMPT, Prompts::SYSTEM_PROMPT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**opts) ⇒ Loop

Returns a new instance of Loop.

Options Hash (**opts):



39
40
41
42
43
44
# File 'lib/rubyn_code/agent/loop.rb', line 39

def initialize(**opts)
  assign_dependencies(opts)
  assign_callbacks(opts)
  @plan_mode = false
  @static_prompt_sections = nil
end

Instance Attribute Details

#codebase_index ⇒ Index::CodebaseIndex? (readonly)



50
51
52
# File 'lib/rubyn_code/agent/loop.rb', line 50

def codebase_index
  @codebase_index
end

#plan_mode ⇒ Boolean



47
48
49
# File 'lib/rubyn_code/agent/loop.rb', line 47

def plan_mode
  @plan_mode
end

Instance Method Details

#send_message(user_input) ⇒ String

Send a user message and run the agent loop until a final text response is produced or the iteration limit is reached.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rubyn_code/agent/loop.rb', line 57

def send_message(user_input)
  initialize_session!
  check_user_feedback(user_input)
  drain_background_notifications
  inject_skill_listing unless @skills_injected
  @decision_compactor&.detect_topic_switch(user_input)
  @skill_ttl&.tick!
  autoload_triggered_skills(user_input)
  @conversation.add_user_message(user_input)
  reset_system_prompt_cache!
  reset_iteration_state

  iteration = 0
  loop do
    result = run_iteration(iteration)
    return result if result

    iteration += 1
    break unless keep_iterating?(iteration)
  end

  RubynCode::Debug.warn("Hit iteration limit (#{iteration})")
  max_iterations_warning(iteration)
end