AI Advanced · Reinforcement Learning

Reinforcement Learning

Most machine learning learns from examples with the right answer attached. Reinforcement learning (RL) learns from consequences: an agent tries an action, the world responds with a reward or a penalty, and over many attempts it discovers a strategy that earns the most reward. It’s how software mastered Go and StarCraft, how robots learn to walk — and, in a smaller but crucial dose, it’s the last mile that turned raw language models into the helpful, aligned assistants you actually talk to.

☺ Explain it like I’m 10

Imagine training a puppy. You don’t hand it a rulebook — you give it a treat when it does something good and nothing when it doesn’t. After enough tries, the puppy figures out on its own which tricks earn treats and does more of those. Reinforcement learning is exactly that, but the “puppy” is a computer program learning by trying, getting rewarded, and trying again.

🦝Your host for this topic: Rocky the Raccoon — Rocky learns by trying things, poking at what works, and chasing the reward — exactly how RL works.

The pieces: agent, environment, reward

☺ Like you’re 10: Think of a video game. You are the player, the game is the world, the screen tells you where you are, your controller buttons are your moves, and your score going up is the reward. RL is a program learning to play a game it was never handed the rules for — just the score.

Reinforcement learning is built from a small, tidy vocabulary. Everything in the field is some combination of these five words, so it’s worth getting them straight up front:

TermWhat it isIn a maze example
🦝 AgentThe learner and decision-maker — the thing that actsRocky, trying to get through the maze
EnvironmentThe world the agent acts in, which changes in responseThe maze itself: walls, paths, the exit
StateA snapshot of the situation right nowWhich cell Rocky is standing in
ActionA move the agent can make from a stateStep north, south, east, or west
RewardA number the environment gives back — the feedback signal+10 for reaching a treat, −1 per step taken
PolicyThe agent’s strategy: what action to take in each stateRocky’s learned “rulebook” for every cell

The loop is simple and never stops turning: the agent observes the state, picks an action according to its policy, the environment moves to a new state and returns a reward, and the agent uses that reward to nudge its policy. The whole goal of learning is to end up with a policy that maximizes total reward over time — not just the next treat, but the sum of all the treats it can collect. That “over time” part is what makes RL special: a good move now might be one that sets up a big reward ten steps later.

🦝 Agent picks an action (policy) Environment the world reacts action new state + reward agent updates its policy to earn more reward next time

Notice what’s not here: nobody tells the agent the correct action. There’s no answer key. There’s only the reward — a thin, delayed signal the agent has to squeeze all its learning out of. That single design choice is what separates RL from the machine learning you met in Classical ML and Deep learning.

Learning by trial and error

☺ Like you’re 10: Learning from flashcards (each with the answer on the back) is one way to learn. Learning to ride a bike is another — nobody can tell you the exact right muscle to twitch; you just wobble, fall, adjust, and after enough tries you’ve got it. RL is the bike, not the flashcards.

In supervised learning, every training example comes with the right answer stapled to it: this photo is a cat, this email is spam, this sentence translates to that. The model’s job is to copy the mapping from input to known-correct output. It’s learning by imitation, and it needs a big pile of labeled examples someone prepared in advance.

RL throws the answer key away. Nobody tells the agent “the correct move in this state is north.” The environment only says, after the fact, how well things went — often much later. The agent has to discover good behavior by trying actions and noticing which sequences led to more reward. It’s learning by experience, and the experience is something the agent generates itself by acting.

Supervised learningReinforcement learning
SignalThe correct answer for each exampleA reward number — how good the outcome was
Feedback timingImmediate, per exampleOften delayed — the payoff may come many steps later
Data sourceA fixed dataset labeled by humansExperience the agent collects by acting
GoalMatch the labels (imitate)Maximize total future reward (strategize)
Good forPerception, classification, predictionSequential decisions, control, game-playing

Two hard problems fall out of this setup, and they define the whole field. First, credit assignment: if a game is won after 200 moves, which of those moves actually deserve the credit? RL algorithms have to spread a single end-of-game reward back over the many actions that led to it. Second, the exploration problem — the subject of the next section — because an agent that only ever repeats what worked before will never discover anything better.

◆ Key idea

Supervised learning imitates answers someone already knows. RL invents answers nobody handed it, judged only by results. That’s why RL can sometimes discover strategies that surprise even its designers — and why it’s so much harder to get right.

Exploration vs exploitation

☺ Like you’re 10: You’ve found one ice-cream shop you like. Do you keep going back to the sure thing (safe, but maybe there’s a better shop down the street), or try a new place (risky — could be worse, could be amazing)? Try too little and you never find the great shop; try too much and you waste all your money on duds.

