Class: ActionAgent::SandboxRunJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/action_agent/sandbox_run_job.rb

Constant Summary collapse

PROVIDER_MODELS =
{
  "anthropic" => "claude-haiku-4-5",
  "openai" => "gpt-4o",
  "ollama" => "llama3.1:8b"
}.freeze

Instance Method Summary collapse

Instance Method Details

#perform(sandbox_session_id, run_id, task, provider = "anthropic") ⇒ Object

Execute a task in the sandbox using ActiveAgent's generate_later



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/jobs/action_agent/sandbox_run_job.rb', line 14

def perform(sandbox_session_id, run_id, task, provider = "anthropic")
  sandbox = SandboxSession.find(sandbox_session_id)
  return unless sandbox.can_run?

  started_at = Time.current

  # Broadcast that run has started
  broadcast_run_started(sandbox, run_id, task, provider)

  begin
    # Use ActiveAgent with generate_later for async processing
    # The agent's after_generation callback will handle recording results
    if defined?(ActiveAgent::Base)
      execute_with_active_agent(sandbox, run_id, task, provider, started_at)
    else
      # Fallback to direct API calls if ActiveAgent not available
      execute_with_fallback(sandbox, run_id, task, provider, started_at)
    end
  rescue => e
    Rails.logger.error("Sandbox run failed: #{e.message}")
    sandbox.update!(status: :ready, error_message: e.message)
    broadcast_run_error(sandbox, run_id, provider, e.message)
  end
end