Manuscript Offprint

arXiv:2609.04570

Dynamic Adaptation of the LLM Context for Generating Routines with Coupled Semantics

Gnaneswar Villuri, Hashmath Shaik, Alex Doboli

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Gnaneswar Villuri, Hashmath Shaik, and Alex Doboli

Department of ECE, Stony Brook University, Stony Brook, NY, USA

gnaneswar.villuri@stonybrook.edu

Abstract. 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.01p < 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.

Keywords: large language models · code generation · execution feedback · simulated annealing · sample-efficient optimization

1 Introduction

Automated software generation using LLMs has become a prominent research topic [1–3], with tools, e.g., Cursor [4,5], offering substantial productivity gains [6, 7]. LLM-based code generation excels at scaffolding but misses execution-dependent patterns [8]. Evolutionary methods (like genetic programming [9], FunSearch [10], AlphaEvolve [11]) use mutation operators but require thousands of evaluations. Feedback-driven methods, i.e. CEGIS [12] and Reflexion [13], iterate from execution outcomes, but Reflexion operates on a single trajectory without structured

G. Villuri et al.

Table 1: Qualitative comparison of LLM-based code generation approaches.

PropertyZero-shotReflexion [13]AlphaEvolve [11]Ours
Iterative refinementX✓✓✓
Structured feedbackXXX✓
Multi-candidate per iter.XX✓✓
Non-greedy selectionXX✓✓
Semantic layer (KG)XXX✓

diagnostic extraction or multi-candidate generation, and commits greedily to improvements. Moreover, a persistent limitation remains: LLMs struggle when the correctness of one component depends on the runtime behavior of another, not just its textual description. We call this static binding: inter-component meaning dependencies can be resolved only by observing the execution patterns of the components.

The code generation method proposed in this paper uses a validation-generation agent loop with a knowledge-graph (KG) intermediate layer and simulated annealing (SA) for candidate selection to generate multiple candidates per iteration, enabling broader exploration (see Section 4). To address the limitations of static binding, a dedicated validation agent extracts structured feedback from code execution traces rather than from free-form verbal reflection. SA balances exploration and exploitation instead of making greedy commitments, as in most current approaches. The central claim is sample efficiency: structured execution feedback produces rapid, directed improvement before population-based diversity can accumulate. Our convergence curves locate the crossover with population-based search empirically at 600–800 evaluations; below that threshold our system outperforms all iterative baselines on seven of eight problems at both 300 and 600 evaluations (p<0.01p < 0.01, Table 2, Figure 4). The crossover reflects a complementary tradeoff between feedback-driven early convergence and population-based asymptotic exploration, not a failure of the feedback mechanism.

This paper makes the following contributions:

  1. It presents a formal taxonomy of meaning dependencies among software components, providing a precise characterization of the LLM static-binding limitation. Four related cases are discussed in Section 3.

  2. It proposes a novel two-agent, KG-based system architecture for code synthesis (Section 4).

  3. It provides empirical evidence of superior sample efficiency: our method outperforms all iterative baselines on seven of eight problems at both 300 and 600 evaluations (p<0.01p < 0.01), with the feedback-vs-diversity crossover located empirically at 600–800 evaluations (Section 6).