PROF: An LLM-based Reward Code Preference Optimization Framework for Offline Imitation Learning

Shengjie Sun, Jiafei Lyu, Runze Liu, Mengbei Yan, Bo Liu, Deheng Ye, Xiu Li · DOI

Abstract

Offline Reinforcement Learning (RL) often suffers from a lack of explicit reward functions in pre-collected datasets. While Offline Imitation Learning (IL) attempts to address this by leveraging expert demonstrations, existing methods frequently rely on black-box distance metrics that prioritize exact mimicry over interpretability and generalizability. We present PROF (LLM-based Reward Code Preference Optimization Framework), a novel system that utilizes Large Language Models (LLMs) to generate, rank, and iteratively refine executable Python reward functions. By introducing a Reward Preference Ranking (RPR) strategy, PROF optimizes reward code using only a single expert trajectory without environment interaction. Our framework achieves state-of-the-art performance on the D4RL benchmark, demonstrating significant improvements in MuJoCo, AntMaze, and Adroit tasks.

Introduction

In Reinforcement Learning, the absence of a "reward signal"—the mathematical formula defining success—is a significant bottleneck for offline data utilization. While we may possess logs of robotic movement and expert demonstrations, the underlying reward function remains implicit. Traditional Offline Imitation Learning (IL) typically employs distance metrics to reward trajectories that mimic expert behavior. However, this approach often leads to oversimplification, as it ignores diverse solutions to a task, and lacks interpretability, making it difficult for human engineers to diagnose agent failures.

PROF addresses these challenges by transforming reward design into a code optimization problem. By leveraging the semantic reasoning capabilities of LLMs, PROF generates human-readable Python code for reward functions, ensuring both transparency and high performance.

Methodology

PROF operates through a three-stage pipeline designed to refine reward functions without requiring environment interaction during the design phase.

The PROF framework consists of three stages: Reward Generation, Preference Ranking, and Iterative Optimization.
  1. Reward Generation: The system prompts an LLM with natural language descriptions of the environment and task. The LLM generates multiple candidate Python functions that calculate rewards based on state and action inputs.
  2. Reward Preference Ranking (RPR): This core innovation ranks candidates based on two principles: the expert trajectory should yield a higher return than noisy offline data, and it should outperform a perturbed (noised) version of itself. A dominance score is calculated for each function based on these preferences.
  3. Iterative Optimization (TextGrad): Using the TextGrad technique, the LLM acts as a "textual gradient engine." It analyzes the differences between high-ranking and low-ranking functions, reflects on logical discrepancies, and provides actionable code revisions to improve the reward logic.

Experimental Evaluation

The framework was evaluated on the D4RL benchmark, covering diverse domains:

  • MuJoCo Locomotion: Standard tasks including HalfCheetah, Hopper, and Walker2d.
  • AntMaze: Goal-conditioned navigation in complex maze environments.
  • Adroit: High-dimensional robotic hand manipulation tasks (e.g., door opening, pen manipulation).

Results and Discussion

PROF consistently matched or outperformed established baselines across all tested domains. In MuJoCo locomotion tasks, PROF achieved a total score of 724.8, surpassing the previous state-of-the-art method, SEABO.

Performance comparison on MuJoCo locomotion tasks. PROF (IQL+PROF) achieves the highest total score compared to baselines.

Key findings from the evaluation include:

  • Data Efficiency: PROF demonstrates that a single expert trajectory, combined with the semantic priors of an LLM, is sufficient to ground a robust reward function.
  • Interpretability: Executable Python code allows researchers to verify if the LLM is rewarding appropriate behaviors, such as forward velocity versus energy efficiency.
  • Optimization Thresholds: The study identified an optimal iteration threshold; while simple tasks peak early, complex tasks like AntMaze benefit from further refinement. However, excessive iterations can lead to "reward hacking," where the LLM optimizes for dominance scores rather than actual task performance.

Conclusion

PROF represents a significant step toward interpretable and automated reward engineering in offline RL. By bridging the gap between natural language task descriptions and executable code, it enables agents to learn effectively from minimal expert data. Future work will address the framework's dependency on high-quality semantic environment descriptions and the computational overhead associated with iterative LLM calls.

Summary updated

BibTeX
@misc{sun2025prof,
  author = {Shengjie Sun and Jiafei Lyu and Runze Liu and Mengbei Yan and Bo Liu and Deheng Ye and Xiu Li},
  title = {{PROF: An LLM-based Reward Code Preference Optimization Framework for Offline Imitation Learning}},
  year = {2025},
  eprint = {2511.13765},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2511.13765},
}
Figure