Module: RubyLLM::Agents::BackgroundRemover::Execution

Includes:
Concerns::ImageOperationExecution
Included in:
RubyLLM::Agents::BackgroundRemover
Defined in:
lib/ruby_llm/agents/image/background_remover/execution.rb

Overview

Execution logic for background removers

Handles image validation, budget tracking, caching, background removal execution, and result building.

Instance Method Summary collapse

Instance Method Details

#executeBackgroundRemovalResult

Execute the background removal pipeline

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ruby_llm/agents/image/background_remover/execution.rb', line 20

def execute
  started_at = Time.current

  resolve_tenant_context!
  check_budget! if budget_tracking_enabled?
  validate_image!

  # Check cache
  cached = check_cache(BackgroundRemovalResult) if cache_enabled?
  return cached if cached

  # Remove background
  removal_result = remove_background

  # Build result
  result = build_result(
    foreground: removal_result[:foreground],
    mask: removal_result[:mask],
    started_at: started_at,
    completed_at: Time.current
  )

  # Cache result
  write_cache(result) if cache_enabled?

  # Track execution
  record_execution(result) if execution_tracking_enabled?

  result
rescue => e
  record_failed_execution(e, started_at) if execution_tracking_enabled?
  build_error_result(e, started_at)
end