Class: OllamaAgent::ToolRuntime::Executor

Inherits:
Object
  • Object
show all
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

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.

Parameters:

  • action (Hash)

    ‘{ tool: Tool, args: Hash }`

Returns:

  • (Object)

    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.message }
end