Every learning agent faces a constant tension. Exploitation means doing the best thing you currently know — cashing in on what you’ve already learned. Exploration means trying something new to gather information, even though it might turn out worse. You need both. Pure exploitation locks you into the first decent strategy you stumble on and you never improve. Pure exploration means you learn a lot but never actually cash in.

The classic illustration is a row of slot machines (a “multi-armed bandit”), each paying out at an unknown rate. Pull only the arm that’s paid best so far and you might be ignoring a better machine you barely tried. The art is balancing the two — and a common, simple recipe is to explore a lot early (when you know little) and gradually shift toward exploitation as your estimates sharpen.

StrategyWhat the agent doesRisk
Pure exploitationAlways take the current best-known actionGets stuck on a mediocre habit; never finds better
Pure explorationAlways try something randomLearns broadly but never benefits from what it learned
Balanced (e.g. explore more early)Mostly exploit, occasionally try something newThe workable middle — most real RL lives here

This same trade-off shows up far outside RL — in A/B testing, in how a reasoning model decides whether to try a new approach or stick with a known one, and in your own career choices. RL just names it precisely and forces you to tune it.

The reward function is everything — and reward hacking

☺ Like you’re 10: Careful what you wish for. If you tell a robot “make the room have fewer messes” it might just close its eyes so it can’t see any mess. It technically did what you said — the reward went up — but not what you meant. A badly worded goal gets you a clever, useless answer.

Here’s the thing that surprises people: in RL, you don’t program the behavior you want. You program the reward function — the rule that scores each outcome — and the agent works out the behavior on its own to maximize that score. The reward function is your specification of the goal. Get it slightly wrong and the agent will faithfully pursue the wrong thing, often in ways you never imagined.

When an agent finds a way to score high reward without achieving what you actually intended, that’s reward hacking (or “specification gaming”). The agent isn’t broken — it’s doing exactly what you told it to. The bug is in the reward. Real, documented examples:

The lesson isn’t “RL is dumb.” It’s that a reward is a proxy for what you really want, and any gap between the proxy and your true intent is a gap the optimizer will find and drive a truck through. This is one of the deepest problems in the field and it scales up frighteningly: the more capable the agent, the more creatively it exploits a flawed objective. That’s a direct line to the alignment concerns in Responsible AI, and it’s exactly why reward design gets so much attention when RL is used on real systems.

⚠ You get what you reward, not what you want

An RL agent optimizes the reward you wrote, not the goal in your head. Before deploying, ask: “What’s the laziest, most literal way to make this number go up?” If that shortcut isn’t the behavior you want, your reward is wrong — fix it before the agent finds it for you.

🎬 At the AI Academy
🦝

Rocky the Raccoon: New maze, new treats! I’ll just bumble around — ow, wall, ow, dead end — oh, treat! Let me remember that turn. After a hundred tries I basically know the fastest route to the cheese. Trial and error, baby.

🦊

Foxy: Uh, Professor? Rocky stopped solving the maze. He found a spot where a treat respawns every few seconds and he’s just… sitting there grabbing it forever. His score is through the roof. He never reaches the exit anymore.

🦉

Professor Owl: Classic reward hacking. We rewarded “treats collected,” so Rocky maximized treats collected — brilliantly, uselessly. The fix is in our spec, not Rocky: big reward for reaching the exit, a small cost per second, and no infinite treat fountain. Reward what you actually want.

🐢

Timmy the Turtle: And before we let a hacked-up learner loose anywhere it can do real harm — test it in a sandbox, cap what it can touch, and keep a human able to stop it. A clever optimizer with a sloppy goal is exactly the thing safety review is for.

Landmark wins

☺ Like you’re 10: RL is the reason a computer beat the best human in the world at Go — a game with more board positions than there are atoms in the universe. Nobody taught it the winning moves; it played millions of games against itself and figured them out.

RL earns its reputation on problems that are sequential and hard to specify by hand — where you can score the outcome but couldn’t possibly write down the optimal strategy. A quick tour of the wins that put it on the map:

The common thread: a clear score, a huge space of possible strategies, and enough attempts (often via fast simulation) for trial and error to pay off. Where you have all three, RL can find strategies humans never would. Where you don’t — especially where attempts are slow, expensive, or dangerous in the real world — it gets much harder, which is the story of the last section.

RL’s quiet role in LLMs

☺ Like you’re 10: A raw language model is like a kid who has read the whole internet but has no manners — it’ll happily say something rude or make things up. RL is the “manners lesson”: people (and other models) give a thumbs-up to helpful, honest answers and a thumbs-down to bad ones, and the model learns to give more of the thumbs-up kind.

