Skip to main content
L8.7

Reinforcement Learning: States, Actions, Rewards, and Policies

About 42 min

Goal

By the end of this lesson, you can explain the reinforcement-learning interaction loop using agent, environment, state or observation, action, reward, policy, return, and exploration versus exploitation.

Imagine a game in which you repeatedly choose between two buttons. After each choice, the game gives you a number. One button often gives a small reward. The other sometimes gives a larger reward but sometimes gives nothing.

You are not given the best action as a label for every round. You act, observe what happens, receive a reward, and use experience to improve future choices.

That repeated feedback loop is the core of reinforcement learning (RL).

The basic interaction loop​

The pieces are:

  • agent — the learner or decision-maker;
  • environment — the world the agent interacts with;
  • state/observation — information available before a decision;
  • action — a choice the agent makes;
  • reward — a feedback number after the action;
  • policy — the rule or model that chooses actions.

The loop repeats:

observe state
-> choose action from policy
-> environment changes
-> receive reward and next observation
-> repeat

In a simple bandit there may be no changing state; the important uncertainty is which action tends to produce better reward. In other tasks, the state changes after every action.

Reward is feedback, not a complete description of the world​

A reward tells the agent what the training process values numerically. It does not automatically capture everything we care about.

If a delivery robot receives +1 only for moving quickly, it may learn behavior that is fast but unsafe unless the reward or constraints represent safety too.

That distinction will matter again in RLHF: optimizing a measured reward does not prove truth, safety, or general quality.

Longer-term consequences need return​

Some actions produce a small immediate reward but a better future. RL therefore often reasons about return: accumulated reward over several steps, sometimes giving less weight to rewards far in the future.

For example, suppose three rewards are 1, 0, 5 and the discount factor is 0.9. A discounted return from the first step is:

1 + 0.9 × 0 + 0.9² × 5 = 5.05

The immediate reward was only 1, but the later reward still matters. You do not need the Bellman equation here. The intuitive question is enough: does this action only look good now, or does it lead to better outcomes over the rest of the interaction?

Exploration versus exploitation​

If the agent always chooses the action that currently looks best, it may never discover a better option. If it explores constantly, it may ignore useful knowledge it already has.

  • exploitation uses the best-known action;
  • exploration tries alternatives to gather information.

A practical policy often balances both.

One simple rule is ε-greedy: with probability ε, explore a random action; otherwise, choose the action with the highest current reward estimate. After each reward arrives, update the estimate from experience. This gives us a small but real learning loop rather than a prerecorded action sequence.

In this Lab, “explore” means sample randomly from all available actions. A random exploratory draw can still land on the action that currently looks best, so you may see a trace line such as explore safe. The exploration decision and the final action are related but not identical.

A note about the word “agent”: in this lesson, an RL agent is the decision-maker that learns from environment feedback. In Level 11, “LLM agent” will mean a software system that repeatedly observes state, chooses among allowed actions or tools, and decides whether to continue or stop. The loop idea is related, but an LLM agent does not automatically learn its model weights from every interaction.

Two major families you will hear about​

Two important names are:

  • Q-learning/value-based methods, which learn estimates of how good actions or states are;
  • policy-gradient methods, which directly adjust a parameterized policy toward actions associated with higher return.

These names locate later methods on the map. This lesson does not require implementing a full RL algorithm.

Predict

An agent always chooses the action with the highest reward estimate and never tries alternatives. Which side of the trade-off is it emphasizing?

Run the Browser Lab​

The Lab is a tiny two-action bandit with seeded stochastic rewards and an ε-greedy policy. The random seed keeps the run reproducible for debugging, while the reward process is still sampled rather than read from a fixed schedule. You can inspect the environment code and calculate its reward probabilities, but the learning agent does not read those probabilities; it only receives the rewards sampled after its actions.

This bandit does not model delayed state transitions, so the Lab reports total reward for the sampled rounds rather than introducing another discounted-return calculation. The discounted-return example above is the concept to use when later rewards depend on earlier actions and timing matters.

  1. Run the Lab unchanged. Follow the trace from explore/exploit decision → reward → estimate update.
  2. Find the first round where the policy explores the risky action. Notice how one sampled reward changes the risky action's estimated value and can influence later choices.
  3. In the visible call run_learning(rounds=12, epsilon=0.25, seed=2), change only epsilon to 0.0. The policy now exploits from the initial tie and never gathers evidence about risky. Explain why “never trying it” is different from proving it is worse.
  4. Restore epsilon=0.25, then change only seed=2 to seed=3. Compare how the different action and reward samples change the estimates and total reward without changing the learning rule. This seed is chosen so the short run still collects risky-action experience.
  5. Explain why one lucky risky reward can temporarily make an action look best, and why repeated experience is needed before treating that estimate as reliable.

The important distinction is now visible in code: a sequence is the trace that happened on one run; the policy is the ε-greedy rule that generated those choices from current estimates.

Loading lab…

Quick Check

1. What is a policy?
2. Why can return differ from immediate reward?
3. Why explore?

0 of 3 questions answered.

Explain it back​

Describe an agent interacting with an environment for three steps. Name the observation, action, reward, and policy at each step, then explain one reason an immediate reward could be misleading.

Check your explanation

A strong answer mentions:

  • Step 1: the two-button game has no changing state, so observation o1 only says a round is ready. The ε-greedy policy, which reads the agent's own reward estimates (not part of the observation), explores and presses the risky button (a1); reward r1 = 0.
  • Step 2: observation o2 carries the feedback from round 1, and the agent lowers its risky-button estimate. The policy exploits the safe button (a2); reward r2 = 1.
  • Step 3: observation o3 carries that feedback. The policy explores again and presses the risky button (a3); reward r3 = 5 raises the risky-button estimate for later rounds.
  • An immediate reward can mislead: with discount 0.9, return across these three steps is 0 + 0.9×1 + 0.9²×5 = 4.95, not just the first reward 0.

Key Takeaways

  • RL learns from repeated interaction rather than target labels for every decision.
  • A policy chooses actions; the environment returns observations and rewards.
  • Return captures longer-term consequences beyond the next reward.
  • Exploration gathers information; exploitation uses what is currently believed to work.
  • Reward is a training signal, not proof that every desired property is satisfied.

Next Lesson

Next, return to language-model preference pairs. Those comparisons will become the human feedback used by RLHF-style and DPO-style alignment methods.

References

Lesson actions

Completion is stored locally on this device.

View progress