{"system": ..., "user": ...}.
For most tasks, you don’t need to touch this. Just set the system prompt in config.yaml:
config.yaml
Architecture
1
Controller calls context_builder.build_prompt()
Once per iteration, before calling the LLM
2
Context builder renders templates
Fills in placeholders with parent program, context programs, and metrics
3
Returns {system, user} dict
Sent directly to the LLM
Directory Structure
TemplateManager. Later directories override earlier ones on filename conflicts.
Default Templates
When to Write a Custom Builder
You need a custom builder if:Your algorithm has search-specific state
Your algorithm has search-specific state
Examples:
- Multi-island search: “You are on island 3 (exploration mode)”
- Tree search: “Current path: root → node_5 → node_12”
- Acceptance gating: “Last 5 attempts were rejected because…”
You want to add dynamic guidance
You want to add dynamic guidance
Examples:
- Stagnation response: “No improvement in 20 iterations. Try a radical change.”
- Evaluator feedback: “Previous solution failed validation: timeout”
- Paradigm hints: “Consider using dynamic programming instead of greedy.”
You need custom context program formatting
You need custom context program formatting
Examples:
- Ranked context: “Top 3 programs: #1 (score=0.95), #2 (score=0.92), …”
- Sibling context: “3 siblings from the same parent, all failed”
- Diverse context: “Programs from 3 different search islands”
Writing a Custom Builder
The most common pattern is extendingDefaultContextBuilder and injecting extra guidance via the {search_guidance} placeholder.
The default templates already include this slot—an empty string makes it disappear cleanly.
Basic Pattern
Complete Example: Island-Based Search
Here’s a builder that tells the LLM which island it’s on:my_algo/builder.py
Template with Placeholder
Createmy_algo/templates/diff_user_message.txt (overrides default):
diff_user_message.txt
CONTEXT PROGRAMS
TASK
Generate SEARCH/REPLACE blocks to improve the program._prompt_context dict is automatically passed to build_prompt() as the context parameter.
Registration via Config
To make a builder available via config (instead of hardcoding in controller), add it to_init_context_builder() in search/default_discovery_controller.py:
default_discovery_controller.py
config.yaml
Advanced: Dynamic Guidance
For guidance that changes based on search progress:Template Variables
Available placeholders in templates:Real-World Examples
AdaEvolve Builder
Adds evaluator feedback, paradigm guidance, and sibling context:adaevolve/builder.py
EvoX Builder
Adds LLM-generated search strategy summaries:evox/builder.py
TemplateManager API
TheTemplateManager loads and renders .txt templates:
Next Steps
Custom Algorithms
Implement your own search strategies
Custom Benchmarks
Add your own optimization tasks