A courier can take a nearby delivery for one point or spend a point getting to the depot for a larger delivery. Which job should it take? Reinforcement learning (RL) lets an agent learn a rule for choosing actions from the rewards it receives. The key is to compare the return over the whole trip, not just the first reward.
What does a reinforcement learning agent learn?
The agent is the decision maker. The environment responds to an action with a reward and a transition to the next state. A policy says which action to take in each state, or how likely each action is. The objective is to maximize expected return: the sum of rewards, sometimes discounted so later rewards count less. A reward can arrive at any step, not just at the end.
In supervised learning, a training example might label a delivery “late.” An RL agent instead chooses a job; its choice changes both the feedback it gets and the jobs it can take next. For a side-by-side comparison, see the guide to the branches of machine learning.
Try two trips from the same starting state
Use these three rules as the entire environment. Each episode starts at town with zero points. In town, local earns +1 and ends the trip; travel earns −1 and moves the courier to the depot. At the depot the only action, deliver, earns +4 and ends the trip. There is no next decision after the terminal state. Use points per completed trip, with no discount or extra time penalty.
During exploration, try each starting action once and record its observed return. Then use the action with the larger recorded return in town. Compare this learned policy with a baseline that always takes the local job. Both start in town, use the same rules and stop at the end of one trip. Here is the entire experiment in Python 3; no packages or random seed are needed.
def trip(first_action):
if first_action == "local":
return [1] # town -> end
if first_action == "travel":
return [-1, 4] # town -> depot -> end
raise ValueError(first_action)
observed = {}
for action in ("local", "travel"):
observed[action] = sum(trip(action))
choice = max(observed, key=observed.get)
print(choice, sum(trip(choice)), sum(trip("local")))Expected output: travel 3 1. The learned policy travels in town and delivers at the depot: −1 + 4 = 3. The baseline earns 1. The first step costs a point yet makes the four-point delivery possible. Connecting that later reward to the earlier choice is the credit assignment problem. Choosing local every time after one successful trip would exploit a known payoff without exploring the alternative.
When would the baseline win?
Change the depot payout from 4 to 1 and rerun the code. Traveling now earns 0, so the same learning rule picks local and ties the baseline at 1. If pickups sometimes fail, one trial per action no longer tells you the expected return. Train on repeated trips, then freeze both policies and evaluate on fresh trips drawn under the same conditions. Report the spread as well as the mean. If the real goal is points per hour rather than points per trip, record trip duration before deciding which policy is better.
This is a two-choice experiment, not evidence about real couriers, games, or trading. It needs neither deep learning nor a simulator beyond three fixed transitions. For other tasks, start with the guide to choosing a machine learning algorithm.
Sources and further reading
OpenAI’s Spinning Up: Key Concepts in RL defines policies, trajectories, and return. The Farama Foundation’s Gymnasium environment API shows how a program separates the next observation, reward, and end-of-episode signals. A task ending under its own rules is different from a run stopped at an external time limit.
Historical credit: the original article discussed DeepMind’s Atari work and included a video from Two Minute Papers. The courier example above is new and does not reproduce their footage.
As an Amazon Associate I earn from qualifying purchases. For a book-length treatment, see Richard S. Sutton and Andrew G. Barto’s Reinforcement Learning: An Introduction, second edition (hardcover), on Amazon US.



