Skip to content

Interview question · Optimizing & Tuning Agents

Design the reward for training a coding agent with reinforcement learning. What makes it useful?

The agent will optimise exactly what you reward. A useful reward checks the real outcome where the agent cannot reach it, is neither always won nor always lost, and closes the hacks you can predict.

hardNewUpdated Nov 2026

TL;DR: Reward the verified outcome: hidden tests the agent cannot see or edit pass after its patch, and the existing suite still passes. Guard the known hacks (edits to tests, hard-coded outputs, deleted code paths) with checks and penalties. Choose tasks of mixed difficulty so groups of attempts differ, because GRPO-style training learns nothing from groups that all succeed or all fail. Validate on held-out repositories and compare with what prompt and harness changes achieve.

How to approach it

Define the outcome, make it verifiable and unreachable, decide binary versus partial credit, list the hacks and their guards, then cover the task distribution and validation.

A strong answer

The outcome. For a bug-fix task: the issue's failing tests now pass, the previously passing tests still pass, and the patch builds and type-checks.

Make it verifiable and unreachable.

  • Hidden tests live outside the agent's workspace and run in a separate step.
  • The agent's sandbox has no write access to grader files.
  • The reward is computed from the environment, not from the agent's summary.

Binary or partial. Binary (all target tests pass and nothing regressed) is hard to game but sparse. Partial credit (fraction of target tests passing) gives more signal on hard tasks and more surface to exploit. A common choice is binary for the headline reward plus small shaped terms you watch closely.

Guard the hacks.

def reward(result):
    if result["touched_tests"] or result["hardcoded_outputs"]:
        return 0.0, "rejected: changed tests or hard-coded outputs"
    if not result["builds"]:
        return 0.0, "does not build"
    target = result["target_passed"] / result["target_total"]
    regressions = result["previously_passing_failed"]
    score = 1.0 if target == 1.0 and regressions == 0 else 0.0
    return score, f"target {target:.0%}, regressions {regressions}"

print(reward({"touched_tests": False, "hardcoded_outputs": False, "builds": True,
              "target_passed": 3, "target_total": 3, "previously_passing_failed": 0}))
print(reward({"touched_tests": True, "hardcoded_outputs": False, "builds": True,
              "target_passed": 3, "target_total": 3, "previously_passing_failed": 0}))
# => (0.0, 'rejected: changed tests or hard-coded outputs')

Task difficulty. With group-based methods such as GRPO, an attempt's advantage is relative to its group. Tasks the model always solves or never solves give zero advantage. Filter or schedule tasks so most groups are mixed, and refresh the pool as the model improves.

Length and cost. Cap steps and tokens per rollout so the reward does not favour brute force, and track cost per solved task.

Validate. Held-out repositories, not just held-out issues from training repositories; review samples of high-reward trajectories by hand; compare with prompt optimisation and harness changes on the same tasks before committing to a trained model.

What interviewers probe next

"Why not use an LLM judge as the reward?" For code, tests are a stronger verifier; a judge can be persuaded and drifts. Use a judge only for qualities tests cannot check, and calibrate it.

"What if rewards keep rising but reviewers reject patches?" That is reward hacking: inspect trajectories, find the gap between the checker and the intent, and close it.

How it's scored

Weak: "Reward when tests pass."

Hire: Hidden tests, no regressions, guards against editing tests.

Strong Hire: Verified and unreachable outcome, binary versus partial trade-off, explicit hack guards, mixed-difficulty curriculum tied to group-relative advantages, step and cost caps, held-out repositories, trajectory review and comparison with cheaper levers.

Common mistakes

  • Letting the agent see or modify the tests that score it.
  • Training on tasks it always or never solves.
  • Trusting the reward curve without reading trajectories.
You just read a free answer. Every topic opens its first 5 answers to anyone. Sign in and the count per topic goes to 6, and the site remembers where you stopped in each one.Google sign-in · free · no payment details
HOW DID IT GO?
0
READING SIGNED OUT

Signing in raises your free answers from 5 to 6 per topic, adds an applied lesson in every topic and easy practice tests, and the site starts remembering you: mastery per topic, bookmarks, and a next-focus recommendation. Free, no card.

Sign in free
UP NEXT ON YOUR JOURNEY
DISCUSSION · 0

Nobody has commented. Post a correction or another way to answer.