Class: RubyLLM::Agents::ExecutionLoggerJob Private

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/ruby_llm/agents/infrastructure/execution_logger_job.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Background job for logging agent executions to the database

Called automatically after each agent execution to create records, calculate costs, and detect anomalies.

Examples:

Configuration

RubyLLM::Agents.configure do |config|
  config.anomaly_cost_threshold = 5.00       # Log if cost > $5
  config.anomaly_duration_threshold = 10_000 # Log if duration > 10s
end

See Also:

Instance Method Summary collapse

Instance Method Details

#perform(execution_data) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Creates execution record and performs post-processing

Parameters:

  • execution_data (Hash)

    Execution attributes from instrumentation



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ruby_llm/agents/infrastructure/execution_logger_job.rb', line 27

def perform(execution_data)
  # Extract detail data before filtering (stored in separate table)
  detail_data = execution_data.delete(:_detail_data) || execution_data.delete("_detail_data")

  # Filter to only known attributes to prevent schema mismatches
  filtered_data = filter_known_attributes(execution_data)
  execution = Execution.create!(filtered_data)

  # Create detail record if present
  if detail_data&.values&.any? { |v| v.present? && v != {} && v != [] }
    execution.create_detail!(detail_data)
  end

  # Calculate costs if token data is available
  if execution.input_tokens && execution.output_tokens
    execution.calculate_costs!
    execution.save!
  end

  # Log if execution was anomalous
  log_anomaly(execution) if anomaly?(execution)
end