Skip to content

Add Prompt Meta-Evolution#393

Open
fangchenli wants to merge 4 commits intoalgorithmicsuperintelligence:mainfrom
fangchenli:feature/prompt-meta-evolution
Open

Add Prompt Meta-Evolution#393
fangchenli wants to merge 4 commits intoalgorithmicsuperintelligence:mainfrom
fangchenli:feature/prompt-meta-evolution

Conversation

@fangchenli
Copy link
Contributor

@fangchenli fangchenli commented Feb 4, 2026

closes #170

Implements meta-evolution of prompt templates. The system maintains an archive of prompt templates, tracks their empirical success rates, and evolves them over time using LLM to improve mutation quality.

The scoring formula:
math score = w_success × success_rate + w_improvement × improvement_rate + w_fitness × normalized_delta
The weights are controlled in the config.

Unittests added and also tested with the function_minimization example.

fangchenli and others added 4 commits February 3, 2026 13:48
## Problem

When diff-based evolution is enabled, the "Previous Attempts" section
of prompts shows changes like:

    Change 1: Replace 15 lines with 18 lines

This gives the LLM no visibility into what the actual edits were,
making it harder to:
- Learn from successful patterns
- Avoid repeating failed exact matches
- Understand what format produces valid SEARCH blocks

This contributes to the high rate of "apply diff fail" errors
(see issue algorithmicsuperintelligence#346) where SEARCH patterns don't exactly match the
original code.

## Solution

Update `format_diff_summary()` to show actual content for multi-line
blocks:

    Change 1: Replace:
      def old_function():
          return False
    with:
      def new_function():
          return True

Single-line changes remain compact:

    Change 1: 'x = 1' to 'x = 2'

Add `_format_block_lines()` helper with configurable truncation limits.

## Configuration

New options in `prompt:` config section:

```yaml
prompt:
  diff_summary_max_line_len: 100  # Truncate lines longer than this
  diff_summary_max_lines: 30      # Max lines per SEARCH/REPLACE block
```

## Files Changed

- `openevolve/config.py` - Add PromptConfig options
- `openevolve/utils/code_utils.py` - Update format_diff_summary
- `openevolve/iteration.py` - Pass config to format_diff_summary
- `openevolve/process_parallel.py` - Pass config to format_diff_summary
- `tests/test_code_utils.py` - Add tests for new behavior

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Implements meta-evolution of prompt templates inspired by the Darwin
Gödel Machine paper. The system maintains an archive of prompt templates,
tracks their success rates, and evolves them over time to improve
mutation quality.

Key features:
- PromptTemplate dataclass with success/improvement tracking
- PromptArchive for managing template population with sampling
- Configurable scoring weights for template quality assessment
- Automatic template evolution at configurable intervals
- Checkpoint persistence for prompt archives
- Validation to ensure scoring weights sum to 1.0

New config options under `prompt_meta_evolution`:
- enabled: Master switch (default: false)
- archive_size: Max templates to keep
- evolution_interval: Iterations between evolutions
- exploration_rate: Random sampling probability
- score_weight_*: Configurable scoring formula weights

Closes algorithmicsuperintelligence#170
Related to algorithmicsuperintelligence#53

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Simplify async event loop handling using asyncio.run()
- Add scoring config persistence in checkpoint serialization
- Document exploration bonus formula with clear comment
- Add test for scoring config serialization round-trip

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@fangchenli fangchenli marked this pull request as ready for review February 4, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Meta Prompt Evolution

1 participant