# OpenEvolve

> Evolutionary coding agent that has an LLM mutate a program until a scorer says it improved

- Category: AI Coding / Autonomous Coding Agents
- Language: Python
- Licence: Apache-2.0
- Repository: https://github.com/algorithmicsuperintelligence/openevolve
- Canonical page: https://ai-tldr.dev/tools/openevolve/

## In short

OpenEvolve is an open-source implementation of AlphaEvolve — an evolutionary coding agent. It sits in the Autonomous Coding Agents category of the AI Coding tools and is open-source, written in Python and licensed Apache-2.0. To get started: install from PyPI.

## Overview

OpenEvolve is an open-source implementation of AlphaEvolve — an evolutionary coding agent. You hand it a starting program and an evaluator that returns one or more scores; it then loops, asking an LLM to produce variants, running your evaluator on each, and keeping the ones that score better. The loop is what distinguishes it from a chat-based refactor: the model proposes, a program you wrote judges, and only measured improvements survive.

Because the selection signal is your evaluator rather than a human reading diffs, OpenEvolve is aimed at problems where "better" is a number you can compute: a kernel that runs faster, a packing that fits more circles, a filter with less error. The project runs evolution across parallel islands and supports multi-objective runs with automatic Pareto selection, so several competing metrics can be optimised at once. The repository's own example gallery covers GPU kernel discovery with MLX Metal shaders, circle packing, adaptive sorting in Rust, and automated signal-processing filter design, spanning Python, Rust, R and Metal.

It works either as a CLI over files — an initial program, an evaluator and a YAML config — or as a library, where `run_evolution` takes inline source and a callable evaluator and `evolve_function` evolves a Python function directly against test cases. The shipped example config targets Google Gemini by default, but any OpenAI-compatible provider can be used by editing the config.

## What it does

- Evolutionary loop: an LLM proposes program variants, your evaluator scores them, and the best are carried forward
- Parallel evolution across islands, so exploration is not a single hill-climbing chain
- Multi-objective runs with automatic Pareto selection when you return several metrics
- Language-agnostic — the shipped examples evolve Python, Rust, R and Metal shader code
- Usable as a CLI over program/evaluator/config files, or as a library with inline code and a callable evaluator
- Any OpenAI-compatible provider can drive the evolution by editing the YAML config

## Getting started

OpenEvolve is on PyPI. The quickest route is to run one of the bundled examples so you can see the loop before writing your own evaluator.

1. Install from PyPI

   A pip install is all that is needed; Docker options are documented in the repository's installation section.

```bash
pip install openevolve
```

2. Point it at a model

   The bundled example config uses Google Gemini by default and still reads the key from OPENAI_API_KEY. Any OpenAI-compatible provider works if you edit config.yaml.

```bash
export OPENAI_API_KEY="your-gemini-api-key"
```

3. Run a bundled example

   The runner takes the initial program, the evaluator, a config and an iteration budget. Function minimization is the smallest example.

```bash
python openevolve-run.py examples/function_minimization/initial_program.py \
  examples/function_minimization/evaluator.py \
  --config examples/function_minimization/config.yaml \
  --iterations 50
```

4. Or drive it from Python

   The library API needs no external files: pass the starting source and an evaluator callable, or evolve a function directly against test cases.

```python
from openevolve import run_evolution, evolve_function

result = run_evolution(
    initial_program='''
    def fibonacci(n):
        if n <= 1: return n
        return fibonacci(n-1) + fibonacci(n-2)
    ''',
    evaluator=lambda path: {"score": benchmark_fib(path)},
    iterations=100,
)

result = evolve_function(
    bubble_sort,
    test_cases=[([3, 1, 2], [1, 2, 3]), ([5, 2, 8], [2, 5, 8])],
    iterations=50,
)
print(f"Evolved sorting algorithm: {result.best_code}")
```

5. Write your own evaluator

   The evaluator is the whole design decision: it receives a candidate program path and returns the metric dict that decides what survives. Return several keys to get multi-objective Pareto selection.

## When to use it

- Search for a faster GPU or CPU kernel when you can benchmark candidates but can't see the optimum by inspection
- Attack a combinatorial or geometric optimisation problem where a scorer is easy to write and the algorithm is not
- Tune a numerical routine — a filter, a solver, a heuristic — against a fixed error or throughput target
- Trade several metrics off at once (speed against accuracy, say) and read the Pareto front instead of picking a weighting up front
