Skip to content

GEPACallback

gepa.core.callbacks.GEPACallback

Bases: Protocol

Protocol for GEPA optimization callbacks.

All methods are optional - implement only those you need. Callbacks are called synchronously and should not modify the state.

Functions

on_optimization_start(event: OptimizationStartEvent) -> None

Called when optimization begins.

Source code in gepa/core/callbacks.py
def on_optimization_start(self, event: OptimizationStartEvent) -> None:
    """Called when optimization begins."""
    ...

on_optimization_end(event: OptimizationEndEvent) -> None

Called when optimization completes.

Source code in gepa/core/callbacks.py
def on_optimization_end(self, event: OptimizationEndEvent) -> None:
    """Called when optimization completes."""
    ...

on_iteration_start(event: IterationStartEvent) -> None

Called at the start of each iteration.

Source code in gepa/core/callbacks.py
def on_iteration_start(self, event: IterationStartEvent) -> None:
    """Called at the start of each iteration."""
    ...

on_iteration_end(event: IterationEndEvent) -> None

Called at the end of each iteration.

Source code in gepa/core/callbacks.py
def on_iteration_end(self, event: IterationEndEvent) -> None:
    """Called at the end of each iteration."""
    ...

on_candidate_selected(event: CandidateSelectedEvent) -> None

Called when a candidate is selected for mutation.

Source code in gepa/core/callbacks.py
def on_candidate_selected(self, event: CandidateSelectedEvent) -> None:
    """Called when a candidate is selected for mutation."""
    ...

on_minibatch_sampled(event: MinibatchSampledEvent) -> None

Called when a training minibatch is sampled.

Source code in gepa/core/callbacks.py
def on_minibatch_sampled(self, event: MinibatchSampledEvent) -> None:
    """Called when a training minibatch is sampled."""
    ...

on_evaluation_start(event: EvaluationStartEvent) -> None

Called before evaluating a candidate.

Source code in gepa/core/callbacks.py
def on_evaluation_start(self, event: EvaluationStartEvent) -> None:
    """Called before evaluating a candidate."""
    ...

on_evaluation_end(event: EvaluationEndEvent) -> None

Called after evaluating a candidate.

Source code in gepa/core/callbacks.py
def on_evaluation_end(self, event: EvaluationEndEvent) -> None:
    """Called after evaluating a candidate."""
    ...

on_evaluation_skipped(event: EvaluationSkippedEvent) -> None

Called when an evaluation is skipped or its results are not used.

Source code in gepa/core/callbacks.py
def on_evaluation_skipped(self, event: EvaluationSkippedEvent) -> None:
    """Called when an evaluation is skipped or its results are not used."""
    ...

on_valset_evaluated(event: ValsetEvaluatedEvent) -> None

Called after a candidate is evaluated on the validation set.

Source code in gepa/core/callbacks.py
def on_valset_evaluated(self, event: ValsetEvaluatedEvent) -> None:
    """Called after a candidate is evaluated on the validation set."""
    ...

on_reflective_dataset_built(event: ReflectiveDatasetBuiltEvent) -> None

Called after building the reflective dataset.

Source code in gepa/core/callbacks.py
def on_reflective_dataset_built(self, event: ReflectiveDatasetBuiltEvent) -> None:
    """Called after building the reflective dataset."""
    ...

on_proposal_start(event: ProposalStartEvent) -> None

Called before proposing new instructions.

Source code in gepa/core/callbacks.py
def on_proposal_start(self, event: ProposalStartEvent) -> None:
    """Called before proposing new instructions."""
    ...

on_proposal_end(event: ProposalEndEvent) -> None

Called after proposing new instructions.

Source code in gepa/core/callbacks.py
def on_proposal_end(self, event: ProposalEndEvent) -> None:
    """Called after proposing new instructions."""
    ...

on_candidate_accepted(event: CandidateAcceptedEvent) -> None

Called when a new candidate is accepted.

Source code in gepa/core/callbacks.py
def on_candidate_accepted(self, event: CandidateAcceptedEvent) -> None:
    """Called when a new candidate is accepted."""
    ...

on_candidate_rejected(event: CandidateRejectedEvent) -> None

Called when a candidate is rejected.

Source code in gepa/core/callbacks.py
def on_candidate_rejected(self, event: CandidateRejectedEvent) -> None:
    """Called when a candidate is rejected."""
    ...

on_merge_attempted(event: MergeAttemptedEvent) -> None

Called when a merge is attempted.

Source code in gepa/core/callbacks.py
def on_merge_attempted(self, event: MergeAttemptedEvent) -> None:
    """Called when a merge is attempted."""
    ...

on_merge_accepted(event: MergeAcceptedEvent) -> None

Called when a merge is accepted.

Source code in gepa/core/callbacks.py
def on_merge_accepted(self, event: MergeAcceptedEvent) -> None:
    """Called when a merge is accepted."""
    ...

on_merge_rejected(event: MergeRejectedEvent) -> None

Called when a merge is rejected.

Source code in gepa/core/callbacks.py
def on_merge_rejected(self, event: MergeRejectedEvent) -> None:
    """Called when a merge is rejected."""
    ...

on_pareto_front_updated(event: ParetoFrontUpdatedEvent) -> None

Called when the Pareto front is updated.

Source code in gepa/core/callbacks.py
def on_pareto_front_updated(self, event: ParetoFrontUpdatedEvent) -> None:
    """Called when the Pareto front is updated."""
    ...

on_state_saved(event: StateSavedEvent) -> None

Called after state is saved to disk.

Source code in gepa/core/callbacks.py
def on_state_saved(self, event: StateSavedEvent) -> None:
    """Called after state is saved to disk."""
    ...

on_budget_updated(event: BudgetUpdatedEvent) -> None

Called when the evaluation budget is updated.

Source code in gepa/core/callbacks.py
def on_budget_updated(self, event: BudgetUpdatedEvent) -> None:
    """Called when the evaluation budget is updated."""
    ...

on_error(event: ErrorEvent) -> None

Called when an error occurs during optimization.

Source code in gepa/core/callbacks.py
def on_error(self, event: ErrorEvent) -> None:
    """Called when an error occurs during optimization."""
    ...