The AI Handbook Open in the app →

Reinforcement Learning

Foundations · Intermediate · 5 min read

What is it?

Reinforcement learning trains an agent to make decisions by trial and error, rewarding good outcomes and penalizing bad ones until it learns a strategy.

Explain like I'm 5

It's how you train a dog with treats. Good move, treat; bad move, no treat. Over time the dog learns the moves that earn the most treats.

Why was it created?

Some problems have no labeled 'right answer' per step — only a goal and feedback over time. RL was developed to learn good behavior from rewards rather than labels.

Where is it used?

  • Game-playing AI
  • Robotics and control
  • Recommendation and bidding
  • Aligning LLMs (RLHF)

Why should developers care?

RL underlies game-playing breakthroughs, robotics, and the RLHF step that aligns chat models, so it's key to how AI learns to act.

How does it work?

An agent observes a state, takes an action, and receives a reward and a new state. It learns a policy — a mapping from states to actions — that maximizes total reward over time, balancing exploration (trying new things) with exploitation (using what works).

Real-world example

An AI learns to play a game by playing millions of rounds, gradually favoring moves that led to winning.

Common use cases

  • Sequential decision-making
  • Control and robotics
  • Optimization under feedback
  • Preference alignment (RLHF)

Advantages

  • Learns from goals, not labels
  • Handles sequential decisions
  • Can discover novel strategies
  • Adapts to feedback over time

Disadvantages

  • Sample-inefficient (needs many trials)
  • Reward design is hard and gameable
  • Training can be unstable
  • Hard to test safely in the real world

When should you use it?

When the task is sequential decision-making with a reward signal rather than labeled correct answers.

When should you avoid it?

When you have labeled data for direct prediction (use supervised learning) or can't define a safe, meaningful reward.

Alternatives

Supervised learningImitation learningClassical optimization/control

Related terms

Reinforcement Learning from Human FeedbackMachine LearningAI AgentTraining

Interview questions

Beginner

  • What does an RL agent learn from?
  • What is a reward in RL?

Intermediate

  • What is the exploration vs exploitation trade-off?
  • What is a policy?

Senior

  • Why is reward design so error-prone?
  • How does RLHF apply RL to language models?

Common misconceptions

  • "RL needs labeled answers" — it learns from rewards, not per-step labels.
  • "A reward function is easy to write" — poorly designed rewards get gamed in surprising ways.

Fun facts

  • RL agents mastered Go and Atari games at superhuman levels.
  • The RL in RLHF is what turns a base LLM into a preference-aligned assistant.

Timeline

  • 1980s-90s — Foundations of RL (Q-learning, policy methods)
  • 2015-2016 — Deep RL masters Atari and Go

Learning resources

Quick summary

Reinforcement learning trains an agent by trial and error using rewards, learning a policy that maximizes long-term payoff.

Cheat sheet

  • Learns from rewards, not labels
  • State → action → reward loop
  • Explore vs exploit
  • Powers game AI and RLHF

If you remember only one thing

Reinforcement learning teaches an agent to act by rewarding good outcomes over time, like training a dog with treats.

Further reading