Class: ActionAgent::EvaluationRunnerService

Inherits:
Object
  • Object
show all
Defined in:
app/services/action_agent/evaluation_runner_service.rb

Overview

Runs an Evaluation against the agent's most recent persisted generations (solid_agent's agent_generations).

Rule-based criteria are scored deterministically from the recorded data. The llm_judge criterion asks a judge model (through the activeagent gem) to score each sample 0.0..1.0; it requires configured provider credentials and is skipped — never faked — when none are available.

Constant Summary collapse

PASS_THRESHOLD =
0.7

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(evaluation) ⇒ EvaluationRunnerService

Returns a new instance of EvaluationRunnerService.



18
19
20
# File 'app/services/action_agent/evaluation_runner_service.rb', line 18

def initialize(evaluation)
  @evaluation = evaluation
end

Class Method Details

.call(evaluation) ⇒ Object



14
15
16
# File 'app/services/action_agent/evaluation_runner_service.rb', line 14

def self.call(evaluation)
  new(evaluation).call
end

Instance Method Details

#callObject



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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/services/action_agent/evaluation_runner_service.rb', line 22

def call
  run = @evaluation.evaluation_runs.create!(status: :running)

  # judge_defined evaluations author their KPI criteria on first run.
  ensure_judge_defined_kpis! if @evaluation.judge_defined?

  sample_criteria, telemetry_criteria = @evaluation.criteria.partition do |criterion|
    !Evaluation::TELEMETRY_CRITERION_TYPES.include?(criterion["type"])
  end

  if @evaluation.compare_models.any?
    return score_comparison(run, sample_criteria, telemetry_criteria)
  end

  samples = sample_criteria.any? ? sample_generations : []
  if sample_criteria.any? && samples.empty?
    run.update!(
      status: :failed,
      error_message: "No generations to evaluate yet — run the agent first",
      completed_at: Time.current
    )
    return run
  end

  scores = {}
  per_sample_scores = Hash.new { |h, k| h[k] = [] }

  telemetry_criteria.each do |criterion|
    scores[criterion["key"]] = score_telemetry_criterion(criterion)
  end

  sample_criteria.each do |criterion|
    stats = criterion_stats(criterion, samples, per_sample_scores)
    scores[criterion["key"]] = stats
  end

  run.update!(
    status: :complete,
    scores: scores,
    samples_evaluated: samples.size,
    samples_passed: passed_count(per_sample_scores),
    completed_at: Time.current
  )
  run
rescue StandardError => e
  run&.update!(status: :failed, error_message: e.message, completed_at: Time.current)
  raise
end