{"system": ..., "user": ...}.
For most tasks, you don’t need to touch this. Just set the system prompt in config.yaml:
config.yaml
Architecture
Context builder renders templates
Fills in placeholders with parent program, context programs, and metrics
Directory Structure
TemplateManager. Later directories override earlier ones on filename conflicts.
Default Templates
| File | Role | When Used |
|---|---|---|
system_message.txt | system | Default system prompt (overridden by config) |
diff_user_message.txt | user | Diff-based generation (default mode) |
full_rewrite_user_message.txt | user | Full rewrite mode |
full_rewrite_prompt_opt_user_message.txt | user | Prompt optimization tasks |
image_user_message.txt | user | Image generation mode |
evaluator_system_message.txt | system | LLM judge (only with llm_as_judge) |
evaluator_user_message.txt | user | LLM judge user message |
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:| Variable | Type | Description |
|---|---|---|
{program} | str | Current program source code |
{language} | str | Programming language (“python”, “text”, “image”) |
{metrics} | str | Formatted metrics from parent program |
{context_programs} | str | Formatted list of context programs |
{search_guidance} | str | Custom guidance from your builder |
{errors} | str | Failed attempts (if retry mode) |
{db_stats} | str | Database statistics (score distribution, etc.) |
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