Skip to content

Latest commit

 

History

History
632 lines (575 loc) · 38.9 KB

index.md

File metadata and controls

632 lines (575 loc) · 38.9 KB
template landing.html
title Optimize Anything with LLMs
description Optimize any text — prompts, code, agent architectures, configurations — using LLM-based reflection and Pareto-efficient evolutionary search. If you can measure it, you can optimize it.
hide
navigation
toc
title
GEPA Logo GEPA Logo

Automatically optimize prompts for any AI system

Frontier Performance, up to 90x cheaper | 35x faster than RL

Used by Shopify, Databricks and Dropbox

Downloads

:material-format-quote-close: What People Are Saying

Shopify
Tobi Lutke
CEO, Shopify
Both DSPy and (especially) GEPA are currently severely under hyped in the AI context engineering world
View on X
Databricks
Ivan Zhou
Research Engineer, Databricks Mosaic
GEPA can push open models beyond frontier performance; gpt-oss-120b + GEPA beats Claude Opus 4.1 while being 90x cheaper
View on X
Dropbox
Drew Houston
CEO, Dropbox
Have heard great things about DSPy plus GEPA, which is an even stronger prompt optimizer than miprov2 — repo and (fascinating) examples of generated prompts
View on X
<script> document.addEventListener('DOMContentLoaded', function() { const allTestimonials = [ { icon: '

Shopify

', author: 'Tobi Lutke', role: 'CEO, Shopify', content: 'Both DSPy and (especially) GEPA are currently severely under hyped in the AI context engineering world', linkUrl: 'https://x.com/tobi/status/1963434604741701909', linkIcon: '', linkText: 'View on X' }, { icon: '

Databricks

', author: 'Ivan Zhou', role: 'Research Engineer, Databricks Mosaic', content: 'GEPA can push open models beyond frontier performance; gpt-oss-120b + GEPA beats Claude Opus 4.1 while being 90x cheaper', linkUrl: 'https://x.com/ivanhzyy/status/1971066193747689521', linkIcon: '', linkText: 'View on X' }, { icon: '

Dropbox

', author: 'Drew Houston', role: 'CEO, Dropbox', content: 'Have heard great things about DSPy plus GEPA, which is an even stronger prompt optimizer than miprov2 — repo and (fascinating) examples of generated prompts', linkUrl: 'https://x.com/drewhouston/status/1974750621690728623', linkIcon: '', linkText: 'View on X' }, { icon: '', author: 'Chad Boyda', role: 'CTO, AppSumo', content: 'DSPy\'s GEPA is prompt engineering! The only kind we should all collectively be doing. What a work of art', linkUrl: 'https://x.com/chadboyda/status/1955298177197764963', linkIcon: '', linkText: 'View on X' }, { icon: '', author: 'OpenAI', role: 'Official Cookbook', content: 'Self-evolving agents that autonomously retrain themselves using GEPA to improve performance over time.', linkUrl: 'https://developers.openai.com/cookbook/examples/partners/self_evolving_agents/autonomous_agent_retraining', linkIcon: '', linkText: 'Read Cookbook' }, { icon: '

Dropbox

', author: 'Josh Clemm', role: 'VP of Engineering, Dropbox Dash', content: 'With DSPy [GEPA], you just plug the model in, define your goals, and out spits the prompt that works. So you can do this model switching far more rapidly.', linkUrl: 'https://dropbox.tech/machine-learning/vp-josh-clemm-knowledge-graphs-mcp-and-dspy-dash', linkIcon: '', linkText: 'Read More' } ]; function renderCard(t) { return `
${t.icon}
${t.author}
${t.role}
${t.content}
${t.linkIcon} ${t.linkText} `; } const grid = document.querySelector('.testimonials-grid'); if (!grid) return; const cards = grid.querySelectorAll('.testimonial-card'); // Track which testimonials are currently visible (indices into allTestimonials) let visible = [0, 1, 2]; // Queue of testimonials waiting to be shown let queue = [3, 4, 5]; let swapInterval; function swapOne() { if (queue.length === 0) { // Rebuild queue from all non-visible testimonials queue = []; for (let i = 0; i < allTestimonials.length; i++) { if (!visible.includes(i)) queue.push(i); } // Shuffle the queue for (let i = queue.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [queue[i], queue[j]] = [queue[j], queue[i]]; } } // Pick a random slot (0, 1, or 2) to replace const slotIndex = Math.floor(Math.random() * 3); const card = cards[slotIndex]; const nextTestimonialIndex = queue.shift(); // Animate out card.classList.add('testimonial-swap-out'); setTimeout(() => { // Swap content card.innerHTML = renderCard(allTestimonials[nextTestimonialIndex]); visible[slotIndex] = nextTestimonialIndex; // Animate in card.classList.remove('testimonial-swap-out'); card.classList.add('testimonial-swap-in'); setTimeout(() => { card.classList.remove('testimonial-swap-in'); }, 500); }, 500); } function startSwapping() { clearInterval(swapInterval); swapInterval = setInterval(swapOne, 3500); } function stopSwapping() { clearInterval(swapInterval); } grid.addEventListener('mouseenter', stopSwapping); grid.addEventListener('mouseleave', startSwapping); startSwapping(); }); </script>

:material-rocket-launch-outline: Get Started

PyPI GitHub stars Paper License
pip install gepa

=== "Basic Example"

```python
import gepa

# Load your dataset
trainset, valset, _ = gepa.examples.aime.init_dataset()

# Define your initial prompt
seed_prompt = {"system_prompt": "You are a helpful assistant..."}

# Run optimization
result = gepa.optimize(
    seed_candidate=seed_prompt,
    trainset=trainset,
    valset=valset,
    task_lm="openai/gpt-4.1-mini",
    max_metric_calls=150,
    reflection_lm="openai/gpt-5",
)

print(result.best_candidate['system_prompt'])
```

**Result:** +10% improvement (46.6% &rarr; 56.6%) on AIME 2025 with GPT-4.1 Mini

=== "With DSPy"

```python
import dspy

class RAG(dspy.Module):
    def __init__(self):
        self.retrieve = dspy.Retrieve(k=3)
        self.generate = dspy.ChainOfThought("context, question -> answer")

    def forward(self, question):
        context = self.retrieve(question).passages
        return self.generate(context=context, question=question)

# Optimize with GEPA
gepa = dspy.GEPA(
    metric=your_metric,
    max_metric_calls=150,
    reflection_lm="openai/gpt-5"
)
optimized_rag = gepa.compile(student=RAG(), trainset=trainset, valset=valset)
```

GEPA is built into DSPy! See [DSPy tutorials](https://dspy.ai/tutorials/gepa_ai_program/) for more.

=== "Custom System"

```python
from gepa import optimize
from gepa.core.adapter import EvaluationBatch

class MySystemAdapter:
    def evaluate(self, batch, candidate, capture_traces=False):
        outputs, scores, trajectories = [], [], []
        for example in batch:
            prompt = candidate['my_prompt']
            result = my_system.run(prompt, example)
            score = compute_score(result, example)
            outputs.append(result)
            scores.append(score)
            if capture_traces:
                trajectories.append({
                    'input': example,
                    'output': result.output,
                    'steps': result.intermediate_steps,
                    'errors': result.errors
                })
        return EvaluationBatch(
            outputs=outputs,
            scores=scores,
            trajectories=trajectories if capture_traces else None
        )

    def make_reflective_dataset(self, candidate, eval_batch, components_to_update):
        reflective_data = {}
        for component in components_to_update:
            reflective_data[component] = []
            for traj, score in zip(eval_batch.trajectories, eval_batch.scores):
                reflective_data[component].append({
                    'Inputs': traj['input'],
                    'Generated Outputs': traj['output'],
                    'Feedback': f"Score: {score}. Errors: {traj['errors']}"
                })
        return reflective_data

result = optimize(
    seed_candidate={'my_prompt': 'Initial prompt...'},
    trainset=my_trainset,
    valset=my_valset,
    adapter=MySystemAdapter(),
    task_lm="openai/gpt-4.1-mini",
)
```

:material-chart-line: Results

:material-cog: How It Works

Traditional optimizers (RL, evolutionary strategies) collapse rich execution traces into a single scalar reward — they know that a candidate failed, but not why. GEPA takes a different approach: evaluators return Actionable Side Information (ASI) — error messages, profiling data, reasoning logs — and an LLM reads this feedback to diagnose failures and propose targeted fixes. Each mutation inherits accumulated lessons from all ancestors in the search tree. GEPA also supports system-aware merge — combining strengths of two pareto-optimal candidates excelling on different tasks.

1
Select from
Pareto Front
Pick candidate excelling on some examples
→
2
Run on
Minibatch
Execute & capture full traces
→
3
Reflect with
LLM
Diagnose failures in natural language
→
4
Mutate
Prompt
Accumulate lessons from ancestors and new rollouts
→
5
Accept if
Improved
Add to pool & update Pareto front
Repeat until convergence
Based on research from UC Berkeley, Stanford, MIT & Databricks. Learn how it works → | Read the paper →

:material-application: GEPA Case Studies

:material-target: GEPA Shines When

Rollouts Are Expensive
  • Scientific simulations, slow compilation
  • Complex agents with long tool calls
  • 100–500 evals vs. 10K+ for RL
Data Is Scarce
  • New hardware with zero training data
  • Works with as few as 3 examples
  • Rapid prototyping on novel domains
API-Only Models
  • No weights access needed
  • Optimize GPT-5, Claude, Gemini directly
  • No custom infra or fine-tuning pipeline
You Need Interpretability
  • Human-readable optimization traces
  • See why each prompt changed
  • Debug complex agent behaviors

!!! note "GEPA complements RL and fine-tuning" These approaches are not mutually exclusive. Use GEPA for rapid initial optimization (minutes to hours, API-only access), then apply RL or fine-tuning for additional gains as demonstrated in BetterTogether / mmGRPO recipe. For scenarios with abundant data and 100,000+ cheap rollouts, gradient-based methods remain effective — GEPA works best when rollouts are expensive, data is scarce, or you need interpretable optimization traces.

:material-account-group: Community & Resources

Built something with GEPA? We'd love to feature your work.

:material-format-quote-close: Citation

If you use GEPA in your research, please cite our paper:

@misc{agrawal2025gepareflectivepromptevolution,
      title={GEPA: Reflective Prompt Evolution Can Outperform Reinforcement Learning},
      author={Lakshya A Agrawal and Shangyin Tan and Dilara Soylu and Noah Ziems and
              Rishi Khare and Krista Opsahl-Ong and Arnav Singhvi and Herumb Shandilya and
              Michael J Ryan and Meng Jiang and Christopher Potts and Koushik Sen and
              Alexandros G. Dimakis and Ion Stoica and Dan Klein and Matei Zaharia and Omar Khattab},
      year={2025},
      eprint={2507.19457},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2507.19457}
}