◆ AI All-in-One

Level 3 In-Depth AI · Reinforcement Learning

Actor-Critic Methods

Combine a policy (the actor) with a learned value function (the critic). The critic tells the actor, after every step, whether things went better or worse than expected. Advantage, A2C and A3C, and generalised advantage estimation.

Level
●●●●● Advanced
Reading
14 min
To learn it well
1.5 hours to read, an afternoon to practise
↗ Plan a path here

Read first

Policy GradientsValue Functions and Bellman Equations

This leads to

Proximal Policy Optimization
The full path from zero — 18 concepts before this one
  1. What Is AI?
  2. Probability Basics
  3. Derivatives and Slopes
  4. Vectors
  5. How Machines Learn
  6. Partial Derivatives and Gradients
  7. Matrices and Matrix Multiplication
  8. Supervised, Unsupervised and Reinforcement Learning
  9. Gradient Descent
  10. Supervised Learning
  11. Reinforcement Learning: The Basics
  12. Linear Regression
  13. The Perceptron
  14. Markov Decision Processes
  15. Logistic Regression
  16. Value Functions and Bellman Equations
  17. Neural Networks
  18. Policy Gradients
  19. Actor-Critic Methods

Read them roughly in this order. See it on the concept map →

Why it matters

REINFORCE learns a policy directly, but it has two weaknesses. It must wait until an episode ends to compute each return, and that return is very noisy, so learning is slow and erratic. Value-based methods learn from every single step with low noise, but they struggle with continuous actions and can't represent random policies.

Actor-critic methods take the best of both. An actor (the policy) chooses actions. A critic (a value function) watches and, after every step, says whether the outcome was better or worse than expected. The actor follows a policy gradient, but it is weighted by the critic's low-noise judgment instead of a raw return.

Almost every modern deep-RL algorithm is an actor-critic: A2C and A3C, Proximal Policy Optimization (the workhorse behind RLHF and Preference Optimization), and SAC and TD3 for robotics. The critic idea also explains the "value model" that classic RLHF trains next to the language model. Once you understand this chapter, most RL papers become readable.

The intuition

Think of an apprentice chef (the actor) and an experienced taster (the critic). The apprentice cooks. The taster has eaten thousands of dishes and has a sense of how good a dish should be at each stage. After each step, the taster doesn't say "the final meal scored 7 out of 10". The taster says "that's better than I'd expect at this point" or "worse than I'd expect". The apprentice adjusts on the spot, without waiting for the meal to be finished.

Meanwhile the taster is learning too. Each time the actual outcome differs from the taster's expectation, the taster updates their sense of what to expect. The two improve together. The apprentice's cooking gets better, and the taster's judgments get more accurate. Each makes the other's job easier.

The key quantity is the surprise, the TD error from Q-Learning:

δt=Rt+1+γV(St+1)−V(St)\delta_t = R_{t+1} + \gamma V(S_{t+1}) - V(S_t)

"What actually happened (one real reward plus the critic's estimate of where I landed) minus what the critic expected." If δ>0\delta > 0, the action was better than expected, so make it more likely. If δ<0\delta < 0, make it less likely. And in both cases, move the critic's estimate towards what happened.

Actor policy πθ(a | s) decides what to do Critic value Vw(s) judges how good s is Environment returns r and s′ action a r, s′ next state s′ TD error δ δ = r + γV(s′) − V(s) "better or worse than expected?" δ trains the actor: a becomes more likely if δ > 0, less if δ < 0 δ trains the critic: V(s) ← V(s) + α δ
Fig. 1 The actor-critic loop. The actor picks actions. The environment returns a reward and the next state. The critic turns these into a TD error δ, the surprise. δ trains both: it tells the actor whether to make its action more or less likely, and it corrects the critic's own value estimate.

Key idea Actor-critic = policy gradient with the noisy return GtG_t replaced by the critic's advantage estimate, "how much better than expected was that?". The critic learns by TD, the actor by policy gradient, and they train together.

