AlphaEvolve, Evolutionary Coding Agents
Pair a frontier coding model with an evolutionary loop and a machine-checkable evaluator. Let the loop run long enough. It discovers a 4x4 complex-matrix multiplication procedure that uses 48 scalar multiplications, the first improvement over Strassen in 56 years. It also finds a Google-wide Borg scheduling heuristic that recovers ~0.7% of cluster compute in production. The architecture is boring on purpose. The wins come from the evaluator's rigor.
The Problem
Large language models can write code. Evolutionary algorithms can search over code. Both have been tried separately for decades; both hit ceilings. The LLM ceiling is confabulation: the model writes plausible code that does not do what it claims. The evolutionary ceiling is search cost: random mutations over syntax rarely produce compilable programs, let alone better ones.
AlphaEvolve (Novikov et al., DeepMind, arXiv:2506.13131, June 2025) combines them. The LLM proposes targeted edits to a program database; an automatic evaluator scores each variant; high-scoring variants become parents for future generations. The LLM handles the expensive step of writing plausible code; the evaluator catches the confabulations. The loop runs for hours to weeks.
Results reported: 48-scalar-multiplication 4x4 complex matrix multiplication (Strassen's 1969 bound was 49), a Borg scheduling heuristic in Google production, a 32.5% FlashAttention kernel speedup, Gemini training throughput improvements.
The architecture works because the evaluator is machine-checkable. It does not work where the evaluator isn't. That asymmetry is the lesson.
The Concept
The loop
- Start from a seed program
P_0that is correct but suboptimal. - Maintain a database of variant programs, each scored by the evaluator.
- Sample one or more parents from the database (MAP-elites-style or island-based).
- Prompt the LLM (Gemini Flash for many candidates, Gemini Pro for the hard ones) to produce a modified variant of the parent.
- Compile, run, and evaluate the variant on the held-out evaluator.
- Insert into the database keyed by its score and feature vector.
- Repeat.
Two details matter. First, the LLM is prompted with more than the parent program, typically several top variants from the database, plus the evaluator signature, plus a short task description. The model's job is to propose a targeted change that might improve the score. Second, the database is structured (MAP-elites grid, island-based) so the loop explores diversity, not just the current leader.
What makes the evaluator non-negotiable
AlphaEvolve's wins all come from domains where the evaluator is fast, deterministic, and hard to game:
- Matrix multiplication algorithm: a unit test that multiplies matrices and checks equality bit-identically.
- Borg scheduling heuristic: a production-grade simulator that replays historical cluster load and measures wasted compute.
- FlashAttention kernel: a correctness test plus a wall-clock benchmark on real hardware.
- Gemini training throughput: measured GPU-seconds per step.
In each case the evaluator catches the class of LLM errors that would otherwise dominate: confabulated correctness claims, performance claims that vanish on hardware, and edge-case failures. Remove the evaluator and the loop optimizes for pretty code.
Reward hacking is the other face of that statement
Evolution optimizes for whatever the evaluator measures. If the evaluator is imperfect, the loop will find the imperfection. In an unverified domain the loop would optimize for the surface feature, not the intended behavior. DeepMind flags this explicitly in the paper: AlphaEvolve's successes transfer only to domains where evaluator rigor matches the ambition of the search.
Concrete 2025-2026 examples of reward hacking in code-search loops:
- Optimization targets that reward "time to complete" rewarded submitting empty solutions.
- Benchmark scores that reward correctness-under-test rewarded memorizing tests and overfitting.
- A "code quality" proxy rewarded removing comments and rewriting variable names, with no semantic change.
The fix in AlphaEvolve: ship a held-out evaluator the LLM has never seen, with inputs generated at evaluation time. Even then, DeepMind recommends strong review on any proposed deployment.
Why LLM + search beats either alone
The LLM can produce compilable, semantically plausible modifications. A random-mutation GA on a 2000-line Python file almost always produces syntax errors. The LLM also concentrates search on plausible neighborhoods (change one function, not random bytes) which dramatically reduces wasted evaluator calls.
The evaluator, in turn, catches the LLM's confabulations. LLMs will confidently claim that a function "is $O(n \log n)$ in the limit" when it is actually $O(n^2)$; a wall-clock benchmark makes the question settled.
Where AlphaEvolve fits in the frontier stack
| System | Generator | Evaluator | Domain | Example win |
|---|---|---|---|---|
| AlphaEvolve | Gemini | correctness + benchmark | algorithms, kernels, schedulers | 48-mul 4x4 matmul |
| FunSearch (DeepMind, 2023) | PaLM / Codey | correctness | combinatorial math | cap-set lower bounds |
| AI Scientist v2 (Sakana, L5) | GPT/Claude | LLM critique + experiment | ML research | ICLR workshop paper |
| Darwin Godel Machine (L4) | agent scaffolding | SWE-bench / Polyglot | agent code | 20% → 50% SWE-bench |
All four are variations on the same recipe: generator plus evaluator, loop. The differences are what the evaluator grades and how rigorous it is.
Use It
code/main.py implements a minimal AlphaEvolve-like loop over a toy symbolic-regression problem. The "LLM" is a stdlib proxy that proposes small syntactic mutations to a program that computes a target function. The "evaluator" measures mean squared error on held-out test points.
Watch:
- How the best score improves over generations.
- How a MAP-elites grid keeps diverse solutions alive so the loop doesn't converge on a local minimum.
- How removing the held-out test (training-only evaluator) lets the loop overfit spectacularly.
Ship It
outputs/skill-evaluator-rigor-audit.md is the precondition for considering an AlphaEvolve-style loop in a new domain: does your evaluator actually catch the failures you care about?
Exercises
- Run
code/main.py. Note the best score trajectory. Disable the held-out evaluator (flag--no-holdout) and re-run. Quantify the overfitting. - Read Section 3 of the AlphaEvolve paper on the MAP-elites grid. Design a feature-vector descriptor for a new problem (e.g. compiler optimization passes) that would keep the search diverse.
- The 48-multiplication 4x4 result improved on Strassen's 49-mul bound after 56 years. Read Appendix F of the paper and explain in three sentences why the evaluator for this problem is particularly easy to get right, and why most domains are not like it.
- Propose one domain where AlphaEvolve would fail. Identify exactly where the evaluator breaks and why.
- For a domain you know, write the evaluator signature you would use. Include (a) correctness conditions, (b) performance metric, (c) held-out input generation rule, (d) at least one anti-reward-hacking check.
Key Terms
| Term | What people say | What it actually means |
|---|---|---|
| AlphaEvolve | "DeepMind's evolutionary coding agent" | Gemini + program database + machine-checkable evaluator |
| MAP-elites | "Diversity-preserving archive" | Grid keyed by feature vectors; each cell holds the best variant with that descriptor |
| Island model | "Parallel evolution subpopulations" | Independent populations that migrate periodically; prevents premature convergence |
| Machine-checkable evaluator | "Deterministic oracle" | A unit test, simulator, or benchmark the LLM cannot fake, a prerequisite for this loop |
| Reward hacking | "Optimizing the measure, not the goal" | Loop finds a way to maximize score without doing the intended task |
| Seed program | "The starting point" | An initial correct-but-suboptimal program the loop evolves from |
| Held-out evaluator | "Evaluation data the LLM never saw" | Inputs generated at evaluation time to prevent memorization |
Further Reading
- Novikov et al. (2025). AlphaEvolve: A coding agent for scientific and algorithmic discoverythe full paper.
- DeepMind blog on AlphaEvolvevendor writeup with results.
- AlphaEvolve results repositorydiscovered algorithms, including the 48-mul 4x4 matmul.
- Romera-Paredes et al. (2023). Mathematical discoveries from program search with LLMs (FunSearch)the predecessor system.
- Anthropic, Responsible Scaling Policy v3.0 (Feb 2026)frames evaluator-bound autonomy as a key research direction.
The full code
Every file for this lesson. Copy it, run it, then change it.
"""Minimal AlphaEvolve-like evolutionary loop — stdlib Python.
Toy symbolic regression. The "LLM" proposes a small mutation to a candidate
expression (change a constant, change an operator, add a term). The
"evaluator" scores the expression on training and held-out test points.
MAP-elites grid keeps diverse candidates: cell keyed by (expression depth,
constant magnitude bucket). Without a held-out split the loop overfits
aggressively; with one the best candidate generalizes.
"""
from __future__ import annotations
import argparse
import math
import random
from dataclasses import dataclass
DEFAULT_SEED = 1
# Target function the loop tries to rediscover.
def target(x: float) -> float:
return 2.0 * x * x + 3.0 * x - 1.0
Expr = tuple # recursive: ("num", v) | ("x",) | ("add", a, b) | ("mul", a, b)
def evaluate_expr(e: Expr, x: float) -> float:
tag = e[0]
if tag == "num":
return float(e[1])
if tag == "x":
return x
if tag == "add":
return evaluate_expr(e[1], x) + evaluate_expr(e[2], x)
if tag == "mul":
return evaluate_expr(e[1], x) * evaluate_expr(e[2], x)
raise ValueError(tag)
def depth(e: Expr) -> int:
tag = e[0]
if tag in ("num", "x"):
return 1
return 1 + max(depth(e[1]), depth(e[2]))
def max_const(e: Expr) -> float:
tag = e[0]
if tag == "num":
return abs(e[1])
if tag == "x":
return 0.0
return max(max_const(e[1]), max_const(e[2]))
def mutate(e: Expr) -> Expr:
"""Stand-in for the LLM's targeted edit."""
choice = random.random()
if choice < 0.25:
return random_leaf()
if choice < 0.5:
return ("add", e, random_leaf())
if choice < 0.75:
return ("mul", e, random_leaf())
# perturb a constant somewhere
return perturb(e)
def perturb(e: Expr) -> Expr:
tag = e[0]
if tag == "num":
return ("num", e[1] + random.choice([-1.0, -0.5, 0.5, 1.0]))
if tag == "x":
return e
return (tag, perturb(e[1]), e[2]) if random.random() < 0.5 else (tag, e[1], perturb(e[2]))
def random_leaf() -> Expr:
if random.random() < 0.5:
return ("x",)
return ("num", float(random.choice([-2, -1, 0, 1, 2, 3])))
def render(e: Expr) -> str:
tag = e[0]
if tag == "num":
return f"{e[1]:g}"
if tag == "x":
return "x"
op = "+" if tag == "add" else "*"
return f"({render(e[1])} {op} {render(e[2])})"
def mse(e: Expr, xs: list[float]) -> float:
total = 0.0
for x in xs:
try:
y = evaluate_expr(e, x)
except (OverflowError, ValueError):
return float("inf")
total += (y - target(x)) ** 2
return total / max(1, len(xs))
@dataclass
class Candidate:
expr: Expr
train_score: float
test_score: float
generation: int
def cell_key(e: Expr) -> tuple[int, int]:
d = min(depth(e), 6)
c = min(int(max_const(e) / 2), 4)
return (d, c)
def seed_candidate(test_xs: list[float], train_xs: list[float], gen: int) -> Candidate:
e = random_leaf()
return Candidate(e, mse(e, train_xs), mse(e, test_xs), gen)
def run_loop(
generations: int,
pop: int,
use_holdout: bool,
seed: int | None = None,
) -> tuple[Candidate, list[float], list[float]]:
if seed is not None:
random.seed(seed)
train_xs = [-2.0, -1.0, 0.0, 1.0, 2.0, 3.0]
test_xs = [-2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5]
def signal_of(c: Candidate) -> float:
return 0.5 * (c.train_score + c.test_score) if use_holdout else c.train_score
archive: dict[tuple[int, int], Candidate] = {}
for _ in range(pop):
c = seed_candidate(test_xs, train_xs, 0)
key = cell_key(c.expr)
incumbent = archive.get(key)
if incumbent is None or signal_of(c) < signal_of(incumbent):
archive[key] = c
best_trace: list[float] = []
test_trace: list[float] = []
for g in range(1, generations + 1):
parent = random.choice(list(archive.values()))
child_expr = mutate(parent.expr)
tr = mse(child_expr, train_xs)
te = mse(child_expr, test_xs)
child = Candidate(child_expr, tr, te, g)
key = cell_key(child_expr)
incumbent = archive.get(key)
if incumbent is None or signal_of(child) < signal_of(incumbent):
archive[key] = child
best = min(archive.values(), key=lambda c: c.train_score)
best_trace.append(best.train_score)
test_trace.append(best.test_score)
# Final selection must use the same signal as the search: using the
# held-out test here when use_holdout=False would silently leak the
# holdout back into Run B and mask the overfitting the lesson shows.
best = min(archive.values(), key=signal_of)
return best, best_trace, test_trace
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--no-holdout",
action="store_true",
help="skip the held-out test evaluator (Run B only; forces reward-hacking demo)",
)
args = parser.parse_args()
print("=" * 70)
print("ALPHAEVOLVE-STYLE LOOP (Phase 15, Lesson 3)")
print("=" * 70)
print("target: 2x^2 + 3x - 1")
if not args.no_holdout:
print("\nRun A: held-out test included in evaluator signal")
best, train_trace, _ = run_loop(
generations=1500, pop=20, use_holdout=True, seed=DEFAULT_SEED
)
print(f" best expr : {render(best.expr)}")
print(f" train MSE : {best.train_score:.4f}")
print(f" test MSE : {best.test_score:.4f}")
print(f" generation: {best.generation}")
print(" progress : gen 100 train={:.3f} gen 500 train={:.3f} gen 1500 train={:.3f}".format(
train_trace[99], train_trace[499], train_trace[-1]))
print("\nRun B: no held-out test (train-only evaluator -> reward hacking risk)")
best, _train_trace, _test_trace = run_loop(
generations=1500, pop=20, use_holdout=False, seed=DEFAULT_SEED
)
print(f" best expr : {render(best.expr)}")
print(f" train MSE : {best.train_score:.4f}")
print(f" test MSE : {best.test_score:.4f}")
print(f" generation: {best.generation}")
gap = best.test_score - best.train_score
print(f" train-to-test gap: {gap:+.4f} (large gap = overfit/reward hacking proxy)")
print()
print("=" * 70)
print("HEADLINE: the evaluator is the architecture")
print("-" * 70)
print(" Run A converges to low train AND low test MSE.")
print(" Run B converges to low train MSE; test MSE stays loose or worse.")
print(" A held-out evaluator is the difference between discovery and")
print(" reward hacking. AlphaEvolve's wins are in domains where such an")
print(" evaluator exists. Picking those domains is the hard part.")
if __name__ == "__main__":
main()