Class: RobotLab::To::StopConditions
- Inherits:
-
Object
- Object
- RobotLab::To::StopConditions
- Defined in:
- lib/robot_lab/to/stop_conditions.rb
Overview
Evaluates all stop conditions against the current run state.
Instance Method Summary collapse
-
#after? ⇒ Boolean
Checked after an iteration completes.
-
#before? ⇒ Boolean
Checked before starting a new iteration.
-
#initialize(config, run) ⇒ StopConditions
constructor
A new instance of StopConditions.
-
#stop_when_met?(result) ⇒ Boolean
Checked after a successful iteration with a stop_when condition.
-
#token_limit_exceeded? ⇒ Boolean
Called by the orchestrator's token-tracking callback mid-iteration.
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.
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.
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.
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.
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 |