How it works

The advantage

Policy Gradients showed that subtracting a baseline b(s)b(s) from the return reduces noise without biasing the gradient, and that the ideal baseline is the state value vπ(s)v_\pi(s). What remains is the advantage:

Aπ(s,a)=qπ(s,a)−vπ(s)A_\pi(s, a) = q_\pi(s, a) - v_\pi(s)

It answers: how much better is action aa than the policy's average behaviour in state ss? A positive advantage means the action beats the policy's own average, so do it more. The policy gradient becomes

∇θJ(θ)=E[Aπ(St,At) ∇θlog⁡πθ(At∣St)]\nabla_\theta J(\theta) = \mathbb{E}\big[ A_\pi(S_t, A_t)\, \nabla_\theta \log \pi_\theta(A_t \mid S_t) \big]

We don't know AπA_\pi, but the TD error estimates it. Given St=sS_t = s and At=aA_t = a, the expected value of Rt+1+γvπ(St+1)R_{t+1} + \gamma v_\pi(S_{t+1}) is exactly qπ(s,a)q_\pi(s, a) (that is the Bellman equation). So the TD error δt\delta_t, computed with the true vπv_\pi, is an unbiased sample of the advantage. With a learned critic Vw≈vπV_w \approx v_\pi it is a slightly biased but far less noisy estimate. This is the central bargain of actor-critic: accept a little bias to remove a lot of variance.

One-step actor-critic

With actor parameters θ\theta and critic parameters ww (ww for "weights"; for a table, one number per state), after every step:

  1. Compute the TD error: δ=Rt+1+γVw(St+1)−Vw(St)\delta = R_{t+1} + \gamma V_w(S_{t+1}) - V_w(S_t). Use Vw=0V_w = 0 for a terminal St+1S_{t+1}.
  2. Update the critic towards the TD target: w←w+αw δ ∇wVw(St)w \leftarrow w + \alpha_w\, \delta\, \nabla_w V_w(S_t).
  3. Update the actor along the policy gradient: θ←θ+αθ δ ∇θlog⁡πθ(At∣St)\theta \leftarrow \theta + \alpha_\theta\, \delta\, \nabla_\theta \log \pi_\theta(A_t \mid S_t).

For a table, ∇wVw(St)\nabla_w V_w(S_t) is 1 for the entry of StS_t and 0 elsewhere, so step 2 is just the TD(0) rule from Q-Learning. For a softmax actor, ∇log⁡π\nabla \log \pi with respect to the logits is "one-hot of the action taken minus the probabilities" (Policy Gradients).

Worked example. The critic believes V(s)=0.50V(s) = 0.50. The agent takes "right" with probability 0.25 (all four actions equally likely), receives r=0r = 0, and lands in s′s' with V(s′)=0.70V(s') = 0.70. With γ=0.9\gamma = 0.9:

  • TD error: δ=0+0.9×0.70−0.50=+0.13\delta = 0 + 0.9 \times 0.70 - 0.50 = +0.13. Better than expected.
  • Critic, with αw=0.1\alpha_w = 0.1: V(s)←0.50+0.1×0.13=0.513V(s) \leftarrow 0.50 + 0.1 \times 0.13 = 0.513.
  • Actor, with αθ=0.1\alpha_\theta = 0.1: the logit gradient is (−0.25,−0.25,−0.25,+0.75)(-0.25, -0.25, -0.25, +0.75), so "right" gains 0.1×0.13×0.75≈0.010.1 \times 0.13 \times 0.75 \approx 0.01 in logit and the other three each lose about 0.003. "Right" becomes slightly more likely.

Deep actor-critic: A2C and A3C

With neural networks, actor and critic are usually one network with two heads: a shared body that reads the state, a policy head that outputs action logits, and a value head that outputs a single number V(s)V(s). The training loss combines three parts:

