An Elixir implementation of GEPA (Genetic-Pareto), a framework for optimizing text-based system components using LLM-based reflection and Pareto-efficient evolutionary search.
Add gepa_ex to your list of dependencies in mix.exs:
def deps do
[
{:gepa_ex, "~> 0.1.1"}
]
endGEPA optimizes arbitrary systems composed of text componentsβlike AI prompts, code snippets, or textual specsβagainst any evaluation metric. It employs LLMs to reflect on system behavior, using feedback from execution traces to drive targeted improvements.
This is an Elixir port of the Python GEPA library, designed to leverage:
- π BEAM concurrency for 5-10x evaluation speedup (coming in Phase 4)
- π‘οΈ OTP supervision for fault-tolerant external service integration
- π Functional programming for clean, testable code
- π Telemetry for comprehensive observability (coming in Phase 3)
- β¨ Production LLMs - OpenAI GPT-4o-mini & Google Gemini Flash Lite (
gemini-flash-lite-latest)
Optimization System:
- β
GEPA.optimize/1- Public API (working!) - β
GEPA.Engine- Full optimization loop with stop conditions - β
GEPA.Proposer.Reflective- Mutation strategy - β
GEPA.State- State management with automatic Pareto updates (96.5% coverage) - β
GEPA.Utils.Pareto- Multi-objective optimization (93.5% coverage, property-verified) - β
GEPA.Result- Result analysis (100% coverage) - β
GEPA.Adapters.Basic- Q&A adapter (92.1% coverage) - β Stop conditions with budget control
- β State persistence (save/load)
- β End-to-end integration tested
Production LLM Integration:
- β
GEPA.LLM- Unified LLM behavior - β
GEPA.LLM.ReqLLM- Production implementation via ReqLLM- OpenAI support (GPT-4o-mini default)
- Google Gemini support (gemini-flash-lite-latest)
- Error handling, retries, timeouts
- Configurable via environment or runtime
- β
GEPA.LLM.Mock- Testing implementation with flexible responses
Advanced Batch Sampling:
- β
GEPA.Strategies.BatchSampler.EpochShuffled- Epoch-based training with shuffling - β Reproducible with seed control
- β Better training dynamics than simple sampling
Working Examples:
- β 4 .exs script examples (quick start, math, custom adapter, persistence)
- β 3 Livebook notebooks (interactive learning)
- β Comprehensive examples/README.md guide
- β Livebook guide with visualizations
Phase 2 Additions - NEW! π
Merge Proposer:
- β
GEPA.Proposer.Merge- Genealogy-based candidate merging - β
GEPA.Utils- Pareto dominator detection (93.3% coverage) - β
GEPA.Proposer.MergeUtils- Ancestry tracking (92.3% coverage) - β Engine integration with merge scheduling
- β 44 comprehensive tests (34 unit + 10 properties)
Incremental Evaluation:
- β
GEPA.Strategies.EvaluationPolicy.Incremental- Progressive validation - β Configurable sample sizes and thresholds
- β Reduces computation on large validation sets
- β 12 tests
Advanced Stop Conditions:
- β
GEPA.StopCondition.Timeout- Time-based stopping - β
GEPA.StopCondition.NoImprovement- Early stopping - β Flexible time units and patience settings
- β 9 tests
Test Quality:
- 201 tests (185 unit + 16 properties + 1 doctest)
- 100% passing β
- 75.4% coverage (excellent!)
- Property tests with 1,600+ runs
- Zero Dialyzer errors
- TDD methodology throughout
β Phase 1: Production Viability - COMPLETE!
- β Real LLM integration (OpenAI, Gemini)
- β Quick start examples (4 scripts + 3 livebooks)
- β EpochShuffledBatchSampler
β Phase 2: Core Completeness - COMPLETE!
- β Merge proposer (genealogy-based recombination)
- β IncrementalEvaluationPolicy (progressive validation)
- β Additional stop conditions (Timeout, NoImprovement)
- β Engine integration for merge proposer
Phase 3: Production Hardening - 8-10 weeks
- π‘ Telemetry integration
- π¨ Progress tracking
- π‘οΈ Robust error handling
Phase 4: Ecosystem Expansion - 12-14 weeks
- π Additional adapters (Generic, RAG)
- π Performance optimization (parallel evaluation)
- π Community infrastructure
# Define training data
trainset = [
%{input: "What is 2+2?", answer: "4"},
%{input: "What is 3+3?", answer: "6"}
]
valset = [%{input: "What is 5+5?", answer: "10"}]
# Create adapter with mock LLM (for testing)
adapter = GEPA.Adapters.Basic.new(llm: GEPA.LLM.Mock.new())
# Run optimization
{:ok, result} = GEPA.optimize(
seed_candidate: %{"instruction" => "You are a helpful assistant."},
trainset: trainset,
valset: valset,
adapter: adapter,
max_metric_calls: 50
)
# Access results
best_program = GEPA.Result.best_candidate(result)
best_score = GEPA.Result.best_score(result)
IO.puts("Best score: #{best_score}")
IO.puts("Iterations: #{result.i}")# OpenAI (GPT-4o-mini) - Requires OPENAI_API_KEY
llm = GEPA.LLM.ReqLLM.new(provider: :openai)
adapter = GEPA.Adapters.Basic.new(llm: llm)
# Or Gemini (`gemini-flash-lite-latest`) - Requires GEMINI_API_KEY
llm = GEPA.LLM.ReqLLM.new(provider: :gemini)
adapter = GEPA.Adapters.Basic.new(llm: llm)
# Then run optimization as above
{:ok, result} = GEPA.optimize(
seed_candidate: %{"instruction" => "..."},
trainset: trainset,
valset: valset,
adapter: adapter,
max_metric_calls: 50
)See Examples overview for complete working examples!
For interactive learning and experimentation:
# Install Livebook
mix escript.install hex livebook
# Open a livebook
livebook server livebooks/01_quick_start.livemdAvailable Livebooks:
01_quick_start.livemd- Interactive introduction02_advanced_optimization.livemd- Parameter tuning and visualization03_custom_adapter.livemd- Build adapters interactively
See livebooks/README.md for details!
{:ok, result} = GEPA.optimize(
seed_candidate: seed,
trainset: trainset,
valset: valset,
adapter: GEPA.Adapters.Basic.new(),
max_metric_calls: 100,
run_dir: "./my_optimization" # State saved here, can resume
)# Get dependencies
mix deps.get
# Run tests
mix test
# Run with coverage
mix test --cover
# Run specific tests
mix test test/gepa/utils/pareto_test.exs
# Format code
mix format
# Type checking
mix dialyzerBased on behavior-driven design with functional core:
GEPA.optimize/1
β
GEPA.Engine β Behaviors β User Implementations
βββ Adapter (evaluate, reflect, propose)
βββ Proposer (reflective, merge)
βββ Strategies (selection, sampling, evaluation)
βββ StopCondition (budget, time, threshold)
- Technical Design
- Implementation Status
- LLM Adapter Design - Design for real LLM integration
- Documentation cleanup: removed broken links to non-existent documentation files
- Initial release with Phase 1 & 2 complete
- Production LLM integration (OpenAI GPT-4o-mini, Google Gemini Flash Lite)
- Core optimization engine with reflective and merge proposers
- Incremental evaluation and advanced stop conditions
- 218 tests passing with 75.4% coverage
- GEPA Python - Original implementation
- GEPA Paper - Research paper