5.1.1 · D2Reinforcement Learning Foundations

Visual walkthrough — Agent, environment, state, action, reward

2,215 words10 min readBack to topic

This page builds ONE idea from nothing: why the agent chases the sum of future rewards, discounted, and why that sum is a finite, well-behaved number. We start with a single arrow of feedback and end with the recursive rule that seeds the Bellman Equations.

Everything here refines the loop from the parent note Agent, environment, state, action, reward. If a symbol appears, it was drawn first.


Step 1 — One tick of the clock: what actually happens

WHAT. At a single moment in time we have four things in a chain: the agent is in a situation, it makes a choice, the world changes, and a single number comes back.

WHY. Before summing anything, we must agree on what one reward even is and where it comes from. Everything later is just this one tick, repeated.

PICTURE. Look at the figure. The purple box is the agent (the chooser). The coral box is the environment (the world). The three labelled arrows are the entire transaction of one time step.

Figure — Agent, environment, state, action, reward

Read the arrows left to right: see → choose → receive and land in . That "" in just means "the next tick's state."


Step 2 — Chaining ticks into a trajectory

WHAT. We paste many single ticks end to end. The state a tick lands in becomes the state the next tick starts from.

WHY. A reward alone tells you this instant was good or bad. But learning to ride a bike is about a whole ride. To talk about "how good was the whole thing," we need the full chain.

PICTURE. Each grey capsule is one Step-1 tick. The mint arrow shows how of one capsule is the of the next — the ticks interlock like train cars.

Figure — Agent, environment, state, action, reward

The single number we care about — how good was the whole ride — must be built out of these . That's Step 3.


Step 3 — The naive answer: just add the rewards (finite horizon)

WHAT. If the ride ends — a game is won, a robot reaches the goal at some final tick — the honest "total goodness from now on" is simply the sum of the rewards left.

WHY. Nothing fancy is needed when there's a finish line. Every reward counts once, fully. We call this total the return.

PICTURE. Bars are individual rewards . Stacking them (mint total on the right) is the return . Notice the sum starts at the current tick , not at — we always ask "from here on."

Figure — Agent, environment, state, action, reward

Step 4 — The problem: what if the ride never ends?

WHAT. Many tasks have no finish line — a thermostat runs forever, a trading agent never "wins." Then and the naive sum can blow up to infinity.

WHY. If every future reward is, say, , then . Every policy would score "infinity," so we could never say one is better. A useless objective. We need a total that stays finite yet still prefers good behaviour.

PICTURE. Left panel: equal bars marching off to the right forever — the area (total) is unbounded, the number breaks. This is the wall we must get past.

Figure — Agent, environment, state, action, reward

Step 5 — The fix: discounting (why the exponential, not something else)

WHAT. Multiply each future reward by a shrinking weight before adding: the reward ticks away is worth only of its face value, where (the Greek letter gamma) is a number between and .

WHY this exact tool — the power , not a fixed cap or a linear fade? Three reasons stack up:

  1. It converges (Step 6 proves it) — the total stays finite.
  2. It's consistent across time. One tick of waiting always costs the same factor , no matter where you are in the ride. A linear fade like would treat tick 50 and tick 51 differently from tick 1 and tick 2, and would even go negative. Only the exponential has "each step of delay costs a fixed fraction" — the same reason compound interest uses powers.
  3. It's a dial. = only care about right now (myopic); = care about the far future (far-sighted).

PICTURE. The same infinite bars from Step 4, but now each is scaled by the mint curve . The far-off bars are crushed toward zero, so the shaded total is finite — a filled shape with a real area.

Figure — Agent, environment, state, action, reward

Step 6 — The edge case that must not break: does the sum stay finite?

WHAT. We prove that even with infinitely many terms, is a finite number — provided rewards don't themselves run to infinity.

WHY. Step 5 claimed convergence; a claim isn't a proof. We must guarantee the agent's objective is a real, comparable number in the worst case (every reward as large as allowed).

PICTURE. The bound in one image: replace every real reward with the largest possible one, (grey dashed ceiling). The discounted stack of these ceilings is the tallest the return could ever be — and even that stack is a finite geometric total (the mint area saturates to a line).

Figure — Agent, environment, state, action, reward

Now bound the return term by term:

  • First : the size of a sum is at most the sum of sizes (triangle inequality).
  • Second : swap each for its ceiling .

The leftover is a geometric series — each term is the previous times . Its closed form:

This is the degenerate boundary made explicit: ⇒ budget ⇒ return may diverge (back to Step 4's wall). ⇒ budget , pure greed. The safe operating range is .


Step 7 — The payoff: the return folds into itself

WHAT. Pull the very first reward out of the discounted sum. What remains is the same kind of return, one tick later, scaled by .

WHY. This turns an infinite sum into a tiny two-piece rule — "now's reward, plus a discounted copy of the future." It's the seed from which Policy and Value Functions and the Bellman Equations grow, and it's what lets algorithms bootstrap (estimate a value from a neighbouring value).

PICTURE. Split the stack: the bottom brick is at full height; the entire rest of the stack, lifted out and re-labelled, is — and it enters scaled by (mint bracket).

Figure — Agent, environment, state, action, reward

Every term inside the bracket had one factor of pulled out front, and the leftover is the definition of the return starting at .


The one-picture summary

Every idea on this page, in a single frame: one tick becomes a chain; the chain's rewards become a discounted stack; the stack is provably finite and folds into .

Figure — Agent, environment, state, action, reward
Recall Feynman retelling — say it like you'd explain to a friend

The world hands the agent one number at a time — a reward. Nobody cares about a single number; we care about the whole trip's worth, which is just all the future rewards added up. But if the trip never ends, "add them all" can be infinity, and infinity beats infinity, so nothing would ever look better than anything else. Fix: shrink each future reward by a fixed fraction per step of delay — the reward steps away is worth of itself. Distant rewards politely fade to nothing, and (because each is at most and the weights add to ) the grand total is always a finite number. The magic bonus: pull the first reward out and what's left is the very same total, one step later, so . That little loop is the whole engine of RL.

Recall Quick self-test

What is in words? ::: The discounted sum of all rewards from time onward — the total future goodness the agent tries to maximise. Why must (not )? ::: At the weight budget is infinite, so the sum can diverge; keeps finite. What does make the agent do? ::: Only care about the immediate reward — purely greedy/myopic. State the recursive return. ::: . What ceiling bounds the return? ::: .

Where this goes next: replace the actual rewards with their expected values under a strategy and becomes a value — the doorway to Policy and Value Functions, the Bellman Equations, and (once we ask how the agent gathers rewards it hasn't seen) Exploration vs Exploitation. When the state is only partly visible, see Partial Observability (POMDP); the fully-formalised loop is the Markov Decision Process (MDP).