2.4 Reinforcement Learning: Agents, Environments & Reward Optimization

Key Takeaways

  • Reinforcement learning optimizes sequential decision-making through trial-and-error interactions where an autonomous agent maximizes cumulative discounted rewards.
  • The Markov Decision Process (MDP) provides the mathematical formalization of RL, defined by States, Actions, Transition Probabilities, Rewards, and a Discount Factor.
  • The exploration versus exploitation dilemma balances discovering new environment dynamics against leveraging known high-reward actions, managed via epsilon-greedy policies.
  • Modern Generative AI relies heavily on Reinforcement Learning from Human Feedback (RLHF) to align foundational Large Language Models with human values and safety instructions.
  • Q-Learning updates an action-value table toward the Bellman optimal target, while Deep Q-Networks (DQNs) replace tabular representations with deep neural networks for continuous state spaces.
Last updated: September 2026

Reinforcement Learning: Agents, Environments & Reward Optimization

Exam Tip: On the OCI AI Foundations Associate (1Z0-1122-26) exam, understand the Agent-Environment loop, the role of the Discount Factor ($\gamma$) in balancing immediate versus long-term rewards, the Exploration vs. Exploitation dilemma, and how Reinforcement Learning from Human Feedback (RLHF) aligns Large Language Models (LLMs) with enterprise safety standards.


Defining Reinforcement Learning

Reinforcement Learning (RL) is the third primary machine learning paradigm, fundamentally distinct from both supervised and unsupervised learning:

  • In Supervised Learning, a model learns from a static dataset of inputs with explicit target answers provided by a teacher ($X \to Y$).
  • In Unsupervised Learning, an algorithm identifies latent structures and correlations in unlabeled data ($X$).
  • In Reinforcement Learning, there is neither labeled training data nor an explicit teacher. Instead, an autonomous agent learns optimal behaviors through active, sequential trial-and-error interactions with a dynamic environment. The agent receives feedback in the form of numerical rewards or penalties, learning to select actions that maximize long-term cumulative return.
Supervised:      Given (Features, Labels)    ──> Learn predictive mapping
Unsupervised:    Given (Features only)       ──> Discover hidden structure/clusters
Reinforcement:   Given (Agent, Environment)  ──> Learn policy via actions & rewards

The Mathematical Framework: Markov Decision Process (MDP)

Reinforcement learning problems are mathematically formalized as a Markov Decision Process (MDP). An MDP relies on the Markov Property, which states that the future state depends solely on the current state and action, and is conditionally independent of the historical sequence of prior states:

P(St+1=sSt=st,At=at,St1=st1,,S0=s0)=P(St+1=sSt=st,At=at)P(S_{t+1} = s' \mid S_t = s_t, A_t = a_t, S_{t-1} = s_{t-1}, \dots, S_0 = s_0) = P(S_{t+1} = s' \mid S_t = s_t, A_t = a_t)

