Organizations: ICN2 – Catalan Institute of Nanoscience and Nanotechnology, Barcelona, Spain · Artificial Intelligence Research Institute (IIIA-CSIC), Barcelona, Spain · Universitat Politècnica de Catalunya (UPC), Barcelona, Spain
Can an LLM learn how an optimizer behaves -- and use that knowledge to control it? We extend Code World Models (CWMs), LLM-synthesized Python programs that predict environment dynamics, from deterministic games to stochastic combinatorial optimization. Given suboptimal trajectories of (1+1)-RLSk, the LLM synthesizes a simulator of the optimizer's dynamics; greedy planning over this simulator then selects the mutation strength k at each step. On \lo{} and \onemax{}, CWM-greedy performs within 6% of the theoretically optimal policy -- without ever seeing optimal-policy trajectories. On \jump{k}, where a deceptive valley causes all adaptive baselines to fail (0% success rate), CWM-greedy achieves 100% success rate -- without any collection policy using oracle knowledge of the gap parameter. On the NK-Landscape, where no closed-form model exists, CWM-greedy outperforms all baselines across fifteen independently generated instances (36.94 vs.\ 36.32; p<0.001) when the prompt includes empirical transition statistics. The CWM also outperforms DQN in sample efficiency (200 offline trajectories vs.\ 500 online episodes), success rate (100% vs.\ 58%), and generalization (k=3: 78% vs.\ 0%). Robustness experiments confirm stable synthesis across 5 independent runs.
Figures & tables
Figure 1: Overview of the CWM approach. Offline : trajectory data and a problem description are assembled into a prompt; an LLM synthesizes a Python world model in a single API call ( ∼ € 0.04). Online : the greedy planner queries the CWM at each step to select k∗ . Bottom : key results across four benchmarks.
Aspect
Original CWM
This work
Environments
18 Gymnasium games
4 EA benchmarks
Dynamics
Deterministic
Stochastic combinatorial
LLM input
Env. docs + trajectories
Math / empirical stats + traj.
Synthesis
GIF-MCTS (iterative)
Single-shot + refinement
Planning
MCTS (5,000 rollouts)
Greedy 1-step lookahead
Baselines
Model-free RL
Adaptive rules & DQN
Table 1: Original CWM framework [ 3 ] vs. this work.
LeadingOnes
OneMax
Jump k
NK
Landscape
Unimodal
Unimodal
Deceptive valley
Rugged / epistatic
Optimal k∗
Known (closed)
Known (closed)
Unknown
Unknown
Key challenge
Smooth k ramp
Sharp policy cliff
Valley crossing
No math model
CWM input
Math description
Math description
Math + empirical table
Empirical table
Budget
0.8n2=2,000
5nlnn=978
10,000
10,000
What CWM learns
k↓ as i↑
Cliff at n/2
k↑ at edge
Transition lookup
Table 2: Benchmark progression: each problem adds a new challenge for CWM-based parameter control.
Figure 2: LeadingOnes : CWM score heatmap over (fitness i , parameter k ). Black stars ( ⋆ ) mark the optimal k∗(i)=⌊n/(i+1)⌋ , snapped to the nearest column when k∗ is not in the displayed set. Stars appear only at k values that are optimal for at least one fitness level; columns without stars (e.g. k=20,25,30,40 ) are never greedy-optimal for any i .
Figure 3: Jump k ( k=2 ): CWM score heatmap over (fitness, parameter k ). Black stars ( ⋆ ) mark the greedy-optimal k∗(i) , snapped to the nearest displayed column. At the valley edge (fitness =n ), the CWM correctly predicts that only k=2 leads to improvement—opposite to all adaptive baselines, which decrease k during stagnation.
Policy
Mean
SR%
Data
optimal
1,346
100%
—
CWM-greedy
1,342
100%
200 offline traj.
stagnation
1,506
99%
— (heuristic)
DQN (500 ep.)
5,210
58%
500 online ep.
DQN (200 ep.)
10,000
0%
200 online ep.
Table 5: CWM vs. DQN on Jump k ( n=50 , k=2 , 100 eval. runs).
Figure 4: Left: CWM vs. DQN on Jump k : 100% success rate vs. 58%. Right: DQN learning curves ( k=2 ). Training beyond 500 episodes degrades performance—success rate plateaus at ∼50% while steps decrease only marginally, revealing overfitting to the ϵ -greedy exploration policy.
Policy
Mean best
Std
Max
Mean rank
CWM-greedy
36.94
1.03
39.12
1.0
static_5
36.32
1.04
38.96
2.5
random_k
36.31
1.00
39.06
2.5
fifth_rule
35.36
0.99
38.91
4.5
stagnation
35.32
0.93
38.91
5.1
self_adjusting
35.22
0.95
39.06
6.1
Table 6: NK-Landscape results ( n=50 , K=2 , budget =10,000 , 100 runs × 15 instances). Std: across per-instance means; Max: best single run. CWM-greedy ranks first on every instance (paired t -test p<0.001 ).
Figure 6: NK CWM score heatmap ( K=2 ). The scores are instance-independent (determined by the CWM alone); the model is evaluated on fifteen landscape instances in Table 6 . No optimal overlay exists—the optimal policy is unknown. The CWM prefers small k at high fitness.
Problem
n
Optimal
CWM
RLS 1
CWM/Opt
LeadingOnes
50
983
1,052
1,220
1.07 ×
100
3,705
4,167
4,923
1.12 ×
200
15,761
16,156
20,210
1.02 ×
OneMax
50
185
188
192
1.02 ×
100
441
452
431
1.02 ×
200
1,031
1,020
1,037
0.99 ×
Table 7: Generalization across problem sizes. CWM trained on n=50 , 50 eval. runs.
CWM
DQN
EAα
k
Mean
SR
Mean
SR
Mean
SR
2
1,259
100%
5,023
58%
10,000
0%
3
21,377
78%
50,000
0%
50,000
0%
4
50,000
0%
50,000
0%
50,000
0%
Table 8: Generalization across Jump k values. CWM and DQN (best: 500 training episodes) trained on k=2 , 50 eval. runs.
Figure 7: Jump k generalization: CWM 78% on k=3 vs. DQN 0%.
Benchmark
τ
ρ
Exact
Note
LeadingOnes
0.784
0.916
60%
—
OneMax
0.614
0.939
82%
—
Jump k
0.898
0.948
—
valley-edge τ=1.0
NK
0.553
—
—
with empirical table
Table 9: CWM quality metrics. τ : Kendall’s rank correlation between CWM-predicted and true action rankings. ρ : Spearman correlation. Exact: fraction of states where CWM selects the same k∗ as the oracle.
In evolutionary algorithms powered by language models, the LLM acts as a single operator that simultaneously updates structural components (like control flow) and continuous parameters. While LLMs can be good at the first, they are not efficient at the second, wasting tokens taking discrete jumps inside a trial and error loop. We resolve this by formalizing a hybrid nested search, in which an outer loop has the LLM propose a structural sketch, with numeric gaps, and an inner numerical optimizer tunes the sketch. Both the outer and inner solvers are pluggable: any text-based optimizer can be combined with a zero-order optimizer (CMA-ES), gradient-based routines, or MCMC samplers. We validate our framework across three scientific domains: (i) meta-optimizers on closed-form test functions, (ii) code-based policies for systems research and social dilemmas; and (iii) approximate Bayesian inference tasks. Across all three, the hybrid optimizer is superior to both vanilla LLM-driven search and pure numerical optimization baselines. Code at: https://github.com/vicgalle/hybrid-nested-search
Large Language Model (LLM)-guided evolutionary search is increasingly used for automated algorithm discovery, yet most current methods track search progress primarily through executable programs and scalar fitness. Even when natural-language reasoning is used through heuristic descriptions or reflection, it typically remains transient mutation context or unstructured memory, rather than organized as persistent population-level state over strategic directions. As a result, evolutionary search can struggle to distinguish syntactically different implementations of the same idea, preserve lower-fitness but strategically promising directions, or detect when an entire family of strategies has saturated. We introduce \model, a modular strategy-space layer that turns language-level strategic reasoning into first-class population-level evolutionary state in LLM-driven program search. \model represents each candidate program with an explicit natural-language strategy, clusters the archive by strategy semantics, retrieves behaviorally complementary inspirations, and periodically navigates the strategy landscape to avoid saturated directions. Without modifying the underlying evolutionary algorithms, \model improves existing evolutionary backbones across algorithm discovery, systems optimization, and agent-scaffold design tasks in most settings. Across four systems benchmarks, \model achieves a 20.6% average relative improvement, with the best single run on Prism scoring 3× higher. These results suggest that persistent strategy representations provide a practical mechanism for improving the effectiveness and cost-efficiency of LLM-guided evolutionary search, pointing toward compound AI systems whose search capabilities benefit from the structured accumulation and reuse of algorithmic strategies.
Sichun Luo, Yi Huang, Haochen Luo +7
1The University of Hong Kong · 2JIUTIAN Research, China Mobile · 3City University of Hong Kong
Large language model (LLM)-driven evolution has shown promise for program search and algorithm discovery, but relying on strong models throughout long evolutionary runs is costly. A natural alternative is to combine cheap and strong models under a fixed inference budget. However, existing approaches typically allocate models at the level of individual queries or mutation steps, overlooking that evolutionary search is stateful: each generated candidate changes the population from which subsequent mutations are produced. We empirically analyze LLM-driven evolutionary trajectories and find that search progress is strongly front-loaded, early trajectory performance is informative but noisy, and cheap models recover much of the early progress achieved by strong models at lower cost. Motivated by these findings, we propose \model, a training-free framework that shifts budget allocation from individual calls to evolving populations through adaptive population handoff. A cheap model explores multiple trajectories in short blocks allocated by a bandit scheduler. Relay Gain, defined as the marginal improvement of a compact, quality-diverse candidate bank constructed for handoff, serves as the scheduler reward and determines when to hand off. The curated candidates initialize a shared strong model population for refinement. Across four benchmarks and three budgets, \model achieves the highest mean score in 11 of 12 settings, outperforming competitive baselines. Our results suggest that in stateful search, budget allocation should be organized around the population, not the individual call.
Sichun Luo, Yi Huang, Guanzhi Deng +6
1The University of Hong Kong · 2JIUTIAN Research, China Mobile · 3City University of Hong Kong +1