Class: SkillBench::Agent::ReactAgent::LoopRunner
- Inherits:
-
Object
- Object
- SkillBench::Agent::ReactAgent::LoopRunner
- Defined in:
- lib/skill_bench/agent/react_agent/loop_runner.rb
Overview
Executes the ReAct loop iterations until completion or max iterations.
Class Method Summary collapse
-
.attach_step_number(iteration, step_count) ⇒ Hash
Attaches the step number to an iteration hash.
-
.call(initial_prompt, max_iterations, config) ⇒ Hash
Executes the loop.
-
.merge_iterations(result, iterations_log) ⇒ Hash
Merges the collected iterations into the result response.
Class Method Details
.attach_step_number(iteration, step_count) ⇒ Hash
Attaches the step number to an iteration hash.
53 54 55 |
# File 'lib/skill_bench/agent/react_agent/loop_runner.rb', line 53 def self.attach_step_number(iteration, step_count) iteration.merge(step_number: step_count) end |
.call(initial_prompt, max_iterations, config) ⇒ Hash
Executes the loop.
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 41 42 43 44 45 46 |
# File 'lib/skill_bench/agent/react_agent/loop_runner.rb', line 16 def self.call(initial_prompt, max_iterations, config) = [{ role: 'user', content: initial_prompt }] iterations_log = [] step_count = 0 while step_count < max_iterations step_count += 1 step_result = Step.call(, config) iteration = step_result[:iteration] iterations_log << attach_step_number(iteration, step_count) if iteration unless step_result[:continue] final_result = step_result[:result] || { success: false, response: { error: { message: 'Step returned no result' } } } return merge_iterations(final_result, iterations_log) end = step_result[:messages] end merge_iterations( { success: false, response: { error: { message: Agent::ReactAgent::MAX_ITERATIONS_REACHED } } }, iterations_log ) rescue StandardError => e SkillBench::ErrorLogger.log_error(e, 'ReactAgent Error') merge_iterations( { success: false, response: { error: { message: e. } } }, iterations_log ) end |
.merge_iterations(result, iterations_log) ⇒ Hash
Merges the collected iterations into the result response.
62 63 64 65 |
# File 'lib/skill_bench/agent/react_agent/loop_runner.rb', line 62 def self.merge_iterations(result, iterations_log) response = result[:response] || {} result.merge(response: response.merge(iterations: iterations_log)) end |