Class: RobotLab::To::StopConditions

Inherits:
Object
  • Object
show all
Defined in:
lib/robot_lab/to/stop_conditions.rb

Overview

Evaluates all stop conditions against the current run state.

Instance Method Summary collapse

Constructor Details

#initialize(config, run) ⇒ StopConditions

Returns a new instance of StopConditions.



7
8
9
10
# File 'lib/robot_lab/to/stop_conditions.rb', line 7

def initialize(config, run)
  @config = config
  @run    = run
end

Instance Method Details

#after?Boolean

Checked after an iteration completes.

Returns:

  • (Boolean)


18
19
20
# File 'lib/robot_lab/to/stop_conditions.rb', line 18

def after?
  check_max_iterations || check_max_tokens || check_consecutive_failures || check_plateau
end

#before?Boolean

Checked before starting a new iteration.

Returns:

  • (Boolean)


13
14
15
# File 'lib/robot_lab/to/stop_conditions.rb', line 13

def before?
  check_max_iterations || check_max_tokens
end

#stop_when_met?(result) ⇒ Boolean

Checked after a successful iteration with a stop_when condition.

Returns:

  • (Boolean)

Raises:



23
24
25
26
27
28
# File 'lib/robot_lab/to/stop_conditions.rb', line 23

def stop_when_met?(result)
  return false unless @config.stop_when
  return false unless result.stop?

  raise AbortError, "stop condition met: #{@config.stop_when}"
end

#token_limit_exceeded?Boolean

Called by the orchestrator's token-tracking callback mid-iteration. Returns the abort reason string if exceeded, nil otherwise.

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/robot_lab/to/stop_conditions.rb', line 32

def token_limit_exceeded?
  return false unless @config.max_tokens

  @run.total_tokens >= @config.max_tokens
end