Reinforcement Learning / RL Core
The vocabulary of learning by trial and error.
Reviewed by Yuvaraj
Reinforcement learning (RL) studies how an agent learns to act by interacting with an environment and receiving numerical reward signals. Unlike supervised learning, no one hands the agent the correct answer for each situation, it must discover which behaviors pay off through trial, error, and delayed consequences. This lesson builds the vocabulary you will use for the rest of the course: the agent–environment loop, returns and discounting, the difference between episodic and continuing tasks, and why designing a good reward is one of the hardest parts of the whole enterprise.
Almost everything in RL is expressed with five interlocking ideas. Fix them firmly and the rest of the field reads easily.
| Term | What it is | Everyday analogy |
|---|---|---|
| Agent | The decision-maker being trained | A student learning to play chess |
| Environment | Everything the agent acts on and observes | The chessboard and opponent |
| State | A description of the current situation | The board position |
| Action | A choice the agent makes | Moving a piece |
Ask about this lesson, or about anything in AI. Answers cite the lessons they draw on.
Finished this lesson?
Mark it complete to earn XP, keep your streak, and schedule a review.
| Reward | A scalar feedback signal | +1 for a win, 0 otherwise |
The policy ties them together. A policy is the agent's behavior, a mapping from states to actions. It can be deterministic, , or stochastic, giving a probability distribution over actions:
Learning, in RL, means gradually improving so that the rewards it collects over time get larger.
RL is a loop, not a dataset. At each timestep the agent observes a state, picks an action, and the environment responds with a reward and a new state. That new state feeds the next decision, and the cycle repeats.
Formally this is a Markov Decision Process (MDP). The Markov property says the next state and reward depend only on the current state and action, not on the full history:
This is a modeling assumption, not a law of nature. When it seems violated (e.g. a single video frame cannot reveal velocity), the usual fix is to enrich the state, stack several frames, so that it becomes Markov.
The agent does not care about a single reward; it cares about the total reward it can accumulate. That total is the return . The naive version is a plain sum of future rewards:
For tasks that never end this sum can be infinite, and even for finite tasks we usually want to prefer reward sooner. Both problems are solved by discounting with a factor :
Each step into the future is worth a factor less. The discount factor has a clean interpretation:
Why discounting is more than a math trick
Discounting keeps infinite-horizon returns finite, biases the agent toward acting sooner, and encodes uncertainty about the future, a reward you might collect twenty steps from now is less certain than one you collect next. The geometric weights also give the return a finite "effective horizon" of roughly steps, so means the agent effectively plans about 100 steps ahead.
Suppose an agent receives rewards , , (a reward that only arrives after two "empty" steps), and . Then
The same reward one step earlier would be worth , and immediately would be worth . This is precisely how discounting nudges the agent to reach reward faster.
The distinction matters because it changes how you write the return and how you evaluate progress. Many practical setups also impose a time limit on an otherwise continuing task, turning it into an episodic one for convenience, but you must then be careful that hitting the time limit is treated as a "cutoff," not as a genuine terminal state.
The reward signal defines what you want, and the agent will relentlessly optimize exactly what you wrote, not what you meant. Two failure modes dominate practice.
Sparse rewards. If reward only arrives at the very end (win/lose, task complete), the agent gets almost no feedback along the way and can flail for a long time before stumbling onto any signal. Techniques like reward shaping, curricula, and exploration bonuses exist largely to combat sparsity.
Reward hacking / specification gaming. If the reward is a proxy for the true goal, the agent may maximize the proxy while defeating the intent. Classic examples: a boat-racing agent that farms a recurring bonus by driving in circles instead of finishing the race; a cleaning robot rewarded for "no visible mess" that learns to cover its sensors. This is a manifestation of Goodhart's law: when a measure becomes a target, it ceases to be a good measure.
For a curious beginner
A reward is like telling a very literal genie your wish. Say "make the room look clean" and it may shove everything under the rug. It did exactly what you said, not what you wanted.
How it is actually used
Prefer rewards tied to outcomes you actually care about, keep them as dense as you safely can, and instrument for gaming: log agent behavior, add penalty terms for obviously degenerate strategies, and iterate. Shaping rewards F(s,a,s') should ideally be potential-based, F = gamma * Phi(s') - Phi(s), which provably does not change the optimal policy.
The underlying mechanism
The agent maximizes under your reward function , not the intended objective . If and diverge anywhere the agent can reach, the optimum of may be terrible under . Potential-based shaping guarantees the reordering of policies is preserved, since the added telescoping term sums to a constant that is independent of the policy.
We now have the objective: find a policy that maximizes expected discounted return . The next question is how. Most methods either estimate how good states and actions are (value functions, next lesson) or adjust the policy directly (policy gradients, later). Both rest entirely on the loop and the return you just met.
Common mistakes