AI Reinforcement Learning Basics

Reinforcement learning trains an agent to make good decisions through trial-and-error interaction with an environment, rather than from a labeled dataset.

A Different Way of Learning

In supervised learning, a model studies a dataset of examples that already come with correct answers attached, such as photos labeled 'cat' or 'dog'. Reinforcement learning (RL) works completely differently: there is no dataset of correct answers at all. Instead, a learner called an agent interacts with a world, tries actions, sees what happens, and gradually figures out through experience which actions tend to work out well and which don't. Nobody hands it the right answer in advance -- it has to discover good behavior by doing.

The Core Pieces

TermWhat It Means
AgentThe decision-maker being trained -- the thing choosing actions and trying to get better at it.
EnvironmentEverything the agent interacts with and that responds to its actions -- a game, a warehouse, a simulated market, a physical robot's surroundings.
StateA snapshot describing the current situation the agent finds itself in, such as its position, remaining resources, or what's visible around it.
ActionOne of the choices available to the agent at a given moment, such as moving forward, turning, or picking an item.
RewardA number the environment sends back after an action, signaling how good or bad that action turned out to be in that moment.
PolicyThe agent's strategy -- a rule (learned over time) that maps states to the action it thinks is best in that state.

Picture a delivery robot learning to navigate a warehouse. Its state is its current position, battery level, and what obstacles are nearby. Its available actions might be move forward, turn left, turn right, or stop. After each action, the environment (the warehouse) updates: the robot moves to a new position, which becomes its new state. If it reaches a shelf efficiently, it might get a positive reward; if it bumps into a shelf or wastes battery wandering in circles, it gets a negative reward, or none at all. Over thousands of attempts, the robot's policy shifts toward the routes and habits that earned the best rewards.

Example

# A simplified agent-environment loop
state = environment.reset()

for step in range(1000):
    action = agent.choose_action(state)          # decide what to do
    next_state, reward = environment.step(action) # world reacts
    agent.learn(state, action, reward, next_state) # update the policy
    state = next_state

The Goal: Maximizing Cumulative Reward

A common misconception is that the agent is just trying to grab the biggest reward at each single step. In reality, RL is built around cumulative reward -- the total reward collected over an entire sequence of actions, not just the next one. Sometimes the best long-term strategy involves accepting a smaller reward now, or even a small penalty, because it leads to a much larger payoff later. A chess-playing agent that sacrifices a piece to win the game two moves later is a good illustration: the immediate reward looks bad, but the cumulative outcome is excellent.

Note: Because there's no labeled 'correct action' for any given state, the agent has to generate its own experience through trial and error, try things that don't work, and use the rewards it receives as the only feedback signal guiding improvement. This is the key structural difference from supervised learning.

Where You'll See This in Practice

  • Game-playing agents that learn strategy purely by playing many matches against themselves or opponents.
  • Robotics, where a physical or simulated robot learns motor skills like walking or grasping through repeated attempts.
  • Resource management, such as an agent learning to allocate computing power or inventory to maximize long-term efficiency.
  • Recommendation systems that adjust what they show a user based on the long-term engagement that follows, not just a single click.
Note: When you're learning RL, keep asking 'what is the reward signal here, and is the agent optimizing for right now or for the long run?' Almost every confusing RL concept becomes clearer once you've pinned down those two things for the specific problem in front of you.