Skip to main content
GEPA (Generalized Evolutionary Prompt Adaptation) is a reflective evolutionary optimizer that automatically improves your prompts through LLM-guided mutations and multi-objective selection. This walkthrough covers everything from setup to retrieving your optimized prompts. Reference: Agrawal et al. (2025). “GEPA: Reflective Prompt Evolution.” arXiv:2507.19457

Why GEPA?

GEPA outperforms GRPO by 10% on average (up to 20%) while using up to 35x fewer rollouts. Best for:
  • Classification tasks (Banking77, intent classification)
  • Multi-hop QA (HotpotQA)
  • Instruction-following tasks
  • When you want diverse prompt variants (Pareto front)
Typical results: 60-75% baseline accuracy → 85-90%+ after 15 generations

Prerequisites

Before starting, ensure you have:
Install the Synth AI SDK:

How GEPA Works

GEPA uses evolutionary principles to explore the prompt space. Understanding the algorithm helps you configure it effectively.

The Optimization Flow

  1. Initialize
    • Split seeds into pareto_seeds and feedback_seeds
    • Evaluate baseline transformation
    • Generate initial population via proposer
    • Evaluate & add to Pareto archive
  2. Evolve (for each generation)
    • For each child:
      • Select parent (instance-wise Pareto sampling)
      • Generate feedback from parent trace
      • Mutate via proposer (LLM-guided)
      • Minibatch gating (quick eval)
      • Full Pareto evaluation (if gating passed)
      • Update archive if non-dominated
  3. Terminate
    • Budget exhausted OR
    • Generation limit OR
    • No improvement for N generations
  4. Return best transformation, by accuracy

Key Components

1. Pattern-Based Transformations

GEPA represents prompt changes as transformations that can be applied to your baseline:

2. Pareto Archive

GEPA maintains a Pareto front of non-dominated solutions, balancing multiple objectives:
  • Accuracy (primary) – Task performance
  • Tool call rate – Function calling frequency (for agentic tasks)
Solutions are kept if they’re not dominated by any other solution across all objectives.

3. Instance-Wise Parent Selection

Unlike traditional selection that uses aggregate scores, GEPA counts how many individual seeds each prompt “wins” on:
This favors prompts that excel on specific example types, encouraging specialization.

4. LLM-Guided Mutations

The proposer (meta-model) generates new prompts by analyzing:
  • Current instruction (baseline)
  • Rollout examples (input/output/feedback for each seed)
  • Trace feedback (e.g., “model under-utilizes tools”)
  • Dataset and program context
The proposer uses instruction typology to structure outputs with: input descriptions, core task, premises, heuristics, constraints, rules, and output descriptions.

Step 1: Create a LocalAPI

Your LocalAPI evaluates prompts by running rollouts and returning scores. See LocalAPI Guide for details. Example Banking77 LocalAPI structure:

Step 2: Deploy Your LocalAPI

The Synth AI backend needs to reach your LocalAPI over the internet to send rollout requests. Use the Python SDK’s InProcessTaskApp for seamless deployment with automatic tunneling:
This:
  1. Starts your LocalAPI locally
  2. Creates a SynthTunnel URL (or another tunnel backend if configured)
  3. Returns the tunnel URL via task_app.url

Verify the Deployment

Check that your LocalAPI is accessible:

Alternative Tunnel Backends

SynthTunnel is the default and recommended backend. If you need a Cloudflare tunnel instead:

Step 3: Create the Configuration

Create a TOML file defining your optimization parameters. The task_app_url should match the URL from Step 2 (stored in your .env as TASK_APP_URL):

Configuration Parameters

Step 4: Launch the Optimization Job

The SDK will:
  1. Validate your TOML configuration
  2. Verify the task app is reachable
  3. Submit the job to Synth AI
  4. Poll for completion

Understanding the Output

During optimization, you’ll see progress updates:
Your LocalAPI logs will show rollout requests:

Step 5: Understanding the Optimization Process

Generation-by-Generation Progress

How Mutations Are Generated

The proposer receives:
  1. Baseline instruction: Your current system prompt
  2. Rollout examples: Input/output pairs with feedback (correct/incorrect, error messages)
  3. Trace statistics: Tool call rate, trajectory length, etc.
  4. Feedback hints: Rule-based suggestions like “model under-utilizes tools”
It generates a new instruction following instruction typology:

Minibatch Gating

Before full evaluation, GEPA performs a quick check:
  1. Evaluate child on a small minibatch (3 seeds)
  2. Compare to parent’s score on the same seeds
  3. If child is worse → skip full evaluation (saves budget)
  4. If child is promising → proceed to full Pareto evaluation
This saves significant compute by filtering out poor mutations early.

Step 6: Retrieve Optimized Prompts

After completion, fetch your results using the Python SDK:

Understanding the Pareto Front

GEPA returns multiple prompts representing different trade-offs: Choose based on your latency/cost requirements.

Step 7: Use the Optimized Prompt

Replace your baseline prompt with the optimized version:

In-Process Optimization

For development and testing, run everything from a single Python script:
See In-Process Task App Walkthrough for a complete example.

Termination Conditions

GEPA stops when any condition is met:

Supported Models

See Supported Models for Prompt Optimization for the full list of policy models.