LLM-based code generation fails when correctness depends on execution-dependent coupling: the meaning of one routine is defined by the runtime behavior of another, a relationship that cannot be resolved from textual descriptions alone. This limitation, which we call static binding, is not confined to explicitly coupled problems; it appears to varying degrees whenever correctness depends on joint execution behavior across components, from explicit cross-coupled optimizers to subtler joint constraints in packing, routing, and symbolic search. This paper proposes dynamic context adaptation, a sample-efficient validation-generation loop designed for this setting. A validation agent extracts structured diagnostic information from execution traces, providing gradient-like guidance to a generation agent that proposes multiple candidates per iteration. A knowledge graph derived from the problem description supplies semantic constraints to the generation agent. Simulated annealing selects among candidates to avoid greedy collapse. Our method outperforms zero-shot, Reflexion, and OpenEvolve on seven of eight problems at both 300 and 600 evaluations (p < 0.01), a regime where population-based search has not yet accumulated sufficient diversity to compete. Notably, on the primary motivating problem (cross-coupled optimization), our method also achieves the best score at 1000 evaluations, consistent with the hypothesis that structured execution feedback is most beneficial when correctness depends on runtime coupling. Ablation results confirm that structured execution feedback is the primary driver.
Figures & tables
Property
Zero-shot
Reflexion [ 13 ]
AlphaEvolve [ 11 ]
Ours
Iterative refinement
✗
✓
✓
✓
Structured feedback
✗
✗
✗
✓
Multi-candidate per iter.
✗
✗
✓
✓
Non-greedy selection
✗
✗
✓
✓
Semantic layer (KG)
✗
✗
✗
✓
Table 1: Qualitative comparison of LLM-based code generation approaches.
Figure 1: Meaning dependencies among components: (a)-(d) the four cases; (e) Example 1; (f) Example 2; (g) general case with auxiliary aux .
Figure 2: Left: validation-generation pipeline. Right: SA selection with Metropolis acceptance and geometric cooling.
Figure 3: Knowledge graphs showing modules, requirements, and meaning dependencies.
Problem
Type
Dep.
Zero-shot
Reflexion
OpenEvolve
Ours
Maze Nav.
Discrete plan.
2
11.7
23.1 ± 2.3
28.3 ± 1.8
27.1 ± 1.2
Circle Pack.
Comb. geo.
1
0.364
0.869 ± 0.051
0.978 ± 0.011
0.961 ± 0.018
Func. Min.
Cont. opt.
1
1.215
1.481 ± 0.031
1.519 ± 0.008
1.514 ± 0.009
Cross-Coupled
Multi-obj. opt.
4
0.511
0.603 ± 0.027
0.681 ± 0.028
0.694 ± 0.019
TSP
Comb. opt.
1
0.398
0.644 ± 0.046
0.803 ± 0.024
0.775 ± 0.027
Signal Proc.
Filter design
1
0.291
0.528 ± 0.054
0.715 ± 0.039
0.692 ± 0.038
Table 2: Results at 1000 evaluations (mean ± std, 10 seeds, Qwen2.5-72B). Bold: best per problem. Dep.: primary meaning-dependency case (§ 3 ); P1 and P2 have explicit coupled semantics (cases 2 and 4), while P3–P8 exhibit latent execution-dependent coupling (case 1 in primary structure).
300 evals
600 evals
1000 evals
Problem
OE
Ours
OE
Ours
OE
Ours
Maze Nav.
19.2 ± 3.1
25.8 ± 1.4
23.3 ± 2.5
26.8 ± 1.3
28.3 ± 1.8
27.1 ± 1.2
Circle Pack.
0.903 ± 0.035
0.952 ± 0.024
0.937 ± 0.025
0.959 ± 0.020
0.978 ± 0.011
0.961 ± 0.018
Func. Min.
1.519 ± 0.014
1.511 ± 0.011
1.519 ± 0.011
1.513 ± 0.010
1.519 ± 0.008
1.514 ± 0.009
Cross-Coupled
0.563 ± 0.042
0.654 ± 0.021
0.621 ± 0.035
0.665 ± 0.020
0.681 ± 0.028
0.694 ± 0.019
TSP
0.701 ± 0.036
0.761 ± 0.033
0.747 ± 0.030
0.772 ± 0.029
0.803 ± 0.024
0.775 ± 0.027
Table 3: Convergence comparison: OpenEvolve (OE) vs. Ours at 300, 600, and 1000 evaluations (mean ± std, 10 seeds). Bold: best per problem at each budget.
Figure 4: Running maximum (best-so-far) score vs. evaluation count (mean ± 1 std, 10 seeds) for circle packing (left) and maze navigation (right). Our method outperforms OpenEvolve up to ∼ 650 evaluations (circle packing) and ∼ 710 evaluations (maze navigation); OpenEvolve surpasses it at 1000 evaluations.
Condition
Maze
Circle
Func Min.
Cross-Cpl.
Full (Ours)
25.8 ± 1.4
0.952 ± 0.024
1.511 ± 0.011
0.654 ± 0.021
w/o Feedback
18.6 ± 2.8
0.657 ± 0.081
1.330 ± 0.058
0.582 ± 0.029
Greedy (no SA)
21.7 ± 2.9
0.866 ± 0.097
1.481 ± 0.038
0.615 ± 0.037
Random selection
14.4 ± 4.1
0.533 ± 0.152
1.209 ± 0.131
0.536 ± 0.051
w/o KG
21.9 ± 2.1
0.895 ± 0.058
1.481 ± 0.029
0.628 ± 0.033
Table 4: Ablation study at 300 evaluations (mean ± std, 10 seeds). Full system in bold.