Abstract
Designing effective reward functions for reinforcement learning (RL) is a notoriously difficult and time-consuming task, often referred to as a "black art." This paper introduces an automated framework that leverages the reasoning and coding capabilities of Large Language Models (LLMs) to write, evaluate, and iteratively refine reward functions for autonomous highway driving. By integrating the LLM into a feedback loop of RL training and performance reflection, the system produces interpretable Python-based reward functions. Experimental results in the Highway-env simulator demonstrate that LLM-evolved rewards can outperform expert-handcrafted functions by 22% in success rate while achieving faster convergence in complex traffic scenarios.
Introduction
Reinforcement Learning is a cornerstone of autonomous driving research, yet its success is fundamentally tethered to the quality of the reward function. This mathematical formula defines the agent's objectives, balancing competing priorities such as safety, speed, and passenger comfort. Traditionally, reward engineering requires weeks of manual trial-and-error by human experts. While automated alternatives like Inverse Reinforcement Learning (IRL) exist, they typically require massive amounts of human driving data and result in "black box" rewards that lack interpretability.
This research addresses these challenges by using LLMs to automate reward engineering. By treating the LLM as an expert reward engineer capable of understanding simulator logic and reflecting on performance data, the authors bridge the gap between automated optimization and human-readable code.
The Iterative Reward Evolution Framework
The proposed framework treats the LLM as the central engine in an iterative design loop. The process is divided into four distinct stages:
- Environment Contextualization: Rather than providing a high-level text summary, the authors provide the LLM with the actual source code of the
Highway-envsimulator. This allows the model to identify available state variables (e.g., vehicle velocity, lane IDs, or collision flags) directly from the class definitions. - Initial Generation: Using a specialized prompt template, the LLM (specifically Claude 3-Haiku) generates several candidate reward functions in Python.
- RL Training and Evaluation: These functions are integrated into a Deep Q-Network (DQN) agent. The agent is trained for 20,000 steps, and its performance is quantified using metrics such as collision rates and average speed.
- Reflection and Evolution: The performance metrics are fed back to the LLM in natural language. The model "reflects" on the agent's failures—for instance, noting if an agent is driving too conservatively—and generates a refined version of the reward code. This evolutionary process continues for several iterations, allowing the reward logic to mature.
Experimental Setup
The framework was evaluated using the Highway-env simulator across three traffic configurations of increasing complexity:
- lane-3-density-1: Three lanes with low traffic density.
- lane-3-density-1.5: Three lanes with medium traffic density.
- lane-4-density-2: Four lanes with high traffic density, representing the most challenging environment.
The performance of the LLM-generated rewards was benchmarked against the "Human" reward—the standard expert-designed function provided within the Highway-env repository.
Key Insights
Code as the Primary Interface
A significant finding was that providing the LLM with the simulator's source code was more effective than providing manual descriptions. LLMs, trained on vast repositories of code, are adept at parsing environment logic and identifying usable variables directly from class definitions.
The Efficacy of Claude 3-Haiku
While initial experiments utilized GPT-4, the researchers found that Claude 3-Haiku was more effective for this specific task. It consistently generated executable, error-free Python code and proved to be a more cost-effective solution for the iterative evolution process.
Interpretability and Safety
Unlike neural-network-based rewards, the LLM outputs standard Python code. This ensures that the reward logic remains transparent and auditable by human safety engineers, preventing "reward hacking"—where an agent finds unintended shortcuts to maximize scores at the expense of safety.
Results
The LLM-evolved rewards demonstrated a 22% higher average success rate compared to expert-handcrafted rewards. In the most complex high-density scenarios, the LLM-designed rewards reached high success rates significantly faster than the human baseline, which often struggled to converge.
Observations of the evolution process showed the LLM moving from simple hyperparameter adjustments in early iterations to complex structural changes in the reward's functional form in later stages, demonstrating a sophisticated understanding of the driving task's requirements.
Conclusion and Future Work
This work demonstrates that LLMs can effectively automate the "black art" of reward engineering for autonomous driving. While the current study focused on structured highway environments, future research will explore more complex urban scenarios, such as intersections and roundabouts. Additionally, incorporating techniques like Chain-of-Thought (CoT) reasoning and explicit safety guardrails within the prompt could further enhance the robustness and safety of the generated reward functions.
Summary updated