An autonomous evolutionary framework for LLM-based agents. Inspired by the Darwin Gödel Machine (DGM) research, this prototype demonstrates how an agent can recursively improve its own source code to survive an increasingly complex benchmark environment.
The core of the system is a Recursive Meta-Evolution Loop. Unlike static agents, DGM treats its own source code as its "DNA" and uses an LLM as a genetic engineer to patch itself based on empirical failure.
graph TD
A[Seed DNA: src/agents/seed_agent.py] --> B[Evaluation: Local Sandbox]
B --> C{Fitness Test: problems.json}
C -->|Failure Logs| D[Mutator: GPT-4o]
D --> E[Propose New DNA: New Source Code]
E --> B
C -->|100% Success| F[Champion: winner_agent.py]
- The DNA: Source code found in
src/agents/seed_agent.py. It starts as a "low-intelligence" organism. - The Laboratory (Local Environment): Evaluation happens in isolated temporary directories. This ensures that mutated code doesn't interfere with your host system while maintaining high-speed testing.
- The Mutator: Uses GPT-4o as a "Recursive Coder" that receives the current code and the exact failure logs from the laboratory.
- The Fitness Function: A rigorous 30-case benchmark testing high-level algorithmic logic, math, and data structures.
This project focuses on Empirical Proof. We generate high-fidelity visualizations and cross-model comparisons to validate the intelligence jump.
After running the evolution, generate the research-grade dashboard:
uv run python visualizer.pyReference Files:
outputs/dgm_dashboard.png: A 4-panel analysis including:- Fig 1: Population Fitness Trace: Scatter plot of every agent ever created vs. the optimization frontier.
- Fig 2: Capability Breakthroughs: Heatmap tracking which logic domains (Math, Logic, String) were mastered at which evolution step.
- Fig 3: Phylogeny Tree: A linked graph showing how the winner evolved from the seed through specific parent-child mutations.
- Fig 4: Champion Task Matrix: Green/Red breakdown of all 30 specific tasks passed by the final winner.
To prove that evolution is necessary, we pit the "Winner" against a one-shot LLM generation:
uv run python comparison.pyReference Files:
outputs/comparison_results.png: Comparison bar chart showing the performance gap.outputs/comparison_data.json: An audit trail containing the entire conversation log, questions, and raw responses from both models for review.
Ensure you have uv installed and your OPENAI_API_KEY in the .env file.
uv venv
source .venv/bin/activate
uv pip install -e .Prepare for a fresh evolution experiment:
rm src/agents/winner_agent.py src/agents/history/* outputs/*uv run python main.pyFor deep technical review, all lineages and logs are stored in:
outputs/evolution_data.json: The complete family tree and logs for every agent generated.src/agents/history/: Snapshots of the "Worst" and "Intermediate" agents for code comparison.
The agent is tested on 30 tasks including:
- Mathematical: GCD, LCM, Collatz Steps, Pascal's Triangle, Armstrong Numbers.
- Algorithmic: Matrix Transpose, Binary Search, Balanced Brackets, LRU Cache simulation.
- String Logic: Caesar Cipher, Run-Length Encoding, Word Frequency analysis.