L=− A^tlog⁡πθ(At∣St)⏟actor  +  c1(V(St)−G^t)2⏟critic  −  c2H[πθ(⋅∣St)]⏟entropy bonusL = \underbrace{-\,\hat{A}_t \log \pi_\theta(A_t \mid S_t)}_{\text{actor}} \;+\; c_1 \underbrace{\big(V(S_t) - \hat{G}_t\big)^2}_{\text{critic}} \;-\; c_2 \underbrace{\mathcal{H}\big[\pi_\theta(\cdot \mid S_t)\big]}_{\text{entropy bonus}}

Here A^t\hat A_t is the advantage estimate, G^t\hat G_t is the critic's regression target (for example an nn-step return), and H\mathcal{H} is the entropy of the action distribution, a measure of how spread out it is (Entropy, Cross-Entropy and KL Divergence). Rewarding entropy stops the policy collapsing to a deterministic one too early. The constants c1c_1 (often 0.5) and c2c_2 (often 0.01) balance the terms.

Instead of one-step TD errors, these methods usually look a few real steps ahead. The n-step return adds nn actual rewards and then bootstraps:

Gt:t+n=Rt+1+γRt+2+⋯+γn−1Rt+n+γnV(St+n)G_{t:t+n} = R_{t+1} + \gamma R_{t+2} + \dots + \gamma^{n-1} R_{t+n} + \gamma^n V(S_{t+n})

A3C (Asynchronous Advantage Actor-Critic; Mnih et al., DeepMind, 2016) ran many copies of the agent in parallel on CPU threads. Each explored its own copy of the environment and sent gradient updates to a shared network. The parallel actors see different situations at the same moment, which decorrelates the data much as Deep Q-Networks's replay buffer does, but without storing anything. A2C is the synchronous version: wait for all the workers, then make one batched update. A2C turned out to be just as good and simpler to run on GPUs, so it became the standard.

Generalised advantage estimation

How far ahead should the advantage estimate look? One-step TD (n=1n = 1) has low variance but leans heavily on the critic, which may be wrong (bias). The full Monte Carlo return (n=∞n = \infty) is unbiased but noisy. Generalised advantage estimation (GAE) (Schulman et al., 2015) mixes all the nn-step estimates with exponentially decaying weights. Written in terms of TD errors, it is simply a discounted sum of future surprises:

A^tGAE(γ,λ)=∑k=0∞(γλ)k δt+k=δt+γλ δt+1+(γλ)2δt+2+…\hat{A}_t^{\text{GAE}(\gamma, \lambda)} = \sum_{k=0}^{\infty} (\gamma \lambda)^k\, \delta_{t+k} = \delta_t + \gamma\lambda\, \delta_{t+1} + (\gamma\lambda)^2 \delta_{t+2} + \dots

The new parameter λ\lambda (between 0 and 1) slides between the two extremes. λ=0\lambda = 0 gives the one-step TD error δt\delta_t. λ=1\lambda = 1 gives Gt−V(St)G_t - V(S_t), the Monte Carlo advantage. Values around λ=0.95\lambda = 0.95 work well in practice and are the default in most Proximal Policy Optimization code.

0 0.5 1 0 10 20 30 40 λ = 0 one-step TD error only λ = 0.5 λ = 0.9 λ = 0.95 (common default) λ = 1 full Monte Carlo return steps ahead, k weight (γλ)ᵏ given to the TD error k steps ahead γ = 0.99 · small λ: low variance, more bias · large λ: less bias, more variance
Fig. 2 How much weight GAE gives to the surprise k steps in the future, for γ = 0.99. With λ = 0 only the immediate TD error counts. With λ = 1 every future TD error counts almost fully, which adds up to the Monte Carlo return. λ = 0.95 looks a few dozen steps ahead.

Worked example (computed by the second code block below). A 4-step episode with rewards 0, 0, 0, 1, critic values 0.5, 0.6, 0.6, 0.7, and γ=0.9\gamma = 0.9. The first TD error is δ0=0+0.9×0.6−0.5=0.04\delta_0 = 0 + 0.9 \times 0.6 - 0.5 = 0.04. With λ=0\lambda = 0 the first step's advantage is just 0.04. With λ=1\lambda = 1 it is G0−V(S0)=0.93−0.5=0.229G_0 - V(S_0) = 0.9^3 - 0.5 = 0.229. With λ=0.95\lambda = 0.95 it is 0.198, in between and much closer to the Monte Carlo value, because the critic here underestimates the later states.

In code

A tabular one-step actor-critic on the icy gridworld from Value Functions and Bellman Equations. The actor is a table of softmax logits H, the critic a table of values V. Both learn from the same TD error, at every step.

import numpy as np

WALL, GOAL, PIT, START = (1, 1), (0, 3), (1, 3), (3, 0)
MOVES = [(-1, 0), (1, 0), (0, -1), (0, 1)]                  # up, down, left, right
SIDE = {0: (2, 3), 1: (2, 3), 2: (0, 1), 3: (0, 1)}         # sideways slips

def step(s, a, rng):                                        # the icy gridworld again
    x = rng.random()
    a = a if x < 0.8 else SIDE[a][0] if x < 0.9 else SIDE[a][1]
    r, c = s[0] + MOVES[a][0], s[1] + MOVES[a][1]
    if 0 <= r < 4 and 0 <= c < 4 and (r, c) != WALL: s = (r, c)
    return s, (1.0 if s == GOAL else -1.0 if s == PIT else 0.0), s in (GOAL, PIT)

rng = np.random.default_rng(0)
H = np.zeros((4, 4, 4))            # actor: action preferences (logits) per square
V = np.zeros((4, 4))               # critic: state-value estimate per square
alpha_actor, alpha_critic, gamma = 0.1, 0.1, 0.9
returns = []
for episode in range(1, 3001):
    s, G, disc, done = START, 0.0, 1.0, False
    while not done:
        pi = np.exp(H[s]) / np.exp(H[s]).sum()              # softmax policy
        a = rng.choice(4, p=pi)
        s2, r, done = step(s, a, rng)
        delta = r + (0 if done else gamma * V[s2]) - V[s]   # TD error = advantage estimate
        V[s] += alpha_critic * delta                        # critic: TD(0) update
        grad_log_pi = -pi; grad_log_pi[a] += 1              # d log π(a|s) / d logits
        H[s] += alpha_actor * delta * grad_log_pi           # actor: policy-gradient step
        G += disc * r; disc *= gamma; s = s2
    returns.append(G)
    if episode in (100, 500, 1000, 2000, 3000):
        print(f"episodes {episode-99:4d}-{episode:4d}: average return {np.mean(returns[-100:]):+.3f}")
print(f"critic's V(start) = {V[START]:.3f}   (optimal v*: 0.473)")
print("greedy actions:\n" + "\n".join(" ".join("■" if (r, c) in (WALL, GOAL, PIT) else "↑↓←→"[H[r, c].argmax()]
                                              for c in range(4)) for r in range(4)))

# episodes    1- 100: average return -0.014
# episodes  401- 500: average return +0.413
# episodes  901-1000: average return +0.439
# episodes 1901-2000: average return +0.465
# episodes 2901-3000: average return +0.464
# critic's V(start) = 0.489   (optimal v*: 0.473)
# greedy actions:
# → → → ■
# ↑ ■ ↑ ■
# ↑ ← ← ←
# ↑ ← ← ←

Compare this with Q-Learning on the same gridworld. The return climbs above 0.4 within 500 episodes, against several thousand for ε-greedy Q-learning, and settles near 0.465, close to the optimal 0.473. There is no ε here. The actor explores because its policy is random, and it becomes more decisive by itself as the logits grow. The critic's estimate of the start square, 0.489, is close to the true optimal value.

