Behavior for stop conditions that control when optimization terminates.
Stop conditions are predicates over the optimization state that return true when the optimization should stop.
Example Implementations
defmodule TimeoutStop do
@behaviour GEPA.StopCondition
defstruct [:start_time, :timeout_ms]
@impl true
def should_stop?(%__MODULE__{start_time: start, timeout_ms: timeout}, _state) do
System.monotonic_time(:millisecond) - start > timeout
end
endComposing Stop Conditions
Use GEPA.StopCondition.Composite to combine multiple conditions with AND/OR logic.
Summary
Callbacks
Check if optimization should stop based on current state.
Functions
Evaluate a stop condition, callable, or module against the current state.
Update a stateful stop condition after an iteration.
Types
@type t() :: term()
Callbacks
@callback should_stop?(t(), GEPA.State.t()) :: boolean()
Check if optimization should stop based on current state.
Parameters
condition: The stop condition struct/stategepa_state: Current GEPA optimization state
Returns
true if optimization should stop, false otherwise
Contract
- Should be pure function (no side effects except reading state)
- Should be monotonic: once true, should stay true
- Should be fast (<1ms) to check
Functions
@spec should_stop?(term(), GEPA.State.t()) :: boolean()
Evaluate a stop condition, callable, or module against the current state.
@spec update(term(), GEPA.State.t()) :: term()
Update a stateful stop condition after an iteration.
Stateless conditions are returned unchanged. Composite conditions update each nested condition recursively.