Class: AgentRuntime::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_runtime/executor.rb

Overview

Executes tool calls via ToolRegistry based on agent decisions.

This class is responsible for executing the actions decided by the planner. It normalizes parameters and delegates to the ToolRegistry for actual execution.

Examples:

Basic usage

executor = Executor.new(tool_registry: tools)
result = executor.execute(decision, state: state)
# => { result: "..." }

Instance Method Summary collapse

Constructor Details

#initialize(tool_registry:) ⇒ Executor

Initialize a new Executor instance.

Parameters:

  • tool_registry (ToolRegistry)

    The registry containing available tools



17
18
19
# File 'lib/agent_runtime/executor.rb', line 17

def initialize(tool_registry:)
  @tools = tool_registry
end

Instance Method Details

#execute(decision, state: nil) ⇒ Hash

Execute a decision by calling the appropriate tool.

If the action is “finish”, returns a done hash without executing any tool. Otherwise, normalizes parameters and calls the tool from the registry.

Examples:

Execute a tool call

decision = Decision.new(action: "search", params: { query: "weather" })
result = executor.execute(decision, state: state)
# => { result: "Sunny, 72°F" }

Finish action

decision = Decision.new(action: "finish")
result = executor.execute(decision, state: state)
# => { done: true }

Parameters:

  • decision (Decision)

    The decision to execute

  • state (State, Hash, nil) (defaults to: nil)

    The current state (unused in default implementation)

Returns:

  • (Hash)

    The execution result hash

Raises:



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/agent_runtime/executor.rb', line 40

def execute(decision, state: nil) # rubocop:disable Lint/UnusedMethodArgument
  case decision.action
  when "finish"
    { done: true }
  else
    normalized_params = normalize_params(decision.params || {})
    @tools.call(decision.action, normalized_params)
  end
rescue StandardError => e
  raise ExecutionError, e.message
end