# `Imp.Optimizer.GEPA.Callback`
[🔗](https://github.com/deepfates/imp/blob/v0.18.1/lib/imp/optimizer/gepa/callback.ex#L1)

Synchronous, observational callbacks for GEPA optimization.

This behaviour mirrors the lifecycle in GEPA `v0.1.1` while making the
callback contract explicit for the BEAM. A callback is a module or
`{module, context}`. Every hook is optional and takes `(event, context)`:
the event map, and the context the callback was registered with, or `nil`
for a bare module.

Callbacks run synchronously in registration order. Their return values are
ignored, so callbacks cannot replace optimizer state or decisions. A callback
failure is isolated, reported as redacted telemetry and a warning, and does
not prevent later callbacks from observing the event.

    defmodule AuditCallback do
      @behaviour Imp.Optimizer.GEPA.Callback

      @impl true
      def on_iteration_end(event, owner) do
        send(owner, {:gepa_iteration, event.iteration, event.proposal_accepted})
      end
    end

    Imp.Optimizer.GEPA.new(metric, callbacks: [{AuditCallback, self()}])

Event maps use atom keys and expose immutable Elixir values. In particular,
`:state` and `:final_state` are snapshots by value rather than mutable handles.
Candidate identifiers, rejection reasons, trajectories, and exceptions stay
as native Elixir terms rather than being stringified. This is the deliberate
Elixir equivalent of upstream's observational state access.

# `callback`

```elixir
@type callback() :: module() | {module(), term()}
```

# `callbacks`

```elixir
@type callbacks() :: [callback()]
```

# `event`

```elixir
@type event() :: map()
```

# `on_budget_updated`
*optional* 

```elixir
@callback on_budget_updated(event(), context :: term()) :: term()
```

# `on_candidate_accepted`
*optional* 

```elixir
@callback on_candidate_accepted(event(), context :: term()) :: term()
```

# `on_candidate_rejected`
*optional* 

```elixir
@callback on_candidate_rejected(event(), context :: term()) :: term()
```

# `on_candidate_selected`
*optional* 

```elixir
@callback on_candidate_selected(event(), context :: term()) :: term()
```

# `on_combee_aggregation`
*optional* 

```elixir
@callback on_combee_aggregation(event(), context :: term()) :: term()
```

# `on_combee_batch_selected`
*optional* 

```elixir
@callback on_combee_batch_selected(event(), context :: term()) :: term()
```

# `on_error`
*optional* 

```elixir
@callback on_error(event(), context :: term()) :: term()
```

# `on_evaluation_end`
*optional* 

```elixir
@callback on_evaluation_end(event(), context :: term()) :: term()
```

# `on_evaluation_skipped`
*optional* 

```elixir
@callback on_evaluation_skipped(event(), context :: term()) :: term()
```

# `on_evaluation_start`
*optional* 

```elixir
@callback on_evaluation_start(event(), context :: term()) :: term()
```

# `on_iteration_end`
*optional* 

```elixir
@callback on_iteration_end(event(), context :: term()) :: term()
```

# `on_iteration_start`
*optional* 

```elixir
@callback on_iteration_start(event(), context :: term()) :: term()
```

# `on_merge_accepted`
*optional* 

```elixir
@callback on_merge_accepted(event(), context :: term()) :: term()
```

# `on_merge_attempted`
*optional* 

```elixir
@callback on_merge_attempted(event(), context :: term()) :: term()
```

# `on_merge_rejected`
*optional* 

```elixir
@callback on_merge_rejected(event(), context :: term()) :: term()
```

# `on_minibatch_sampled`
*optional* 

```elixir
@callback on_minibatch_sampled(event(), context :: term()) :: term()
```

# `on_optimization_end`
*optional* 

```elixir
@callback on_optimization_end(event(), context :: term()) :: term()
```

# `on_optimization_start`
*optional* 

```elixir
@callback on_optimization_start(event(), context :: term()) :: term()
```

# `on_pareto_front_updated`
*optional* 

```elixir
@callback on_pareto_front_updated(event(), context :: term()) :: term()
```

# `on_proposal_end`
*optional* 

```elixir
@callback on_proposal_end(event(), context :: term()) :: term()
```

# `on_proposal_start`
*optional* 

```elixir
@callback on_proposal_start(event(), context :: term()) :: term()
```

# `on_reflective_dataset_built`
*optional* 

```elixir
@callback on_reflective_dataset_built(event(), context :: term()) :: term()
```

# `on_state_saved`
*optional* 

```elixir
@callback on_state_saved(event(), context :: term()) :: term()
```

# `on_valset_evaluated`
*optional* 

```elixir
@callback on_valset_evaluated(event(), context :: term()) :: term()
```

# `events`

```elixir
@spec events() :: [atom()]
```

Returns the callback lifecycle hook names in upstream order.

---

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