Class: OllamaAgent::ToolRuntime::Executor
- Inherits:
-
Object
- Object
- OllamaAgent::ToolRuntime::Executor
- Defined in:
- lib/ollama_agent/tool_runtime/executor.rb
Overview
Runs Tool#call behind an optional validator; normalizes errors to a result Hash.
Instance Method Summary collapse
-
#execute(action) ⇒ Object
Tool return value, or ‘{ “status” => “error”, “error” => String }` on failure.
-
#initialize(validator: nil) ⇒ Executor
constructor
A new instance of Executor.
Constructor Details
#initialize(validator: nil) ⇒ Executor
Returns a new instance of Executor.
7 8 9 |
# File 'lib/ollama_agent/tool_runtime/executor.rb', line 7 def initialize(validator: nil) @validator = validator end |
Instance Method Details
#execute(action) ⇒ Object
Returns tool return value, or ‘{ “status” => “error”, “error” => String }` on failure.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ollama_agent/tool_runtime/executor.rb', line 13 def execute(action) tool = action[:tool] args = action[:args].is_a?(Hash) ? action[:args] : {} args = @validator.validate(tool.name, args) if validate_with?(tool, args) tool.call(args) rescue StandardError => e { "status" => "error", "error" => e. } end |