The greedy actions read off the actor match the optimal policy along the route it actually uses. In the rarely visited squares on the right of the bottom two rows they differ: the actor still prefers ←, including just below the pit, where value iteration chose ↓. The actor has had little reason to refine squares it almost never visits.

Here is GAE on a single short trajectory, with the same backward loop that Proximal Policy Optimization implementations use:

import numpy as np

def gae(rewards, values, last_value, gamma=0.99, lam=0.95):
    """Generalised advantage estimates for one trajectory (last_value = 0 if it ended)."""
    values = np.append(values, last_value)
    adv, running = np.zeros(len(rewards)), 0.0
    for t in reversed(range(len(rewards))):
        delta = rewards[t] + gamma * values[t + 1] - values[t]   # one-step TD error
        running = delta + gamma * lam * running                    # discounted sum of TD errors
        adv[t] = running
    return adv

rewards = np.array([0.0, 0.0, 0.0, 1.0])       # reward only at the end
values  = np.array([0.5, 0.6, 0.6, 0.7])       # the critic's current guesses V(S_t)
for lam in (0.0, 0.5, 0.95, 1.0):
    print(f"lambda = {lam:<4}  advantages: {np.round(gae(rewards, values, 0.0, gamma=0.9, lam=lam), 3)}")

# lambda = 0.0   advantages: [ 0.04 -0.06  0.03  0.3 ]
# lambda = 0.5   advantages: [0.046 0.014 0.165 0.3  ]
# lambda = 0.95  advantages: [0.198 0.185 0.287 0.3  ]
# lambda = 1.0   advantages: [0.229 0.21  0.3   0.3  ]

The loop runs backwards because each advantage is the current TD error plus γλ\gamma\lambda times the next step's advantage, the same recursive trick as Gt=Rt+1+γGt+1G_t = R_{t+1} + \gamma G_{t+1}.

The next step: A2C on a real environment

Stable-Baselines3 ships a tested A2C (shared actor-critic network, n-step returns, entropy bonus, parallel environments). This needs pip install gymnasium stable-baselines3, so it isn't run here:

import gymnasium as gym
from stable_baselines3 import A2C
from stable_baselines3.common.env_util import make_vec_env

env = make_vec_env("CartPole-v1", n_envs=8)          # 8 environments stepped in parallel
model = A2C("MlpPolicy", env, n_steps=5, gamma=0.99, gae_lambda=1.0,
            ent_coef=0.01, vf_coef=0.5, verbose=1)
model.learn(total_timesteps=200_000)

Common pitfalls

  • A bad critic misleads the actor. Early in training the critic is wrong, and its advantage estimates can push the actor the wrong way. Use a larger critic learning rate, or train the critic for a while first, and watch the critic's loss.
  • Gradients through the target. The critic's target R+γV(S′)R + \gamma V(S') must be treated as a constant. In PyTorch, detach it, or the critic learns to move its targets instead of its predictions.
  • Unscaled advantages. Advantages can vary by orders of magnitude between tasks. Normalising them per batch (subtract the mean, divide by the standard deviation) is a standard and very effective trick.
  • Imbalanced loss terms. If the value loss is much larger than the policy loss in a shared network, it dominates the shared layers. Tune c1c_1, or use separate networks.
  • Entropy collapse. If the policy's entropy drops to nearly zero early, exploration stops. Log the entropy, and raise c2c_2 if it falls too fast.

Watch out Actor-critic is still on-policy (except for the off-policy variants below). Data collected by an old version of the actor gives biased gradients for the new one. A3C's asynchronous workers are already slightly stale, and taking many gradient steps on one batch makes it worse. Controlling exactly that staleness is what Proximal Policy Optimization adds.

