Class: Crimson::Agent::ToolExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/crimson/agent/tool_executor.rb

Overview

Executes tool calls with parallel/sequential modes, hooks, and abort support.

Instance Method Summary collapse

Constructor Details

#initialize(tool_registry, events, before_hook: nil, after_hook: nil, abort_signal: nil) ⇒ ToolExecutor

Returns a new instance of ToolExecutor.

Parameters:

  • tool_registry (ToolRegistry)
  • events (EventEmitter)
  • before_hook (Proc, nil) (defaults to: nil)
  • after_hook (Proc, nil) (defaults to: nil)
  • abort_signal (AbortSignal, nil) (defaults to: nil)


14
15
16
17
18
19
20
# File 'lib/crimson/agent/tool_executor.rb', line 14

def initialize(tool_registry, events, before_hook: nil, after_hook: nil, abort_signal: nil)
  @tool_registry = tool_registry
  @events = events
  @before_hook = before_hook
  @after_hook = after_hook
  @abort_signal = abort_signal
end

Instance Method Details

#execute(tool_calls, history) ⇒ Array<Hash>

Execute a list of tool calls. Tools marked as sequential run one at a time; others run in parallel.

Parameters:

Returns:

  • (Array<Hash>)

    results with keys :tool_call, :result, :is_error



27
28
29
30
31
32
33
34
35
# File 'lib/crimson/agent/tool_executor.rb', line 27

def execute(tool_calls, history)
  sequential = tool_calls.any? { |tc| tool_sequential?(tc) }

  if sequential
    execute_sequential(tool_calls, history)
  else
    execute_parallel(tool_calls, history)
  end
end