An MDP is formally defined by a 5-tuple: $(S, A, P, R, \gamma)$:

  1. State ($S$, $s_t$): A comprehensive representation of the environment at time step $t$. States can be discrete (a square on a chessboard) or continuous (multivariate sensor readings of an autonomous vehicle's velocity, steering angle, and LIDAR distances).
  2. Action ($A$, $a_t$): The set of valid decisions or maneuvers available to the agent. Actions can be discrete (turn left, turn right, accelerate) or continuous (applying a specific torque value to a robotic limb).
  3. Transition Probability Function ($P(s_{t+1} \mid s_t, a_t)$): The conditional probability that taking action $a_t$ in state $s_t$ will transition the environment into state $s_{t+1}$.
  4. Reward Function ($R(s_t, a_t, s_{t+1})$): A scalar feedback signal ($r_t \in \mathbb{R}$) emitted by the environment quantifying the immediate benefit or penalty resulting from taking action $a_t$ from state $s_t$.
  5. Discount Factor ($\gamma$, Gamma): A configurable parameter bounded strictly between $0$ and $1$ ($0 \le \gamma < 1$) that determines the present value of future rewards:
    • When $\gamma \to 0$, the agent is myopic (short-sighted), prioritizing immediate instantaneous rewards over long-term outcomes.
    • When $\gamma \to 1$, the agent is far-sighted, placing high value on delayed rewards that may take dozens of sequential steps to achieve.

Cumulative Return & The Bellman Equation

The agent's goal is to maximize the expected discounted cumulative return ($G_t$):

Gt=rt+1+γrt+2+γ2rt+3+=k=0γkrt+k+1G_t = r_{t+1} + \gamma r_{t+2} + \gamma^2 r_{t+3} + \dots = \sum_{k=0}^{\infty} \gamma^k r_{t+k+1}

To make optimal sequential decisions, RL introduces two critical mathematical constructs:

  • Policy ($\pi$): The agent's operational strategy. A deterministic policy directly maps states to actions ($a = \pi(s)$), whereas a stochastic policy defines a probability distribution over actions given a state ($\pi(a \mid s) = P(A_t = a \mid S_t = s)$).
  • Value Function: The expected cumulative return an agent can achieve:
    • State-Value Function ($V^\pi(s)$): Expected return starting from state $s$ following policy $\pi$.
    • Action-Value Function ($Q^\pi(s, a)$): Expected return starting from state $s$, executing action $a$, and thereafter following policy $\pi$.

The foundation of RL algorithms is the recursive Bellman Equation, which decomposes the value of a state-action pair into the immediate reward plus the discounted expected value of the subsequent state:

Q(s,a)=R(s,a)+γsP(ss,a)maxaQ(s,a)Q^*(s, a) = R(s, a) + \gamma \sum_{s'} P(s' \mid s, a) \max_{a'} Q^*(s', a')


The Fundamental Tradeoff: Exploration vs. Exploitation

Because the agent learns entirely through direct environmental interaction, it faces the Exploration vs. Exploitation dilemma:

  • Exploration: Gathering novel information about the environment by executing unfamiliar, non-greedy actions. Exploration enables the agent to discover superior long-term reward paths that are not immediately obvious.
  • Exploitation: Maximizing immediate cumulative payoff by selecting the best-known action based on existing value estimates ($a^* = \arg\max_a Q(s, a)$).

If an agent solely exploits, it risks becoming trapped in suboptimal local optima. If it solely explores, it fails to capitalize on learned knowledge and achieves poor cumulative rewards.

The $\epsilon$-Greedy (Epsilon-Greedy) Strategy

The standard operational mechanism to manage this tradeoff is the $\epsilon$-greedy strategy:

  • With probability $1 - \epsilon$, the agent exploits its current knowledge by choosing the action with the highest estimated value: $a = \arg\max_a Q(s, a)$.
  • With probability $\epsilon$, the agent explores by selecting an action uniformly at random from the action space.
  • $\epsilon$-Decay: During initial training, $\epsilon$ is set high (e.g., $1.0$), forcing extensive exploration when environmental knowledge is minimal. Over time, $\epsilon$ decays toward a small terminal value (e.g., $0.05$), shifting the agent progressively from exploration to exploitation as confidence in its policy matures.

Key RL Approaches: Value-Based, Policy-Based & Actor-Critic

Reinforcement learning algorithms fall into distinct architectural families:

1. Value-Based Methods (Q-Learning & DQN)

Value-based methods learn the optimal value function $Q^*(s, a)$ and derive an implicit policy by choosing actions that maximize value.

  • Q-Learning: A model-free, off-policy temporal difference algorithm that maintains a lookup table (Q-table) of values for every state-action pair. Q-values are updated iteratively using the Bellman optimality equation. Q-learning works effectively for small, discrete state spaces but fails in high-dimensional or continuous environments.
  • Deep Q-Networks (DQN): Replaces the discrete Q-table with a Deep Neural Network that approximates $Q(s, a; \theta)$. Breakthroughs that stabilized DQN include:
    • Experience Replay: Storing transition tuples $(s_t, a_t, r_t, s_{t+1})$ in a large circular memory buffer and sampling random mini-batches for training, breaking temporal correlations between sequential steps.
    • Target Networks: Utilizing a separate, periodically updated neural network to compute target Bellman values, preventing mathematical divergence during gradient descent.

2. Policy-Based Methods (Policy Gradients)

Policy-based algorithms bypass the value function entirely, parameterizing the policy directly as $\pi_\theta(a \mid s)$ and updating weights via gradient ascent on expected return: θJ(θ)=Eπθ[θlogπθ(as)Gt]\nabla_\theta J(\theta) = \mathbb{E}_{\pi_\theta} [\nabla_\theta \log \pi_\theta(a \mid s) G_t] Algorithms like REINFORCE natively handle continuous, high-dimensional action spaces (such as robotic joint articulation) where finding $\arg\max_a Q(s, a)$ at every step is computationally intractable.

3. Actor-Critic Architectures

Actor-Critic models synthesize value-based and policy-based methods by splitting learning across two cooperative neural components:

  • The Actor: Parameterizes and updates the policy $\pi_\theta(a \mid s)$, selecting actions in response to environment states.
  • The Critic: Estimates the value function $V_w(s)$, evaluating the quality of the action selected by the actor. The critic calculates the Advantage signal ($A(s, a) = Q(s, a) - V(s)$), directing the actor to increase the probability of actions that outperform expectations.
  • Prominent algorithms include Advantage Actor-Critic (A2C) and Proximal Policy Optimization (PPO).

Reinforcement Learning in Modern AI: RLHF & Enterprise Applications

While classical RL addressed gaming environments (chess, Go, Atari) and robotics, its most significant contemporary enterprise application is in Generative AI and Large Language Models (LLMs).

Reinforcement Learning from Human Feedback (RLHF)

Base foundation LLMs trained strictly on next-token prediction frequently generate text that is factually inaccurate, unhelpful, biased, or toxic. Reinforcement Learning from Human Feedback (RLHF) aligns foundational LLMs with human values (helpfulness, honesty, and harmlessness).

[Pre-trained Base LLM] ──> [Supervised Fine-Tuning (SFT)]
                                      │
                                      ▼
[Human Annotator Comparisons] ──> [Train Reward Model]
                                      │
                                      ▼
               [PPO Policy Optimization with KL Penalty] ──> [Aligned Enterprise LLM]

The Three-Stage RLHF Pipeline:

  1. Supervised Fine-Tuning (SFT): Professional annotators create high-quality prompt-response demonstration pairs to train the base model on conversational conventions.
  2. Reward Model Training: Human evaluators review multiple candidate responses generated by the SFT model for a prompt and rank them from best to worst. A separate neural Reward Model is trained on these pairwise comparisons to output a scalar reward score reflecting human preference.
  3. Reinforcement Learning Optimization via PPO: The fine-tuned LLM acts as the RL Agent, the context prompt acts as the State, the generated token sequence acts as the Action, and the Reward Model provides the scalar Reward. Using Proximal Policy Optimization (PPO), the model updates its weights to maximize reward scores. A Kullback-Leibler (KL) divergence penalty is applied to prevent the model from drifting too far from the original base distribution ("reward hacking").

Industrial & Cloud Use Cases

Beyond LLM alignment, enterprise RL implementations include:

  • Autonomous Vehicles & Robotics: Dynamic path planning, sensor-guided navigation, and warehouse logistics.
  • Data Center Energy Management: Optimizing cooling chilling plants dynamically based on server workload and weather forecasts (achieving up to 40% reductions in cooling energy).
  • Supply Chain & Inventory Optimization: Setting dynamic reorder points and automated inventory replenishment across distributed global fulfillment networks.
Loading diagram...
The Reinforcement Learning Agent-Environment Loop
Test Your Knowledge

In a Markov Decision Process (MDP), what role does the Discount Factor (gamma) serve in the agent's mathematical objective?

A
B
C
D
Test Your Knowledge

An autonomous mobile robot exploring a warehouse facility implements an epsilon-greedy action selection strategy. If epsilon is configured to 0.15, how will the robot choose its next steering action?

A
B
C
D
Test Your Knowledge

How is Reinforcement Learning from Human Feedback (RLHF) utilized in modern Generative AI foundation models?

A
B
C
D