Variations

  • Proximal Policy Optimization: actor-critic with GAE, plus a clipped objective that allows several safe gradient epochs per batch of data. The most widely used deep-RL algorithm.
  • TRPO (Schulman et al., 2015): limits each policy update with a constraint on the KL divergence. PPO is its simpler successor.
  • DDPG and TD3 (2015, 2018): actor-critic for continuous actions with a deterministic actor and a Q-function critic, trained off-policy from a replay buffer like Deep Q-Networks.
  • SAC (Soft Actor-Critic; Haarnoja et al., 2018): off-policy, with entropy maximisation built into the objective. A standard choice for robot learning.
  • IMPALA (DeepMind, 2018): many actors feed one central learner, with an importance-weighting correction ("V-trace") for the lag between them.
  • Critics in planning: AlphaGo's value network is a critic for board positions (Monte Carlo Tree Search and AlphaGo), and Dreamer trains an actor-critic inside a learned world model (Model-Based RL and World Models).

A bit of history

Actor-critic is one of the oldest ideas in RL. In 1983, Andrew Barto, Richard Sutton and Charles Anderson balanced a pole on a cart with two neuron-like elements, an "associative search element" (the actor) and an "adaptive critic element". The pole-balancing benchmark itself is the CartPole of Deep Q-Networks. The idea had roots in Ian Witten's 1977 work and in theories of how the brain's dopamine signal reports prediction errors. That link, made explicit by Schultz, Dayan and Montague in 1997, is one of neuroscience's best-known connections to RL. Theoretical foundations came from Konda and Tsitsiklis (1999–2000) and the policy gradient theorem. The deep era began with A3C in 2016, which trained faster on a multi-core CPU than DQN did on a GPU. GAE (2015) and then Proximal Policy Optimization (2017) made actor-critic the default family for deep RL.

Try it

  1. Set alpha_critic = 0.0, so the critic stays at 0. The TD error is then just the reward, and the actor only learns on the final step of each episode. How much slower does learning become?
  2. Make the critic learn ten times faster than the actor (alpha_critic = 0.5, alpha_actor = 0.05) and the reverse. Which is more stable?
  3. In the GAE code, change the critic values to the true returns [0.729, 0.81, 0.9, 1.0]. What happens to the advantages for every λ, and why?

Hint for 3: with a perfect critic every TD error is zero in this deterministic episode.

Check your understanding

4 quick questions. Pick an answer to see whether you were right and why. Your best score is saved on this device.

  1. The critic says V(s) = 0.50. The agent gets reward 0 and lands in s′ with V(s′) = 0.70, γ = 0.9. What is the TD error, and what does the actor do?

  2. What is the central bargain of actor-critic compared with REINFORCE?

  3. In GAE, what happens when you set λ = 0 versus λ = 1?

  4. Training an actor-critic, you see the policy's entropy fall to nearly zero early on and learning stalls. What is the usual remedy?

Finished this chapter?

Learn more

Hand-picked courses, books, videos and tutorials for going deeper. See all resources →

Tutorial

Spinning Up in Deep RL

Joshua Achiam (OpenAI) · 2018 · Intermediate · Free

OpenAI's short, precise introduction to deep RL: key concepts and notation, the policy-gradient derivation, and clean reference implementations of VPG, PPO, DDPG, TD3 and SAC.

Article

Policy Gradient Algorithms

Lilian Weng · 2018 · Advanced · Free

The policy-gradient family in one place, from REINFORCE and actor-critic to A3C, TRPO, PPO and SAC, with consistent notation and derivations.

Course

Hugging Face Deep RL Course

Hugging Face · Intermediate · Free

A hands-on deep reinforcement learning course from Q-learning to PPO. You train agents in games.

Docs

Stable-Baselines3 documentation

Raffin et al. · Intermediate · Free

Reliable PyTorch implementations of PPO, A2C, DQN, SAC and more, with a one-line training API that works on any Gymnasium environment. The quickest way to train a real agent.

Facts checked as of 30 November 2026. Fast-moving details (products, prices, laws) change often. · Source: content/entries/rl/actor-critic.md