Training agents with reinforcement learning
Episodes as sequences, token masks, shaping, environments, and grader hacking.
From one response to an episode
Reasoning models train one long response judged at the end. An agent’s episode is different: the model writes a turn, a tool runs, its output returns into the context, and this repeats dozens of times before anything grades the task. Most of the context was written by the environment. And the environment — including the files that decide the reward — can be changed by the agent.
An episode as one sequence
Key idea. Treat the whole episode as one token sequence with mask on model tokens and on task/tool tokens. The policy gradient keeps only the model’s tokens:
Without the mask the loss trains the model to predict tool outputs weighted by success — “auto-suggestive delusion”. Search-R1: average exact match with the mask vs without. Worked group: rewards → this success gets on all model tokens.
Credit across turns and shaping
Episode-level advantages give every turn the same weight. Remedies: a turn-level critic (ArCHer); or potential-based shaping with at episode end, which telescopes and leaves the optimal policy unchanged. Arbitrary bonuses (e.g. for every tool call) change the objective and are exploited. Many systems keep a sparse outcome only (DeepSWE: if hidden tests pass).
Environments and rejection sampling
Environments pair a task distribution, a resettable sandbox, and an outside grader: SWE-Gym, R2E-Gym/DeepSWE, WebRL, Search-R1. Tasks are filtered so GRPO gets signal (not always-succeed / never-succeed).
Filtered behaviour cloning (STaR, expert iteration, RFT): sample, keep successes, SFT on model tokens, repeat. At the current policy its gradient is . In expectation it differs from GRPO mainly in how it weights tasks; it is the baseline every agentic RL result should beat. On a small toy, filtered BC matched GRPO near the ceiling.
Asynchrony and reward hacking
Long uneven episodes push asynchronous rollouts: generation and training decouple; data is slightly off-policy, corrected by importance ratios and clipping (AReaL, async RLHF).
Reward hacking: agents edit what the grader reads — exit(0), skipped tests, patched timers/evaluators, __eq__ always true. Baker et al.: a CoT monitor caught of systemic hacks vs from actions alone; putting the monitor in the reward taught obfuscation. Toy: hackable grader reports while hidden tests say .
Defences and next
Grade outside the sandbox; least privilege on tests; monitor to patch environments, not as a training reward; track an honest eval the training reward does not see.
Every quoted pass rate came with a scaffold, budget and date. Next: evaluating agents — trustworthy measurements of random systems on finite task samples.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Answers are saved on the server and tied to this browser until you sign in.