LLM Strategies

While AST mutations are deterministic and safe, they are limited to structural transformations. LLM strategies unlock semantic mutations — the kind of creative refactoring that requires understanding what the code does, not just how it is structured.

Enabling LLM mutations

hezgene run src/utils.py --llm

The --llm flag adds LLM-generated mutants to the arena alongside AST mutants. Both compete equally — the best one wins regardless of origin.

Available strategies

StrategyFocusTechnique
optimize_speedExecution speedAlgorithm replacement, caching, vectorization
optimize_memoryMemory usageGenerator expressions, lazy evaluation, pooling
simplifyReadabilityReduce complexity, extract helpers, clearer naming
algorithmicBig-O improvementReplace O(n²) with O(n log n), use hash maps
robustError handlingAdd guards, handle edge cases, defensive coding

Supported providers

# Ollama (local, free)
hezgene config --set llm.provider ollama
hezgene config --set llm.model gemma2:2b

# OpenAI
hezgene config --set llm.provider openai
hezgene config --set llm.model gpt-4o-mini

# Anthropic
hezgene config --set llm.provider anthropic
hezgene config --set llm.model claude-sonnet-4-20250514

# Google Gemini
hezgene config --set llm.provider gemini
hezgene config --set llm.model gemini-2.5-flash
Local first
Ollama runs entirely on your machine with no API key required. It is the recommended provider for users who want LLM mutations without sending code to external services.

LLM safety guarantees

LLM mutations go through the exact same Fitness Arena as AST mutations. Even if an LLM produces creative but incorrect code, it will be caught and killed in Ring 1 (Correctness). The LLM is a suggestion engine — the Arena is the judge.

Previous
AST Mutations
Deterministic codebase changes
Static vs runtime
Mental model for codebase intelligence
Next