Agents optimise exactly what you reward. Watch one exploit a loophole, teach a reward model from your own preferences, and see how a KL leash limits over-optimisation.
An agent optimises exactly the reward it is given — not the one you meant. Writing a good reward down is hard, so modern systems learn one from human judgements instead, and must then take care not to optimise the learned reward too hard.
Press Play and let the boat learn to race for the lap prize. Then pick “Add bonus targets” while it trains and watch the orange curve climb as the laps fall to zero.
The boat always sails the learner’s current greedy policy; training runs in the background with ε = 0.7, random starting positions and a backward replay of each episode (Q-learning is off-policy, so the exploration does not change what it learns). Checkpoints 1 → 2 → 3 must be passed in order before the finish counts. Green rings are bonus targets; a dashed ring is waiting to respawn. The chart scores one greedy 200-step race every 10 episodes: orange is the reward the agent optimises, white dashed is laps finished. Dotted lines mark changes to the reward.
In 2016 Jack Clark and Dario Amodei of OpenAI described an agent trained on the boat-racing game CoastRunners in a post called “Faulty reward functions in the wild”. The agent was rewarded for the in-game score, which players earn by hitting targets laid out along the route rather than by finishing. It found an isolated lagoon where it could turn in a large circle and keep hitting three targets as they respawned, catching fire, crashing into other boats and going the wrong way on the track, and it scored more than human players without ever finishing the race. The demo above is a small reconstruction of that idea, not the original game: a 28-cell loop, a lagoon with three targets and a tabular learner.
The learner here is not making a mistake. Its state is the boat’s cell, the next checkpoint and which targets are present, so the course is a finite MDP, and the tests compute the exact optimal policy by value iteration for each preset. With a bonus of 4 and respawning targets, the optimal policy for the designer’s reward really does circle the lagoon and never finishes; with the intended reward, or without respawn, or with a much bigger lap prize, it races. Q-learning finds the same behaviour. The bug is in the reward. Notice also what happens when the reward changes mid-training: the agent first races, and only later discovers the loophole — the learning curve of the proxy rising while the intended objective collapses.
Victoria Krakovna and colleagues at DeepMind collected dozens of such cases in a 2020 post, “Specification gaming: the flip side of AI ingenuity”, and keep a public list. The recurring pattern is that a reward is a proxy for what the designer wants, and a capable optimiser finds where the two come apart. Economists know this as Goodhart’s law, after Charles Goodhart, who observed in 1975 that a statistical regularity tends to collapse once pressure is placed on it for control purposes. The popular phrasing, “when a measure becomes a target, it ceases to be a good measure”, is the anthropologist Marilyn Strathern’s, from 1997.
Decide what kind of walk you like and click A or B each round; the heatmap and the orange walk update after every answer. Or let the simulated human answer, and compare active queries with random ones.
Each walk moves one column right per step and at most one row up or down. The reward is linear in five features, r(s) = wᵀφ(s), and the model is Bradley–Terry: P(A ≻ B) = σ(R(A) − R(B)) with R summed along the walk. After each answer the weights take 288 gradient-descent steps on the logistic loss over every comparison so far (“can’t tell” counts as ½). Active queries ask, out of 150 random pairs, the one the model is least sure about because it does not yet know w. The heatmap is rose for negative reward and green for positive.
People find it much easier to say which of two behaviours they prefer than to write down a reward. The Bradley–Terry model (Ralph Bradley and Milton Terry, 1952, originally for ranking from paired comparisons) turns comparisons into a score: each option has a strength R, and P(A ≻ B) = σ(R(A) − R(B)) = 1 / (1 + e^−(R(A) − R(B))). If R(τ) = Σₛ wᵀφ(s) is linear in features, fitting w is logistic regression on the differences Φ(A) − Φ(B): minimise −Σ [y log σ(z) + (1 − y) log σ(−z)] with z = wᵀ(Φ(A) − Φ(B)). The demo does exactly this by gradient descent, with a small Gaussian prior on w, and plans against the result with dynamic programming. Comparisons only determine rewards up to an additive constant, and the scale is set by how consistent the answers are.
Active querying asks about the pair whose answer the model expects to learn most from: it uses the curvature of the loss (a Laplace approximation to the posterior over w) to find pairs where the prediction is close to ½ because w is uncertain, not because the two walks are equally good. In the simulated runs it reaches a given agreement with fewer comparisons than random pairs, which the reference curves show and the tests check. Real systems use cruder versions of the same idea, since a human’s time is the scarce resource.
Paul Christiano, Jan Leike, Tom Brown, Miljan Martic, Shane Legg and Dario Amodei showed in 2017, in “Deep reinforcement learning from human preferences”, that this scales up: a neural reward model trained on human comparisons of short video clips taught agents Atari games and simulated-robot behaviours, including a backflip that would be hard to specify by hand, while the policy was trained by RL against the reward model. InstructGPT (Long Ouyang and colleagues, 2022) applied the recipe to language models in three steps: supervised fine-tuning on demonstrations, a reward model trained on human rankings of responses, and PPO against that reward model with a KL penalty to the fine-tuned model — reinforcement learning from human feedback, RLHF. Reinforcement learning from AI feedback replaces some of the human labels with a model’s; Constitutional AI (Yuntao Bai and colleagues, 2022) has a model compare responses against a written list of principles.
The demo is far smaller: five hand-made features instead of a neural network, and walks instead of text. If your taste cannot be written as a weighted sum of flowers, river, cliff edge, rocks and road, no amount of data will capture it — a real limitation of every reward model, whose features are whatever the network happens to learn.
Press “Sweep β down” and watch the orange distribution chase the proxy reward while the white curve below rises, peaks and falls. Then add preference data or drag the blue handles, and see the peak move.
π*(y) ∝ πref(y)·exp(rproxy(y)/β) is the exact optimum of E[rproxy] − β·KL(π ‖ πref), computed over 200 bins. The pale rose band is the reward model’s error (proxy minus truth): a bias past the dotted line plus two bumps you can drag. “More preference data” shrinks every error by × 0.8. Best-of-n keeps the sample the proxy rates highest out of n drawn from πref; its curves are plotted at the analytic KL, log n − (n − 1)/n. The rewards are invented for illustration; the shape of the curves is the point.
A learned reward model is accurate only where it has seen data — roughly, on responses the pretrained model already produces. RLHF therefore maximises Eπ[r(y)] − β·KL(π ‖ πref), where πref is the reference model and KL(π ‖ πref) = Σ π(y) log(π(y)/πref(y)). The penalty keeps the policy where the reward model can be trusted, and in language models it also keeps the text fluent and varied. The objective has an exact maximiser, π*(y) = πref(y)·exp(r(y)/β) / Z(β): an exponential tilt of the reference. As β → ∞ the policy is πref; as β → 0 it piles onto the proxy’s argmax. Along the way both KL and expected proxy reward increase monotonically, since each has derivative proportional to the variance of r under π* with respect to 1/β.
The closed form is also the starting point of Direct Preference Optimization (Rafael Rafailov and colleagues, 2023): inverting it gives r(y) = β log(π*(y)/πref(y)) + β log Z, and substituting that into the Bradley–Terry likelihood gives a loss on the policy itself, so preferences can train the policy directly without fitting a separate reward model or running RL.
Leo Gao, John Schulman and Jacob Hilton measured what happens when the leash is let out, in “Scaling laws for reward model overoptimization” (2022). Since asking humans for every measurement is expensive, they used a large “gold” reward model in the role of the human and trained smaller proxy reward models on its labels. Plotted against d = √KL from the initial policy, the proxy reward kept rising while the gold reward rose, peaked and fell, for both best-of-n sampling and RL; they fitted forms d(α − βd) and d(α − β log d) respectively, and larger proxy reward models suffered less from overoptimisation. The demo reproduces that shape with invented one-dimensional rewards, not their numbers.
Best-of-n is the simplest alternative to RL: sample n responses from πref and keep the one the reward model likes best. Its distribution is known exactly, and for a reward with no ties its KL from πref is log n − (n − 1)/n — so even a thousand samples move only about 5.9 nats. On a discrete set of responses the true KL can only be smaller. Both methods are Goodhart’s law made quantitative: optimising a proxy is safe for a while, and the amount you can get away with grows with the quality of the proxy.
Spot a mistake or have an idea?