Class: RubyPi::Tools::Executor

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

Constant Summary collapse

DEFAULT_TIMEOUT =

Default timeout for each tool execution, in seconds.

30

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry, mode: :parallel, timeout: DEFAULT_TIMEOUT) ⇒ Executor

Creates a new Executor.

Parameters:

  • registry (RubyPi::Tools::Registry)

    The registry to look up tools from.

  • mode (Symbol) (defaults to: :parallel)

    Execution mode — :parallel or :sequential.

  • timeout (Numeric) (defaults to: DEFAULT_TIMEOUT)

    Per-tool timeout in seconds (default: 30).

Raises:

  • (ArgumentError)

    If mode is not :parallel or :sequential.



44
45
46
47
48
49
50
51
52
# File 'lib/ruby_pi/tools/executor.rb', line 44

def initialize(registry, mode: :parallel, timeout: DEFAULT_TIMEOUT)
  unless %i[parallel sequential].include?(mode)
    raise ArgumentError, "Mode must be :parallel or :sequential, got #{mode.inspect}"
  end

  @registry = registry
  @mode = mode
  @timeout = timeout
end

Instance Attribute Details

#modeSymbol (readonly)

Returns The execution mode (:parallel or :sequential).

Returns:

  • (Symbol)

    The execution mode (:parallel or :sequential).



33
34
35
# File 'lib/ruby_pi/tools/executor.rb', line 33

def mode
  @mode
end

#timeoutNumeric (readonly)

Returns The per-tool timeout in seconds.

Returns:

  • (Numeric)

    The per-tool timeout in seconds.



36
37
38
# File 'lib/ruby_pi/tools/executor.rb', line 36

def timeout
  @timeout
end

Instance Method Details

#execute(calls) ⇒ Array<RubyPi::Tools::Result>

Executes a list of tool calls and returns their results.

Each call is a hash with ‘:name` (String or Symbol) and `:arguments` (Hash). Tools are looked up in the registry; if a tool is not found, a failure Result is returned for that call.

Parameters:

  • calls (Array<Hash>)

    Tool call requests, each with :name and :arguments.

Returns:



62
63
64
65
66
67
68
69
# File 'lib/ruby_pi/tools/executor.rb', line 62

def execute(calls)
  case @mode
  when :parallel
    execute_parallel(calls)
  when :sequential
    execute_sequential(calls)
  end
end