Class: SwarmSDK::Swarm::Executor

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

Overview

Handles swarm execution orchestration

Extracted from Swarm#execute to reduce complexity and eliminate code duplication. The core execution loop, error handling, and cleanup logic are unified here.

Instance Method Summary collapse

Constructor Details

#initialize(swarm) ⇒ Executor

Returns a new instance of Executor.



10
11
12
# File 'lib/swarm_sdk/swarm/executor.rb', line 10

def initialize(swarm)
  @swarm = swarm
end

Instance Method Details

#run(prompt, wait:, logs:, has_logging:, original_fiber_storage:) ⇒ Async::Task

Execute the swarm with a prompt

Parameters:

  • prompt (String)

    User prompt

  • wait (Boolean)

    Block until completion (true) or return task (false)

  • logs (Array)

    Log collection array

  • has_logging (Boolean)

    Whether logging is enabled

  • original_fiber_storage (Hash)

    Original Fiber storage values to restore

Returns:

  • (Async::Task)

    The execution task



22
23
24
25
26
27
28
29
# File 'lib/swarm_sdk/swarm/executor.rb', line 22

def run(prompt, wait:, logs:, has_logging:, original_fiber_storage:)
  @original_fiber_storage = original_fiber_storage
  if wait
    run_blocking(prompt, logs: logs, has_logging: has_logging)
  else
    run_async(prompt, logs: logs, has_logging: has_logging)
  end
end