Reward
A reward is the environment’s immediate feedback after an agent takes an action. It is usually just one number: positive for outcomes the designer wants, negative for outcomes to avoid, and zero when nothing noteworthy happens. Yet that small signal is what gives reinforcement learning a direction—without labelled “correct actions,” the agent must discover for itself which behaviour earns more reward over time.
How reward drives learning
At time step t, an agent observes a situation, chooses an action, and receives a reward rt+1 along with the next situation. The reward is immediate; the real objective is usually the return, the discounted sum of future rewards. Discounting, controlled by γ, makes a reward now count more than the same reward far in the future. For example, a robot can receive a small penalty for each second it spends moving and a large positive reward for reaching its goal. PPO or DQN then adjusts its policy or value estimates toward actions predicted to produce higher long-term return—not merely the largest reward on the next step.
Reward is a specification, not a moral judgment
The agent does exactly what the reward makes profitable, including loopholes the designer did not intend. This is called reward hacking. Common failures include:
- A game-playing agent earns points by circling around collectible items instead of finishing the level.
- A simulated robot is rewarded for forward speed and learns to fall in a way that fools the simulator’s measurement.
- A navigation agent receives only a reward at the destination, making useful learning painfully slow because successful trajectories are rare.
Why its design matters
Reward connects the environment to the learning update: value functions estimate expected future reward, and policy-gradient methods raise the probability of actions associated with better return. A sparse, delayed, noisy, or badly scaled reward makes credit assignment difficult and can produce unstable training or a policy that optimizes the wrong behaviour. In a Gymnasium environment, the reward returned by each step() is therefore not incidental bookkeeping—it is the operational statement of what “success” means.
Reward is the scalar feedback signal an environment returns after an agent acts, indicating the immediate desirability of the resulting outcome. The agent learns a policy that maximizes expected cumulative, usually discounted, reward rather than merely maximizing each immediate reward. Reward defines the learning objective: its timing, scale, and design determine which behaviors are reinforced and whether the agent can assign credit to earlier actions.
Think of teaching a dog: a treat after sitting tells it, “That was a good choice.” In the same way, a reward is a simple score that tells an AI how well its last choice turned out.
A high reward means the outcome was helpful; a low or negative reward means it was poor. A game-playing AI might get a reward for winning, while a robot vacuum might get one for cleaning a room without bumping into furniture. The AI is not handed a list of correct moves. Instead, it gradually learns which choices tend to lead to better rewards, including rewards that may arrive much later.