Reward

A reward is the number that tells a reinforcement learning model how well an action or attempt went.

In reinforcement learning, a reward is a score that the environment returns after an action or at the end of an episode. Higher rewards mean better outcomes. The model is never told the right answer directly. It learns only by trying to earn more reward over many attempts.

A reward can be given at every step or only at the end. Rewards at the end are easier to define, such as passing tests, but they make it hard to tell which step helped. Rewards come from rules, from a verifier, from another model acting as a judge, or from human ratings. A reward that does not fully match the goal invites reward hacking, where the model finds a way to score well without doing the task.

For agents that write and run code, the reward often comes from executing something, such as a test suite, a build or a script that checks the output. That check has to run in the same environment the agent changed. The environment is often a sandbox, so the check can run safely and give the same result each time. The check has to stay out of the agent's reach, or the agent may change it to raise its own reward.