A greedy hill-climber keeps improving one candidate until every nearby change scores worse. It can stop at a local optimum even when a better solution lies beyond a lower-scoring region. Evolutionary computation searches with a population instead: vary candidates, select by a measurable score, retain useful candidates, and repeat. Having candidates in different parts of the search landscape gives the loop paths a single climber may miss. section 4.1 section 4.6
An integer-search loop
Start with eight random integers and a target of 73. Score each integer by the negative distance from the target; keep the four best, make one copy of each with a +1 or −1 change, and form the next generation from survivors and children. In the shown run, the best candidate reaches 73 at generation 11. The score is its fitness, the change is mutation, and each pass is a generation. This toy needs neither a gradient nor a model. section 4.1.1
For agent improvement, the same loop operates on candidate artifacts rather than integers:
- Vary: create an edited child. Mutation changes one parent; crossover combines two. A model can write semantic edits to text artifacts. section 4.3.1 section 4.6
- Select: measure each candidate with a signal—the fitness score—and choose which candidates can parent another round. Reliable measurement matters because search follows that signal. section 4.1.2 section 4.4.3
- Remember: retain candidates for future rounds and record each child's parent. Parent links make the resulting lineage inspectable. section 4.1.2 section 4.3.1
How much the loop remembers changes its reach and cost. GEPA maintains a small prompt population and uses execution-trace feedback to guide edits, but discarded branches are unavailable later. The Darwin Gödel machine (DGM) keeps every candidate in an archive, allowing a later round to revisit an old branch. That broader memory costs more; it is useful only when the potential gain warrants the extra search and the score is dependable. Inspecting lineages and failures helps distinguish a population that has converged from one still exploring. section 4.3.1 section 4.4.3 section 4.6
Listing 4.1 Natural selection with no model (01_natural_selection.py)
TARGET = 73 #A
def fitness(genome): #B
return -abs(genome - TARGET)
def mutate(genome): #C
return genome + random.choice((-1, 1))
def main():
random.seed(0)
population = [random.randint(0, 100) for _ in range(8)]
for generation in range(40):
population.sort(key=fitness, reverse=True) #D
survivors = population[:4] #E
children = [mutate(g) for g in survivors] #F
population = survivors + children #G
best = max(population, key=fitness)
if fitness(best) == 0:
breakThe Python listing makes selection, mutation, and survivor retention visible in one small loop. section 4.1.1



