Reinforcement learning
Instead of learning from a table of right answers, a reinforcement learning system tries actions in an environment and learns from numerical feedback called rewards—even when those rewards arrive late or point to the wrong shortcut.
The reinforcement learning loop.
In Lesson 4.1, you saw supervised learning, where a model learns from examples paired with target labels or values. Reinforcement learning works differently: nobody supplies a right answer for every step upfront.
Instead, learning happens through a repeating loop of trial and feedback built from five pieces:
Agent
The decision-maker that chooses what to do next.
Environment
The world or problem the agent acts inside and gets feedback from.
State
The current situation the agent observes, such as its position.
Action
One choice the agent makes in the current state.
Reward
A numerical signal from the environment scoring what happened after an action.
Pip (an invented watering bot for this lesson) starts carrying water at the top-left corner of a tiny 4×3 greenhouse grid with a 10-step battery limit. Pip’s job is to reach a thirsty Seedling (+10) while avoiding two wet Puddles (−5).
On each turn, the agent (Pip) checks its state—which tile it is on and how many steps remain—and picks an action (Up, Down, Left, or Right). The environment (the greenhouse grid) moves Pip to the next tile and returns the next state plus a designed reward score—for instance, 0 on a safe tile, −5 on a puddle, or +10 at the seedling.
In everyday life, this feels a bit like training a puppy with treats: the puppy tries actions and repeats the ones that earn treats. Unlike a puppy, though, a software agent does not feel pleasure or understand your wishes—it updates internal numbers to favor choices that tend to earn more reward over time.

In the rest of this lesson, you will see why rewards can arrive late after earlier moves, why a high reward is not the same as “correct,” guide Pip across the grid yourself, and check your understanding.
Why rewards can arrive late.
In Pip’s greenhouse, stepping into a puddle gives −5 right away, and safe tiles give 0 right away. A delayed reward is a payoff that arrives later than the earlier action—or sequence of actions—that helped earn it.
To steer around both puddles and reach the seedling, Pip takes five moves: Down, Down, Right, Right, Right. The +10 payoff arrives right when Pip reaches the seedling on step 5, making it delayed relative to steps 1 through 4 that each scored 0.
That delay creates a tricky puzzle called credit assignment: when +10 finally arrives on step 5, the agent has to figure out which earlier moves actually helped earn it. If Pip wandered in a circle first, only some of the earlier steps deserved credit.
Cooking a pot of soup works the same way. Chopping vegetables and simmering for twenty minutes give no immediate taste payoff—you only find out at the end whether the early steps paid off.

Why a high reward does not mean “correct.”
It is tempting to assume that a high reward means the agent did the right thing. Sometimes a reward tracks the intended goal directly, like Pip’s +10 for watering the seedling—but designers also add a proxy (a stand-in score meant to encourage progress toward the real goal), and a poorly chosen proxy can backfire.
Pip already starts carrying water, so the Water Tap next to Start is optional. Suppose a designer adds a +4 proxy bonus every time Pip visits that tap within the 10-step battery limit—using tap visits as a stand-in for useful movement even though visiting the tap does not water the seedling.
Now compare two routes under that exact same +4 tap-bonus rule:
Direct route: Pip walks around the puddles and waters the seedling. The real task succeeds, and the run ends with +10.
Tap loop: Pip bounces between Start and the Water Tap five times, earning +20—the highest possible score in 10 steps—without ever watering the seedling.
Pip did not “cheat” or break a rule—it maximized the score it was given. In the real world, paying a customer-support team purely for the shortest phone calls can create the same mismatch: staff can hit high scores by hanging up early instead of solving problems.

Guide Pip across the greenhouse.
Try both reward rules in this small grid simulation. Notice how quiet steps build toward a delayed payoff—and how a flawed bonus can make a useless loop outscore the real goal.
- Start in Goal reward (delayed) mode and step Pip around the puddles with the direction buttons (or tab to the grid and use arrow keys) until you reach the seedling.
- Click Show Pip’s example run to see the 5-step safe path score 0 on steps 1–4 and +10 on step 5.
- Switch to Flawed tap bonus (+4) and click Show Pip’s example run to see Pip loop on the tap for +20 while leaving the seedling dry.
- Click Reset at any time to test your own route.
Illustrative simulation with invented tile scores and scripted example runs—not a live RL training engine. Pip starts carrying water; the Water Tap is optional.
Pip starts at the top-left corner carrying water. Choose a direction or show Pip’s example run.
Step-by-step reward trail
No moves yet. Take a step or click “Show Pip’s example run” to see how rewards arrive over time.
Where reinforcement learning fits—and its limits.
Reinforcement learning shines when you can let an agent practice many times—often inside a simulator—and score how well a sequence of decisions worked. Feedback-based reward training is also one of the techniques used alongside other methods when shaping modern AI assistants.
At the same time, RL has clear limits. Real-world trial and error can be slow or unsafe, delayed rewards can require many runs to connect late payoffs to earlier moves, and writing a reward rule that cannot be gamed is surprisingly hard. In the next lesson (4.7), you will see how search and planning explore routes using known rules instead of learning from reward scores.
- Does a negative reward mean the agent feels “punished”?
No. A negative number lowers the immediate score for that choice, though an agent can still take a short-term penalty if that move leads to a larger payoff later.
- Does adding more intermediate rewards guarantee better behavior?
No. Extra proxy bonuses can accidentally create loops or shortcuts that raise the score without accomplishing the real goal.
- How is reinforcement learning different from supervised learning?
Supervised learning provides target labels or values for each example upfront; reinforcement learning gives a feedback score—often delayed—after the agent takes actions in an environment.
Check your understanding.
Take this with you.
Rewards steer behavior, not truth. In reinforcement learning, an agent takes an action in an environment and gets back the next state and a reward. Payoffs are often delayed—and because an agent optimizes the score it is given, a high reward does not guarantee the behavior you actually wanted.
Ready to continue? Return to How Machines Learn.