Zero Labs
Industry News / AI

The More I Tuned My Reward Function, The Worse My RL Agent Got

Source · Towards AI By Efe Dayanır

From the publisher’s feed, collected in the ZeroLabs newsroom.

A practical lesson from building a drone navigation agent and why simpler rewards often win in reinforcement learningFigure 1 — One reward function, three difficulty levels, and the failure mode becomes obvious: the agent solves the easy task cleanly, still reaches the goal in medium difficulty with some inefficiency, but in hard mode it does not crash — it hesitates, loses long-horizon progress, and times out. Source: Image by the author.My reinforcement learning agent refused to move.It wasn’t because of an issue with PPO.It wasn’t due to the environment either.It was all because I designed the reward function too well.For days, I kept modifying penalties and bonuses as if it would magically start working. Somehow, I was convinced that more guidance would fix everything. Instead, I accidentally taught the agent something else:Doing nothing is safer than doing something wrong.The SetupFor a high school project, I built a 2D drone navigation environment from scratch. The task was to start at a random position, avoid obstacles, and reach a goal, all while trying to maximize efficiency.The agent had no global map. It relied only on relative goal direction, velocity, heading, and lidar-like ray-based sensors. And importantly, it didn’t control position directly. Its output was just a target heading and a target speed, just as it would be in a real-world scenario.These were executed through a PD controller, using real dynamics. This forced the agent to make decisions with imperfect knowledge of the outside world and the effects of its actions, thus forcing the agent to truly learn navigation.For training, I used PPO with continuous actions. The policy controlled target heading and target speed, while the environment handled the low-level dynamics through the PD controller. Observations were normalized during training using VecNormalize. The goal was not to tune PPO aggressively, but to understand how reward design affected learning behavior.The ProblemAt first, the agent behaved poorly. It was stalling, hesitating so much that it ultimately got nowhere and timed out. Initial Metrics:• Success: ~10% • Timeout: ~50% • Stuck: ~40% Clearly, something was wrong.My First MistakeI assumed the reward function needed improvement. I went on to add smoothness penalties, low-speed penalties, stall penalties, alignment rewards, timeout penalties…More guidance means better learning… right?Wrong.It Got WorseThe agent became overly cautious, slow, and extremely indecisive. It learned to avoid mistakes at all costs, even if it meant sacrificing task completion. It stopped taking any action it deemed risky, including movement, which was why I had changed the reward function in the first place.The BreakthroughOut of frustration, I removed almost everything. What remained was the reward for reaching the goal, the reward for progress toward the goal, and the penalty for collision.The reward still shaped progress toward the goal, but it no longer tried to micromanage every behavior.To make the difference clearer, this is roughly how the reward changed:Simplified reward logic (conceptual implementation):reward = 0.0# reward progress toward the goalprogress = previous_distance - current_distancereward += 60.0 * progress# reward reaching the goalif reached_goal: reward += 200.0# penalize collisionsif collision: reward -= 40.0# small step costreward -= 0.001The reward no longer tried to control every aspect of behavior. It only encouraged progress and punished failure.What Happened NextPerformance improved dramatically.Each configuration was trained for 800,000 timesteps using the same random seed (42). This does not make the result a statistically rigorous benchmark, but it does make the comparison useful as a controlled debugging case study: the main variable I changed was the reward design and, later, environment difficulty.I tested the policy on progressively harder environments to see if the simpler reward actually helped learning.Figure 2 — Success rate drops as environment complexity increases. Source: Image by the authorThe difficulty levels were not different algorithms. They used the same PPO setup, but changed the environment:- Easy: no obstacles and a larger goal region- Medium: fewer obstacles and moderate navigation difficulty- Hard: more obstacles, a smaller goal region, and longer navigation requirementsThis suggests that the drop in performance mainly reflects increasing environment complexity, not a different learning algorithm.The reported success rates were measured using deterministic evaluation over 300 episodes for each difficulty level.Easy: nearly solved (~97%)Medium: learnable (~74%)Hard: challenging (~40%)What about failures?Figure 3— Timeout becomes the dominant failure mode in harder environments. Source: Image by the authorThe key observation here is that in harder environments, timeout becomes significantly more important. Avoiding collisions seems easier for the agent than maintaining long-horizon progress toward the goal.What the Metrics Actually RevealedAt first, I assumed the hard environment failed mainly because of collisions. But after looking more carefully at the evaluation metrics, that explanation no longer matched the behavior I was seeing. The collision penalty stayed relatively small even in hard mode. What changed much more dramatically was progress toward the goal.As the environments became harder:episode length increased significantlypath efficiency dropped sharplytimeout became the dominant failure modeThis suggests that the main problem was not obstacle avoidance itself.The agent could often avoid nearby obstacles reasonably well. The harder challenge was maintaining consistent long-horizon progress toward the goal.Another interesting detail appeared in the reward decomposition.The collision term changed only slightly across difficulty levels. Meanwhile, both goal reward and progress reward dropped significantly.That changed how I interpreted the failures.The hard policy was not simply crashing. In many episodes, it was still moving, avoiding obstacles, and partially navigating toward the goal. The real issue was that it could not sustain efficient decision-making long enough to consistently finish the task.What the Agent Actually LearnedStatic plots are useful, but they hide the decision process, whereas the animations tell us the full story. Before diving into individual cases, here is what a full trajectory looks like in motion.Figure 4— Side-by-side real PPO rollouts. The easy policy enters the goal region reliably, while the hard policy struggles with long-horizon planning and eventually times out. Source: Image by the authorThe hard policy is particularly interesting because it does not fail at random. The agent can move, avoid obstacles, and partially navigate toward the goal. However, it ultimately loses behavioral consistency and times out.EasyFigure 5— Easy environment trajectory. The agent follows a smooth and direct path into the goal region. Source: Image by the authorThe agent moves directly, behaves smoothly, and reaches the goal efficiently. This matches the high success rate.MediumFigure 6— Medium environment trajectory. The agent reaches the goal but exhibits inefficiencies. Source: Image by the authorNow we see curved paths and small hesitations, but still by all means a successful run. Despite this, failures become more common across runs.HardFigure 7— Hard environment trajectory. The agent fails to reach the goal and times out. Source: Image by the authorThis is the most important failure mode in the entire system. This is where learning starts to break. The agent is not failing because of collisions. It is failing because it cannot make a confident decision. The agent starts toward the goal, slows down, hesitates, stops progressing, and eventually, times out.A Subtle but Important DetailThe agent does not aim for the exact goal, but for the goal region. This is important, because the reward is defined as reaching a radius around the goal. Therefore, the agent learns to be sufficient, not precise. This makes it more efficient and realistic, as setting an acceptable margin of error works better than aiming for absolute precision.The Real InsightI didn’t fix the agent by improving the reward. I fixed it by removing most of it. What I thought was helpful just ended up adding noise, creating conflicting objectives, and slowing learning down. The agent wasn’t struggling because the reward was too simple.It was struggling because it was too complicated.One important limitation is that this does not prove reward simplification was the only reason for improvement. Reinforcement learning has training variance, and different seeds can sometimes lead to different results.However, the behavioral change was consistent with the reward change. With the over-shaped reward, the agent often became cautious and inactive. With the simplified reward, it moved more confidently toward the goal.So I do not see this as a perfect proof, but as strong evidence that the reward design was a major factor.What Actually Works• Keeping the reward tied to the actual objective• Using environment difficulty, not reward micromanagement, to create harder learning problemsWhat Doesn’t Work• Over-engineered rewards • Too many penalties • Trying to control behavior explicitlyThese lead to hesitation, inefficiency, and overall poor learning.Final ResultsPerformance drops as the environment becomes harder, but the learned behavior remains interpretable: the agent still avoids collisions and attempts navigation, while timeout becomes the dominant failure mode.The most important outcome here isn’t the success rate. What matters is not that the hard environment was solved, but that the failure mode became understandable: the agent could still avoid collisions and attempt navigation, but struggled with long-horizon progress.TakeawaysIf your RL agent is stuck:• simplify the reward • reduce penalties • avoid over-guidance • gradually increase environment difficultyLet the agent learn, not obey.Final ThoughtIn hindsight, the problem was never the algorithm. It was the assumptions I made while designing the reward. I didn’t improve my agent by adding more logic. I improved it by trusting the learning process. And in reinforcement learning, the hardest part isn’t designing rewards; it is knowing when to stop.Full project repository:https://github.com/efedayanir/drone-nav-hybridThe More I Tuned My Reward Function, The Worse My RL Agent Got was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.