# `GEPA.StopCondition`
[🔗](https://github.com/nshkrdotcom/gepa_ex/blob/v0.3.0/lib/gepa/stop_condition.ex#L1)

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
    end

## Composing Stop Conditions

Use `GEPA.StopCondition.Composite` to combine multiple conditions with AND/OR logic.

# `t`

```elixir
@type t() :: term()
```

# `should_stop?`

```elixir
@callback should_stop?(t(), GEPA.State.t()) :: boolean()
```

Check if optimization should stop based on current state.

## Parameters

- `condition`: The stop condition struct/state
- `gepa_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

# `should_stop?`

```elixir
@spec should_stop?(term(), GEPA.State.t()) :: boolean()
```

Evaluate a stop condition, callable, or module against the current state.

# `update`

```elixir
@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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
