Fine-tuning, RLHF & Alignment·Question 54 of 61Advanced

You want to RL-train an agent for a multi-turn tool-use task, and the only reward you have is whether the final task succeeded. How do you make that work?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

The hard parts are the environment and credit assignment. The algorithm is the easy bit.

Full worked answer with diagram

The hard parts are the environment and credit assignment. The algorithm is the easy bit.

1. Environment before algorithm. You need a sandbox you can reset, run thousands of times a day in parallel, and that is deterministic enough that the same policy gets the same reward. Mock or record-and-replay external APIs. A live API in the loop gives you rate limits, flakiness and side effects, and reward noise from a flaky environment is indistinguishable from a bad action, so it poisons training directly. Cap turns and tool calls so one runaway episode cannot eat the batch.

2. Task set. A few thousand tasks with programmatic success checks and a spread of difficulty. Then filter continuously: tasks solved on every rollout give no gradient, tasks never solved give no signal. Train the band in between and re-filter as the agent improves. That is your curriculum, and it is most of the win.

3. Credit assignment. A group-relative method (GRPO-style: N rollouts per task, advantage relative to the group) gets you surprisingly far without a value network, which is welcome because value models are unreliable over long horizons. The whole trajectory shares one advantage, which is coarse, but it works when N is large enough and difficulty is right. If it is still too sparse, add step signal: a PRM, or cheap programmatic milestones (did it locate the right file, did the tool call parse, did the query return rows). Keep milestone rewards small relative to the terminal reward and log them separately, because shaped rewards are the easiest thing in the world to hack.

4. Masking. Train only on the model's own tokens. Tool outputs, observations and system messages are context, not targets. Get this wrong and the model learns to hallucinate tool results, which is a nasty bug that looks like a capability problem.

5. Guardrails. KL to reference, watch entropy, hold out a task set the reward never touches.

6. Validate the reward before spending compute. Run 50 rollouts with a strong model and read them. Check that "success" means what you think. It usually does not on the first try.

Worth sketching. it puts the curriculum filter inside the loop, not in a preprocessing step you do once.

flowchart LR
    A["Resettable sandbox,<br/>mocked external APIs"] --> B["N rollouts per task"]
    B --> C["Terminal success check"]
    C --> D["Group-relative advantage<br/>across the N rollouts"]
    D --> E["Update on model tokens only,<br/>tool outputs masked out"]
    E --> B
    C --> F{"All N pass<br/>or all N fail?"}
    F -->|"yes"| G["Drop the task,<br/>refilter the difficulty band"]

What a good answer covers

  • The hard parts are the environment and credit assignment
  • You need a sandbox you can reset, run thousands of times a day in parallel, and that is deterministic…
  • Mock or record-and-replay external APIs
  • A live API in the loop gives you rate limits, flakiness and side effects, and reward noise from a flaky…
  • Cap turns and tool calls so one runaway episode cannot eat the batch

Key terms: 1. Environment before algorithm · 2. Task set · 3. Credit assignment · 4. Masking · 5. Guardrails

Interviewer follow-ups to expect

  1. How would you handle a task where success is only checkable by a human?

  2. Why is trajectory-level advantage tolerable here, and at what horizon does it stop working?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep