Execution-Grounded Agents: Enforcing Physical Constraints in AI Code Generation via Oracle Search

Hugo González Grañena, Cilicia Uzziel PerezDL4C @ ICML 2026

TL;DR

This paper introduces Oracle-Guided Trajectory Search (OGTS), a method to ensure AI-generated scientific code isn't just syntactically correct, but physically valid. By treating a scientific "oracle" (a deterministic checker) as an environment in a reinforcement learning loop at inference time, the authors boosted the pass rate of Llama-3.1-70b from 58% to 84% on complex scientific tasks.

What Problem Does This Paper Address?

When researchers use LLMs to write code for physics or biology, they face a dangerous failure mode: reward misalignment. A model might produce a Python script that is "fluent," well-structured, and executes without errors, yet is scientifically "hallucinated."

For example, the code might ignore Monte Carlo event weights in a physics calculation or use 0-based indexing for a formula that mathematically requires 1-based indexing. Standard coding benchmarks like HumanEval or MBPP don't catch these errors because they focus on general programming logic rather than domain-specific physical constraints. In a real-world lab, a script that runs but produces a subtly wrong number is often more damaging than a script that simply crashes.

Methods

The authors reframe scientific code assistance as inference-time Reinforcement Learning (RL). They treat the LLM as a "base policy" and a deterministic scientific oracle as the "environment."

The core algorithm is Oracle-Guided Trajectory Search (OGTS):

  1. Branching: At each step, the model generates a batch of candidate programs.
  2. Oracle Evaluation: A deterministic oracle executes the code and returns "world feedback." This isn't just a pass/fail; it includes execution exceptions, numerical deviations from a reference, and domain-invariant violations (e.g., "you violated the law of conservation of energy").
  3. Greedy Collapse: Instead of doing a complex tree search (like MCTS), the algorithm prunes low-value trajectories and keeps only the most "informative" failure.
  4. Refinement: The model is prompted again, now conditioned on that specific, structured oracle feedback to "repair" the code.

This approach differs from standard "self-correction" (like Reflexion) because it relies on hard execution grounding rather than the LLM's subjective "reflection" on its own mistakes.

Datasets

The researchers evaluated their framework using:

  • A 50-task Scientific Oracle Suite: Hand-curated tasks covering families like AMS (Approximate Median Significance), weighted log-loss, nDCG, and threshold scans. These tasks prioritize "semantic density"—enforcing physical invariants like probability sums and regulated formulas.
  • ATLAS Higgs Boson Challenge Reproduction: A reproduction of the 2014 machine learning challenge from CERN, requiring the model to handle Monte Carlo weights and specific physics metrics correctly.
  • 500-Query Retrieval Benchmark: Used to test the "AI Scientist's" ability to find the correct documentary evidence before writing code.

Key Insights and Ideas

  • "Greedy Collapse" is Efficient: In scientific programming, a failure often points to a localized semantic defect. The authors found that full tree searches are often wasteful; simply picking the most informative failure and iterating on it is more compute-efficient.
  • Diversity is the Signal: The authors discovered that the standard way of categorizing errors (syntax vs. numerical vs. invariant) isn't enough to predict if a search will succeed. Instead, within-category score diversity—how differently the various code candidates fail—is the key signal that the oracle can successfully guide the model to a fix.
  • Inference-Time Equalization: OGTS allows smaller, open-weight models (like Llama-3.1-70b) to approach the performance of "frontier" models (like Claude-3.7-Sonnet). This is vital for researchers who cannot send sensitive data to commercial APIs and must run models locally.

Key Results

  • Performance Boost: On the 50-task suite, Llama-3.1-70b jumped from a 58% pass rate (with simple retries) to 84% using OGTS.
  • Frontier Comparison: While Claude-3.7-Sonnet saturated the benchmark at 100%, the OGTS framework effectively narrowed the gap between local open-weight models and top-tier proprietary ones.
  • Efficiency: OGTS achieved these gains much more efficiently than "blind" sampling. For instance, OGTS reached an 84% pass rate with ~194 oracle calls, whereas a blind retry strategy required 270 calls to reach a similar level.

Limitations and Future Work

  • Model/Provider Sensitivity: In a replication study using Llama-3.3-70B-Turbo on a different provider, the "strategy ordering" changed. The authors honestly note that factors like quantization (FP8 vs FP16) and decoding configurations can significantly impact how well a model responds to long, structured oracle traces.
  • Instrumentation Needs: The authors suggest that future evaluation infrastructures need to log per-candidate oracle responses at every depth to better understand why certain "repair paths" work better than others.
  • Domain Expansion: While this paper focused on high-energy physics, the authors note the API is domain-agnostic and could be applied to chemistry (stoichiometric validation) or biology (genomic sentinel conventions).

Summary updated

BibTeX
@inproceedings{granena2026execution,
  author = {Hugo González Grañena and Cilicia Uzziel Perez},
  title = {{Execution-Grounded Agents: Enforcing Physical Constraints in AI Code Generation via Oracle Search}},
  booktitle = {DL4C @ ICML},
  year = {2026},
  url = {https://openreview.net/forum?id=wELtV7SAqF},
}
Figure