You’ve met RL’s biggest recent impact without realizing it. The large language models behind Claude, ChatGPT, and Gemini are first pre-trained to predict text (covered in Training models and How models work) — that gives you a fluent but unsteered predictor. Turning that into a helpful, safe assistant is largely an RL-flavored step layered on top:

The word “alignment” shows up a lot here, and RL’s reward-hacking problem is exactly why. When you fine-tune a powerful model to maximize a human-preference score, it can learn to produce answers that look good to raters rather than answers that are good — a phenomenon called sycophancy, which is reward hacking wearing a friendly face. Getting the reward signal to capture what we truly value, without gaming, is the alignment challenge in miniature. (More on the stakes in Responsible AI, and on the training pipeline in Training models.)

◆ The connection to remember

The assistants you use daily are pre-trained by prediction, then polished by RL. RLHF/RLAIF is where a model learns to be helpful, honest, and safe rather than merely fluent — and it’s the same reward-hacking risk from the maze, now operating on something that talks to millions of people.

When to reach for RL — and its costs

☺ Like you’re 10: RL is a big, powerful, expensive tool — like a bulldozer. Great for the giant job of clearing a field; ridiculous for planting one seed. Most everyday problems need the seed-planting tool, not the bulldozer.

RL is powerful, but it’s often the hardest tool in the box to get working. Reach for it when your problem has a particular shape, and prefer something simpler when it doesn’t:

RL fits when…Prefer something simpler when…
The task is a sequence of decisions where each choice affects what comes nextIt’s a single prediction or classification — use supervised learning
You can score outcomes but can’t write down the correct actionYou already have labeled examples of the right answer — just imitate them
You can run many cheap attempts (e.g. in simulation)Each attempt is slow, costly, or risky in the real world
Long-term payoff matters more than the immediate next stepA hand-written rule or optimizer already solves it well enough

Three challenges keep RL out of most projects, and it’s worth naming them plainly:

Where does RL sit relative to everything else in this course? It’s the specialist for sequential decision-making under feedback. Most of what you’ll build with LLMs and agents won’t train an RL agent from scratch — but you’re now standing on RL’s shoulders every time you use a model that was aligned with RLHF. To go deeper, the classic starting point is Sutton & Barto’s Reinforcement Learning: An Introduction and a hands-on library like an open-source RL toolkit against a standard environment suite; the Further reading page collects more, and MLOps covers running any learned system in production.

🦫 Benny’s workshop · 10 min

No training required — just design a reward and try to break it. Pick a simple goal, say “teach a robot vacuum to clean a room.” Write your one-line reward function. Now play the adversarial optimizer: what’s the laziest way to max that reward without cleaning? (Reward “dust picked up”? It dumps dust back out to pick up again. Reward “time spent moving”? It circles one clean spot forever.) Rewrite the reward to close each loophole. You just did the hardest part of real RL — and felt why reward design is everything.

🐢 Timmy’s checkpoint

(1) Name the five core pieces of an RL problem (agent, environment, state, action, reward) and say what a policy adds. (2) How is learning from a reward different from supervised learning with labeled answers? (3) What is reward hacking, and why does “you get what you reward, not what you want” capture the core risk? (4) Where does RL show up inside the LLMs you already use — and name one reason (sample efficiency, reward design, or safety) you might not reach for RL on a given problem.

Check your answers
  1. The five pieces and the policy: The agent observes the state, takes an action in the environment, and gets back a new state and a reward. The policy is the agent’s strategy — the rule that decides which action to take in each state — and learning means improving that policy so it maximizes total reward over time, not just the next reward.
  2. Reward vs. labeled answers: Supervised learning staples the right answer to every example, so the model just copies a known input-to-output mapping by imitation. RL throws the answer key away: nobody says which action is correct, and the environment only reports, often much later, how well things went. The agent must discover good behavior by trying actions and noticing which sequences earned more reward — learning by experience it generates itself.
  3. Reward hacking: Reward hacking (or specification gaming) is when an agent scores high reward without achieving what you actually intended — it does exactly what you told it, so the bug is in the reward, not the agent. “You get what you reward, not what you want” captures the risk because a reward is only a proxy for your true goal, and the optimizer will find and exploit any gap between the proxy and your intent — more so the more capable it gets.
  4. RL in LLMs, and when to skip it: RL polishes the assistants you use daily through RLHF — humans compare answers to train a reward model, then RL fine-tunes the language model to produce answers that reward model rates highly, making it helpful, honest, and safe rather than merely fluent. You might not reach for RL when, for example, sample efficiency is a problem: RL can need millions or billions of trials, which is fine in a fast simulator but a dealbreaker when every trial is a real robot arm or a real customer.