Class: OllamaAgent::ToolRuntime::Loop
- Inherits:
-
Object
- Object
- OllamaAgent::ToolRuntime::Loop
- Defined in:
- lib/ollama_agent/tool_runtime/loop.rb
Overview
Think → resolve tool → execute → observe (memory); stops when a tool returns ‘status: “done”` or max_steps. #run returns the last tool result (the object returned from Executor#execute on the final step).
Instance Attribute Summary collapse
-
#max_steps ⇒ Object
readonly
Returns the value of attribute max_steps.
-
#plan_extractor ⇒ Object
(also: #planner)
readonly
Returns the value of attribute plan_extractor.
Instance Method Summary collapse
-
#initialize(registry:, executor:, memory:, logger: nil, max_steps: 10, plan_extractor: nil, planner: nil) ⇒ Loop
constructor
rubocop:disable Metrics/ParameterLists – runtime wiring matches plan (planner, registry, executor, memory, logger).
-
#run(context:) ⇒ Object
rubocop:enable Metrics/ParameterLists.
Constructor Details
#initialize(registry:, executor:, memory:, logger: nil, max_steps: 10, plan_extractor: nil, planner: nil) ⇒ Loop
rubocop:disable Metrics/ParameterLists – runtime wiring matches plan (planner, registry, executor, memory, logger)
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ollama_agent/tool_runtime/loop.rb', line 13 def initialize(registry:, executor:, memory:, logger: nil, max_steps: 10, plan_extractor: nil, planner: nil) @plan_extractor = plan_extractor || planner raise ArgumentError, "plan_extractor or planner is required" if @plan_extractor.nil? @registry = registry @executor = executor @memory = memory @logger = logger @max_steps = Integer(max_steps) end |
Instance Attribute Details
#max_steps ⇒ Object (readonly)
Returns the value of attribute max_steps.
8 9 10 |
# File 'lib/ollama_agent/tool_runtime/loop.rb', line 8 def max_steps @max_steps end |
#plan_extractor ⇒ Object (readonly) Also known as: planner
Returns the value of attribute plan_extractor.
8 9 10 |
# File 'lib/ollama_agent/tool_runtime/loop.rb', line 8 def plan_extractor @plan_extractor end |
Instance Method Details
#run(context:) ⇒ Object
rubocop:enable Metrics/ParameterLists
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ollama_agent/tool_runtime/loop.rb', line 25 def run(context:) steps = 0 final_result = nil Kernel.loop do raise MaxStepsExceeded, "max_steps=#{@max_steps} exceeded" if steps >= @max_steps thought, action, final_result = plan_and_execute(context) record_step(thought: thought, action: action, result: final_result) break if terminated?(final_result) steps += 1 end final_result end |