ToolKami

AlphaEvolve: ToolKami Style

TL;DR: We implemented a simplified version of AlphaEvolve to optimize Perlin noise code to resemble a target fire image. Code is available at the end of this post.

Google’s AlphaEvolve has made waves in the news, and it’s no surprise given its impressive results and innovative combination of two powerful techniques:

While their implementation remains closed-source, they shared enough details for me to quickly replicate a pseudo loop using my existing agentic setup. For this experiment, I set myself the task of creating an improved Perlin noise implementation that resembles a target fire image. For simplicity, I used Mean Squared Error (MSE) as the fitness function.

Fire

Here’s their architecture in a nutshell: AlphaEvolve’s Architecture

Here’s how it translates into prompts:

Act as an expert software developer. Your task is to iteratively improve the provided codebase.

Create a Perlin noise implementation that resembles the target image (a fire in this case).
1. Use list_directory tool with sort_order 'asc' and limit 10 in the directory '/workspaces/toolkami/projects/perlin/results' which were saved with convention '{score}_{md5sum}.py'.
2. Sample 1 program from the list, it doesn't have to be the best, sample randomly.
3. Make a copy of the file with the name 'candidate_{random_id}_{md5sum}.py' with executable permission and save it in the directory '/workspaces/toolkami/projects/perlin/results'.
4. You are only allowed to modify the content between '# EVOLVE-BLOCK-START' and '# EVOLVE-BLOCK-END', suggest a new idea to improve the code that is inspired by your expert knowledge of game programming, graphics and optimization.
5. Edit the candidate file using the edit tool with the diff-fenced format.
6. Write the output of edit tool to the candidate file
7. Execute the program (as a UV script) and after obtaining the output score, rename the file with convention '{score}_{md5sum}.py'.
8. Forget current memory
9. Repeat the process

In the whitepaper, there is also an interesting mention of this technique to restrict changes:

API. To support evolving multiple components across a codebase, AlphaEvolve exposes an input API where blocks of code can be annotated as to-be-evolved-by-the-system; This design facilitates integrating it with existing codebases while requiring only minimal changes, simply by adding special markers as comments into the code.

To re-summarise the significant simplifications to the original implementation:

The results? The agent successfully reduced the MSE for the base implementation from -0.1373 to -0.0647 (where closer to 0 is better) in just 20 iterations.

Base Implementation

Base result

After 20 Iterations

Loop 20 result

The complete implementation is available here: Code

As this is my first blog post, I hope you enjoyed reading it! Feel free to suggest ways to improve both the blog post and the implementation.

#AI