Part II / Reinforcement Learning

Improving a policy

Value methods learn which action is best, then derive behavior. Policy-gradient methods change the behavior distribution directly. That is especially natural when actions are tokens and the space is enormous.

07
Actor

The policy that assigns action probabilities.

Critic

The value estimator that supplies a baseline.

Tension

Exploit known good actions without collapsing exploration too early.

Move probability mass, not a chess piece

Suppose the reasoning engine has three plausible first actions: inspect the changed gateway, compare both paths, or search logs. Its policy assigns probabilities [0.50, 0.30, 0.20]. A rollout samples "compare both paths" and earns positive advantage. A policy-gradient update increases the log-probability of that sampled action. Because probabilities must sum to one, mass moves away from other choices.

Mental model

The gradient does not say "this action is correct forever." It says "make this sampled action more or less likely in situations like this, in proportion to how surprisingly well or poorly it turned out."

The policy-gradient theorem gives a practical estimator built from grad log pi(a|s) multiplied by return or advantage. The log trick turns the gradient of an expected sampled outcome into a quantity we can estimate from trajectories.

grad J(theta) ~= E [ grad log pi_theta(a_t | s_t) * A_t ] Raise the probability of sampled actions with positive advantage; lower the probability of those with negative advantage.

One sampled investigation

Concrete example

The current policy gives "compare both paths" probability 0.30. The trajectory earns return 0.90, while the critic predicted 0.55. Its estimated advantage is +0.35. The update should increase that action's log-probability, but only for the evidence context that produced it.

If another prompt has a single gateway and a clear interface alarm, the same tool action may be wasteful. Neural policies generalize through shared representations, so an update can affect nearby situations. Because a local sample creates a global parameter change, batch composition, learning rate, clipping, and evaluation all matter.

REINFORCE uses sampled returns directly.[source] Subtracting a baseline that does not depend on the sampled action leaves the expected policy gradient unchanged while reducing variance. A learned state-value function is a common baseline. When the policy and value estimator train together, we call the system actor-critic: the actor chooses actions; the critic evaluates the situation.

Actor loss
Changes action probabilities using estimated advantage.
Critic loss
Fits value estimates toward observed or bootstrapped returns.
Entropy bonus
Rewards distributional spread to resist premature certainty.
KL penalty
Discourages moving too far from a reference or previous policy.

Exploration is how data gets made

If the policy always chooses its current favorite action, it may never discover a better one. In bandits, exploration tries uncertain arms. In sequential problems, an exploratory action changes which states become reachable. In language models, sampling temperature, top-p, prompt selection, and environment diversity influence exploration. The trainer only learns from trajectories generated by the rollout policy.

More randomness is not automatically better. Random tool calls can be expensive or unsafe. Structured exploration may vary candidate answers in a sandbox, use uncertainty to select tasks, preserve entropy only where alternatives are plausible, or add curricula that gradually expose harder environments. Production traffic is usually not the place for unconstrained exploration; replayable environments create a safer boundary.

MechanismWhat it exploresAgent example
Stochastic policyDifferent actions in the same observationSample several investigation plans
Task samplingDifferent regions of the environment distributionOversample rare ambiguous incidents
Entropy regularizationMaintains action-distribution spreadAvoid locking onto one tool sequence
Intrinsic rewardNovelty or information gainReward a query that distinguishes hypotheses

Why token policies fit policy gradients

An LLM policy factorizes a response probability across tokens. The log-probability of the sequence is the sum of token log-probabilities. We can therefore weight generated-token log-probabilities by an advantage estimate and backpropagate through the model. The "action" can be viewed at token level, sequence level, or as a structured tool call assembled from tokens; implementations must be precise about which tokens receive loss.

Prompt tokens usually are not policy actions, so their log-probabilities are masked from the policy loss. Generated reasoning, tool syntax, and final answer tokens may share one sequence reward even though their causal roles differ. Process rewards or token-level credit models can provide more local signals, but they also encode stronger assumptions about the desired path.

Engineering reality

Policy-gradient RL requires sampling from the current or recent policy and retaining token log-probabilities, masks, rewards, and often value estimates. The training batch is a structured trajectory dataset, not a bag of prompt-response strings.

Misconception: positive reward means increase every token

The learning signal should be advantage, not raw praise. A high reward on an easy prompt may be below expectation; a modest reward on a hard prompt may be exceptional. Token masks, baselines, and constraints determine which probabilities move.

On-policy means the data contract is narrow

Policy-gradient estimators are simplest when the trajectories came from the policy being updated. If the behavior policy differs, importance ratios can correct some mismatch, but variance grows and support matters: a policy cannot learn about actions the behavior policy never took. PPO is considered on-policy because it reuses fresh data for a limited number of updates while constraining the change.

For distributed agents, "fresh" is a systems property. Rollout workers cache weights; long episodes finish at different times; trainers update asynchronously. Every trajectory should carry the generating policy version. A pipeline that ignores this metadata can silently become more off-policy as scale increases.

References