1 · Agent, environment, reward
Reinforcement learning is the third pillar: an agent learns to ACT by trial and error, guided only by a reward signal. Meet the loop that defines the whole field.
RL is learning by interaction: an agent observes a state, takes an action, and receives a reward + a new state from the environment — repeating to maximise total reward over time. No labelled examples, just a reward signal.
Without this:
Without the agent-environment-reward frame, RL looks like a grab-bag of algorithms. With it, every method (Q-learning, policy gradients, DQN) is just a different way to turn experience in this loop into better actions.
Supervised learning learns from labelled examples; unsupervised learning finds structure in unlabelled data. Reinforcement learning (RL) is the third pillar, and it learns something different: how to act. There are no correct-answer labels — only a reward signal that says how good things are going.
The entire field is built on one loop between two parties:
- The agent — the learner/decision-maker (the thing we train).
- The environment — everything outside the agent (the world, a game, a market).
At each timestep t:
- The agent sees a state
s_t(what the environment looks like now). - The agent picks an action
a_t. - The environment responds with a reward
r_{t+1}(a number) and the next states_{t+1}.
The agent's goal is to choose actions that maximise the total reward accumulated over time — not just the immediate reward. That distinction (caring about the future) is what makes RL hard and interesting: an action that looks bad now (sacrificing a piece in chess) can lead to far more reward later.
Below is the loop in code, with a trivial environment and a random agent. Everything in this track is about making that agent smart instead of random — but the loop never changes.
Python (in browser)
The agent-environment-reward loop: state → action → (reward, next state), repeated. An 'environment' is just a step() function.
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
What fundamentally distinguishes reinforcement learning from supervised learning?
- RL = learning to act by interaction: state → action → reward + next state, repeated to maximise total reward.
- An environment is concretely a step(state, action) → (next_state, reward, done) function; the agent is a policy mapping states to actions.
- The agent maximises long-term (future) reward, not just the immediate reward — that's what makes RL distinctive.
Game-playing agents (AlphaGo), robotics, recommendation, and RLHF — the 'reinforcement' in instruction-tuned LLMs — are all this loop.
If you remove it: Without the interaction-and-reward frame you can't model sequential decision problems where actions change future states.