|
15 | 15 | <a href="https://github.com/codelion/openevolve/blob/main/LICENSE"><img src="https://img.shields.io/github/license/codelion/openevolve" alt="License"></a> |
16 | 16 | </p> |
17 | 17 |
|
18 | | -[🚀 **Quick Start**](#-quick-start) • [📖 **Examples**](#-examples-gallery) • [💬 **Discussions**](https://github.com/codelion/openevolve/discussions) |
| 18 | +[🚀 **Quick Start**](#-quick-start) • [📖 **Examples**](#-examples-gallery) • [📝 **System Messages**](#-crafting-effective-system-messages) • [💬 **Discussions**](https://github.com/codelion/openevolve/discussions) |
19 | 19 |
|
20 | 20 | *From random search to state-of-the-art: Watch your code evolve in real-time* |
21 | 21 |
|
@@ -516,6 +516,217 @@ See [prompt examples](examples/llm_prompt_optimization/templates/) for complete |
516 | 516 |
|
517 | 517 | </details> |
518 | 518 |
|
| 519 | +## 📝 Crafting Effective System Messages |
| 520 | +
|
| 521 | +**System messages are the secret to successful evolution.** They guide the LLM's understanding of your domain, constraints, and optimization goals. A well-crafted system message can be the difference between random mutations and targeted improvements. |
| 522 | +
|
| 523 | +### Why System Messages Matter |
| 524 | +
|
| 525 | +The system message in your config.yaml is arguably the most important component for evolution success: |
| 526 | +
|
| 527 | +- **Domain Expertise**: Provides LLM with specific knowledge about your problem space |
| 528 | +- **Constraint Awareness**: Defines what can and cannot be changed during evolution |
| 529 | +- **Optimization Focus**: Guides the LLM toward meaningful improvements |
| 530 | +- **Error Prevention**: Helps avoid common pitfalls and compilation errors |
| 531 | +
|
| 532 | +### The Iterative Creation Process |
| 533 | +
|
| 534 | +Based on successful OpenEvolve implementations, system messages are best created through iteration: |
| 535 | +
|
| 536 | +<details> |
| 537 | +<summary><b>🔄 Step-by-Step Process</b></summary> |
| 538 | +
|
| 539 | +**Phase 1: Initial Draft** |
| 540 | +1. Start with a basic system message describing your goal |
| 541 | +2. Run 20-50 evolution iterations to observe behavior |
| 542 | +3. Note where the system gets "stuck" or makes poor choices |
| 543 | +
|
| 544 | +**Phase 2: Refinement** |
| 545 | +4. Add specific guidance based on observed issues |
| 546 | +5. Include domain-specific terminology and concepts |
| 547 | +6. Define clear constraints and optimization targets |
| 548 | +7. Run another batch of iterations |
| 549 | +
|
| 550 | +**Phase 3: Specialization** |
| 551 | +8. Add detailed examples of good vs bad approaches |
| 552 | +9. Include specific library/framework guidance |
| 553 | +10. Add error avoidance patterns you've observed |
| 554 | +11. Fine-tune based on artifact feedback |
| 555 | +
|
| 556 | +**Phase 4: Optimization** |
| 557 | +12. Consider using OpenEvolve itself to optimize your prompt |
| 558 | +13. Measure improvements using combined score metrics |
| 559 | +
|
| 560 | +</details> |
| 561 | +
|
| 562 | +### Examples by Complexity |
| 563 | +
|
| 564 | +#### 🎯 **Simple: General Optimization** |
| 565 | +```yaml |
| 566 | +prompt: |
| 567 | + system_message: | |
| 568 | + You are an expert programmer specializing in optimization algorithms. |
| 569 | + Your task is to improve a function minimization algorithm to find the |
| 570 | + global minimum reliably, escaping local minima that might trap simple algorithms. |
| 571 | +``` |
| 572 | +
|
| 573 | +#### 🔧 **Intermediate: Domain-Specific Guidance** |
| 574 | +```yaml |
| 575 | +prompt: |
| 576 | + system_message: | |
| 577 | + You are an expert prompt engineer. Your task is to revise prompts for LLMs. |
| 578 | +
|
| 579 | + Your improvements should: |
| 580 | + * Clarify vague instructions and eliminate ambiguity |
| 581 | + * Strengthen alignment between prompt and desired task outcome |
| 582 | + * Improve robustness against edge cases |
| 583 | + * Include formatting instructions and examples where helpful |
| 584 | + * Avoid unnecessary verbosity |
| 585 | +
|
| 586 | + Return only the improved prompt text without explanations. |
| 587 | +``` |
| 588 | +
|
| 589 | +#### ⚡ **Advanced: Hardware-Specific Optimization** |
| 590 | +```yaml |
| 591 | +prompt: |
| 592 | + system_message: | |
| 593 | + You are an expert Metal GPU programmer specializing in custom attention |
| 594 | + kernels for Apple Silicon. |
| 595 | +
|
| 596 | + # TARGET: Optimize Metal Kernel for Grouped Query Attention (GQA) |
| 597 | + # HARDWARE: Apple M-series GPUs with unified memory architecture |
| 598 | + # GOAL: 5-15% performance improvement |
| 599 | +
|
| 600 | + # OPTIMIZATION OPPORTUNITIES: |
| 601 | + **1. Memory Access Pattern Optimization:** |
| 602 | + - Coalesced access patterns for Apple Silicon |
| 603 | + - Vectorized loading using SIMD |
| 604 | + - Pre-compute frequently used indices |
| 605 | +
|
| 606 | + **2. Algorithm Fusion:** |
| 607 | + - Combine max finding with score computation |
| 608 | + - Reduce number of passes through data |
| 609 | +
|
| 610 | + # CONSTRAINTS - CRITICAL SAFETY RULES: |
| 611 | + **MUST NOT CHANGE:** |
| 612 | + ❌ Kernel function signature |
| 613 | + ❌ Template parameter names or types |
| 614 | + ❌ Overall algorithm correctness |
| 615 | +
|
| 616 | + **ALLOWED TO OPTIMIZE:** |
| 617 | + ✅ Memory access patterns and indexing |
| 618 | + ✅ Computation order and efficiency |
| 619 | + ✅ Vectorization and SIMD utilization |
| 620 | + ✅ Apple Silicon specific optimizations |
| 621 | +``` |
| 622 | +
|
| 623 | +### Best Practices |
| 624 | +
|
| 625 | +<details> |
| 626 | +<summary><b>🎨 Prompt Engineering Patterns</b></summary> |
| 627 | +
|
| 628 | +**Structure Your Message:** |
| 629 | +- Start with role definition ("You are an expert...") |
| 630 | +- Define the specific task and context |
| 631 | +- List optimization opportunities with examples |
| 632 | +- Set clear constraints and safety rules |
| 633 | +- End with success criteria |
| 634 | +
|
| 635 | +**Use Specific Examples:** |
| 636 | +```yaml |
| 637 | +# Good: Specific optimization targets |
| 638 | +system_message: | |
| 639 | + Focus on reducing memory allocations in the hot loop. |
| 640 | + Example: Replace `new Vector()` with pre-allocated arrays. |
| 641 | +
|
| 642 | +# Avoid: Vague guidance |
| 643 | +system_message: "Make the code faster" |
| 644 | +``` |
| 645 | +
|
| 646 | +**Include Domain Knowledge:** |
| 647 | +```yaml |
| 648 | +# Good: Domain-specific guidance |
| 649 | +system_message: | |
| 650 | + For GPU kernels, prioritize: |
| 651 | + 1. Memory coalescing (access patterns) |
| 652 | + 2. Occupancy (thread utilization) |
| 653 | + 3. Shared memory usage (cache blocking) |
| 654 | +
|
| 655 | +# Avoid: Generic optimization advice |
| 656 | +system_message: "Optimize the algorithm" |
| 657 | +``` |
| 658 | +
|
| 659 | +**Set Clear Boundaries:** |
| 660 | +```yaml |
| 661 | +system_message: | |
| 662 | + MUST NOT CHANGE: |
| 663 | + ❌ Function signatures |
| 664 | + ❌ Algorithm correctness |
| 665 | + ❌ External API compatibility |
| 666 | +
|
| 667 | + ALLOWED TO OPTIMIZE: |
| 668 | + ✅ Internal implementation details |
| 669 | + ✅ Data structures and algorithms |
| 670 | + ✅ Performance optimizations |
| 671 | +``` |
| 672 | +
|
| 673 | +</details> |
| 674 | +
|
| 675 | +<details> |
| 676 | +<summary><b>🔬 Advanced Techniques</b></summary> |
| 677 | +
|
| 678 | +**Artifact-Driven Iteration:** |
| 679 | +- Enable artifacts in your config |
| 680 | +- Include common error patterns in system message |
| 681 | +- Add guidance based on stderr/warning patterns |
| 682 | +
|
| 683 | +**Multi-Phase Evolution:** |
| 684 | +```yaml |
| 685 | +# Phase 1: Broad exploration |
| 686 | +system_message: "Explore different algorithmic approaches..." |
| 687 | + |
| 688 | +# Phase 2: Focused optimization |
| 689 | +system_message: "Given the successful simulated annealing approach, |
| 690 | +focus on parameter tuning and cooling schedules..." |
| 691 | +``` |
| 692 | +
|
| 693 | +**Template Variation:** |
| 694 | +```yaml |
| 695 | +prompt: |
| 696 | + template_dir: "custom_templates/" |
| 697 | + use_template_stochasticity: true |
| 698 | + system_message: | |
| 699 | + # Use multiple greeting variations |
| 700 | + [Randomly: "Let's optimize this code:" | "Time to enhance:" | "Improving:"] |
| 701 | +``` |
| 702 | +
|
| 703 | +</details> |
| 704 | +
|
| 705 | +### Meta-Evolution: Using OpenEvolve to Optimize Prompts |
| 706 | +
|
| 707 | +**You can use OpenEvolve to evolve your system messages themselves!** |
| 708 | +
|
| 709 | +```yaml |
| 710 | +# Example: Evolve prompts for HotpotQA dataset |
| 711 | +Initial Prompt: "Answer the question based on the context." |
| 712 | + |
| 713 | +Evolved Prompt: "As an expert analyst, carefully examine the provided context. |
| 714 | +Break down complex multi-hop reasoning into clear steps. Cross-reference |
| 715 | +information from multiple sources to ensure accuracy. Answer: [question]" |
| 716 | + |
| 717 | +Result: +23% accuracy improvement on HotpotQA benchmark |
| 718 | +``` |
| 719 | +
|
| 720 | +See the [LLM Prompt Optimization example](examples/llm_prompt_optimization/) for a complete implementation. |
| 721 | +
|
| 722 | +### Common Pitfalls to Avoid |
| 723 | +
|
| 724 | +- **Too Vague**: "Make the code better" → Specify exactly what "better" means |
| 725 | +- **Too Restrictive**: Over-constraining can prevent useful optimizations |
| 726 | +- **Missing Context**: Include relevant domain knowledge and terminology |
| 727 | +- **No Examples**: Concrete examples guide LLM better than abstract descriptions |
| 728 | +- **Ignoring Artifacts**: Don't refine prompts based on error feedback |
| 729 | +
|
519 | 730 | ## 🔧 Artifacts & Debugging |
520 | 731 |
|
521 | 732 | **Artifacts side-channel** provides rich feedback to accelerate evolution: |
|
0 commit comments