Overview
GEPA (Genetic-Pareto) is an evolutionary optimization framework that evolves text parameters using LLM-based reflection and Pareto-efficient search. Unlike traditional optimizers that only know that a candidate failed, GEPA uses LLMs to understand why it failed and proposes targeted improvements.Core Architecture
GEPA’s architecture consists of several key components working together:The Optimization Loop
GEPA’s optimization follows a five-step iterative process:1. Select
Select a candidate from the Pareto frontier — the set of candidates where each excels on different subsets of the validation set.- Preservation of specialized improvements
- Cross-pollination between candidates via merge
- Diverse exploration without premature convergence
2. Execute
Evaluate the selected candidate on a small minibatch of training examples (typically 1-3), capturing full execution traces:- Outputs and scores for each example
- Trajectories: Execution traces showing intermediate steps
- Error messages, reasoning logs, profiling data
The minibatch approach is key to efficiency: instead of showing hundreds of examples at once, GEPA focuses the LLM on 1-3 examples for targeted improvements. Over iterations, all examples get attention.
3. Reflect
The adapter builds a reflective dataset from the captured traces, then an LLM analyzes failures and identifies root causes:- Diagnoses why failures occurred
- Identifies patterns across multiple examples
- Understands domain constraints and requirements
4. Mutate
The reflection LM proposes an improved candidate, informed by:- Current component text being optimized
- Reflective dataset with failure analysis
- Accumulated lessons from ancestor candidates in the lineage
- Objective and background (optional domain guidance)
- The current parameter value
- Evaluation feedback structured as side information
- Instructions to analyze failures and propose improvements
5. Accept
Test the new candidate on the same minibatch:- New candidate must strictly improve on the minibatch (sum of scores)
- If accepted, full validation evaluation determines Pareto front membership
- Candidates that improve on any validation example join the frontier
Key Components
GEPAAdapter
The adapter is your integration point with GEPA. It implements three responsibilities:evaluate(): Execute your system with a candidate and return scores/tracesmake_reflective_dataset(): Extract meaningful feedback from execution tracespropose_new_texts()(optional): Custom proposal logic (defaults to LLM-based)
GEPAEngine
The engine orchestrates the optimization loop:GEPAState
Maintains all optimization state:program_candidates: All explored candidatesprog_candidate_val_subscores: Per-example validation scoresprog_candidate_objective_scores: Per-objective aggregate scores- Pareto frontiers: Instance-level, objective-level, hybrid, or cartesian
evaluation_cache: Optional cache for (candidate, example) pairs- Budget tracking: Total evaluations consumed
Three Optimization Modes
GEPA unifies three paradigms under one API:1. Single-Task Search
When:dataset=None, valset=None
Use case: Solve one hard problem. The candidate is the solution.
Example: Circle packing, SVG optimization, mathematical puzzle solving
2. Multi-Task Search
When:dataset=<list>, valset=None
Use case: Solve a batch of related problems with cross-task transfer.
Example: CUDA kernel generation for multiple operations
3. Generalization
When:dataset=<list>, valset=<list>
Use case: Build a skill that transfers to unseen problems.
Example: Prompt optimization for competition math
Efficiency Features
Evaluation Caching
GEPA can cache(candidate, example) evaluation results:
- Expensive evaluations (compilation, simulation, API calls)
- Candidates may be re-evaluated across iterations
- Deterministic evaluation functions
Parallel Evaluation
Parallelize validation set evaluation:State Persistence
GEPA automatically saves/resumes state whenrun_dir is set:
Next Steps
Reflective Evolution
Learn how LLM-based reflection drives candidate improvement
Pareto Optimization
Understand multi-objective Pareto-efficient search
Actionable Side Information
Master the key concept that makes text optimization work
Quickstart
Try GEPA on a real example