NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Synthesizing Programmatic Reinforcement Learning Policies with Large Language Model Guided Search

Max Liu, Chan-Hung Yu, Wei-Hsu Lee, Cheng-Wei Hung, Yen-Chun Chen, Shao-Hua Sun

Abstract

Programmatic reinforcement learning (PRL) has been explored for representing policies through programs as a means to achieve interpretability and generalization. Despite promising outcomes, current state-of-the-art PRL methods are hindered by sample inefficiency, necessitating tens of millions of program-environment interactions. To tackle this challenge, we introduce a novel LLM-guided search framework (LLM-GS). Our key insight is to leverage the programming expertise and common sense reasoning of LLMs to enhance the efficiency of assumption-free, random-guessing search methods. We address the challenge of LLMs' inability to generate precise and grammatically correct programs in domain-specific languages (DSLs) by proposing a Pythonic-DSL strategy - an LLM is instructed to initially generate Python codes and then convert them into DSL programs. To further optimize the LLM-generated programs, we develop a search algorithm named Scheduled Hill Climbing, designed to efficiently explore the programmatic search space to improve the programs consistently. Experimental results in the Karel domain demonstrate our LLM-GS framework's superior effectiveness and efficiency. Extensive ablation studies further verify the critical role of our Pythonic-DSL strategy and Scheduled Hill Climbing algorithm. Moreover, we conduct experiments with two novel tasks, showing that LLM-GS enables users without programming skills and knowledge of the domain or DSL to describe the tasks in natural language to obtain performant programs.

Introduction

Deep Reinforcement Learning (DRL) has achieved incredible feats, but it faces two major hurdles: its policies are often "black boxes" lacking interpretability, and they frequently fail to generalize to new scenarios. Programmatic Reinforcement Learning (PRL) addresses these issues by representing policies as human-readable code in Domain-Specific Languages (DSLs).

However, PRL suffers from extreme sample inefficiency. Finding the optimal program requires searching an astronomical space of possibilities. Current state-of-the-art methods often require tens of millions of environment interactions, making them impractical for complex tasks. This paper introduces LLM-GS, a framework that leverages Large Language Models (LLMs) to prune the search space and guide the discovery process, achieving state-of-the-art performance with significantly fewer interactions.

Methods: The LLM-GS Framework

The LLM-Guided Search (LLM-GS) framework consists of three main components:

1. Domain and Task-Aware Prompting

Instead of simple task requests, LLM-GS provides "scaffolding" prompts describing the environment's physics, actions, and perceptions in natural language. This allows the LLM to use its internal world knowledge to reason about the problem effectively.

2. Pythonic-DSL Strategy

LLMs excel at Python but often struggle with niche, low-level DSLs. LLM-GS instructs the model to write a solution in "constrained Python" first. A specialized parser then converts this Python code into the target DSL. This leverages the LLM's vast training data on general-purpose programming to overcome the "language barrier."

The Domain-Specific Language (DSL) used for programmatic policies in the Karel environment.

3. Scheduled Hill Climbing (SHC)

Initial LLM-generated programs are often good but imperfect. LLM-GS uses SHC to optimize them. Unlike standard Hill Climbing with a fixed search neighborhood, SHC uses a sinusoidal scheduler to gradually increase search breadth. This enables fine-tuning early on and broader exploration later if a solution remains elusive.

Key Insights

  • LLMs as "Search Pruners": LLMs don't need to be perfect; they just need to be better than random. By providing a "warm start" reflecting human-like reasoning, they prevent the search algorithm from wasting millions of steps on nonsensical programs.
  • Two-Stage Success: On difficult tasks like DoorKey, LLMs correctly identify the problem as a multi-stage process (e.g., find key, then find door). This structural understanding is something purely search-based algorithms struggle to discover from scratch.
The DoorKey task requires a two-stage logic: first finding the key, then reaching the goal.

Key Results

  • Massive Efficiency Gains: In the DoorKey task, LLM-GS converged to an optimal solution within 500,000 interactions, while baseline methods failed even after 1,000,000.
  • Higher Quality Code: The Pythonic-DSL strategy resulted in a much higher "acceptance rate" (grammatically correct code) and better average returns compared to direct DSL generation.
  • State-of-the-Art Performance: LLM-GS outperformed existing programmatic RL baselines (like LEAPS and HPRL) across almost all tested tasks in both the Karel and MiniGrid domains.
  • Zero-Shot Adaptability: The system successfully generated performant programs for entirely new tasks using only natural language descriptions, highlighting its potential for non-expert users.

Limitations and Future Work

While promising, the framework currently depends on domain experts to define the DSL grammar and environment rules. Additionally, it relies on high-performing, often proprietary LLMs like GPT-4, which may present cost and availability bottlenecks. Scaling this approach to high-dimensional, continuous control tasks (e.g., robotics) remains a significant challenge, as defining suitable DSLs for such domains is non-trivial. Future work will explore automating DSL creation and enhancing LLM "self-repair" capabilities based on execution traces.

Summary updated

BibTeX
@inproceedings{liu2025synthesizing,
  author = {Max Liu and Chan-Hung Yu and Wei-Hsu Lee and Cheng-Wei Hung and Yen-Chun Chen and Shao-Hua Sun},
  title = {{Synthesizing Programmatic Reinforcement Learning Policies with Large Language Model Guided Search}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=8DBTq09LgN},
}
Figure