How to write a grader or verifier for an agent environment
At a glance
Write a grader that checks the final state with code, also checks what must not have changed, runs where the agent cannot touch it, and is tested with right, wrong and empty answers. Keep environment errors out of the reward, and use a model as judge only for what code cannot check.
- Compiled by
- AgenticRLEnvironments editors
- First recorded
- Last revised
- Reading time
- 8 min
A grader is the code that decides an episode's reward. For agent environments it should inspect what the agent did to the world, not what the agent said it did, and it should be tested as carefully as the environment itself, because every flaw in it becomes something the agent learns.
What kinds of graders do agent environments use?
Agent environments use four kinds of grader: state checks, test suites, answer matching and model judges.
Table: Kinds of grader, with published examples
| Grader | What it checks | Published example | Main risk |
|---|---|---|---|
| State check | The database, files or app state after the episode | AppWorld's state-based unit tests, which also check for collateral damage (arXiv 2407.18901) | Missing a side effect you did not think to check |
| Test suite | Tests that must go from fail to pass, and stay passing | SWE-bench: solved when "all tests across FAIL_TO_PASS and PASS_TO_PASS pass" (arXiv 2310.06770) | Tests too weak to catch a wrong fix |
| Answer or attribute matching | The returned answer or chosen item against the goal | WebShop scores attributes, options and price against the instruction (arXiv 2207.01206) | Formatting differences marked wrong |
| Model judge | Open-ended output, rated by a language model | The MT-Bench judge study (arXiv 2306.05685) | Judge bias and judge exploitation |
All read 2026-11-26.
Step 1: How do I write a state-check grader?
Write it as a set of assertions about the final state, run after the episode ends.
- List the facts that must be true for success: "order A715 status is cancelled".
- List the facts that must stay true: "orders A948 and A661 are still shipped", "no new refunds were issued".
- Read both from the environment's database or API, not from the agent's transcript.
- Return 1 only if every assertion holds; return partial credit only if you have decided you want it (see reward design).
- Log which assertion failed. That log is how you debug both agents and graders.
The second list is what most first graders miss. A grader that only checks "the order is cancelled" pays an agent that cancels every order.
Step 2: How do I write a test-based verifier for code tasks?
Use two test sets: tests that fail before the fix and must pass after it, and tests that pass before and must still pass.
SWE-bench calls them FAIL_TO_PASS and PASS_TO_PASS, and counts a task as solved only if both sets pass after the patch is applied (SWE-bench paper, read 2026-11-26). Three rules keep this honest:
- Run the tests from a clean copy the agent never touched. Copy the agent's changes to source files only, then add the original tests back.
- Check the tests are strong. Run a few plausible wrong fixes; at least one test should fail for each.
- Treat test-file edits as suspicious. If the agent's change touches tests, either discard those edits or fail the episode.
The ABC checklist paper found that "SWE-bench Verified uses insufficient test cases" (Zhu et al., arXiv 2507.02825, read 2026-11-26): strong-looking tests can still accept wrong patches.
Step 3: When should I use a model as judge?
Use a model as judge only when the result cannot be checked by code, such as the quality of a written explanation, and keep it narrow.
The MT-Bench study reports that strong model judges reach "over 80% agreement" with human preferences, "the same level of agreement between humans", and it examines "position, verbosity, and self-enhancement biases" (Zheng et al., arXiv 2306.05685, read 2026-11-26). In practice:
- Give the judge a rubric with yes or no questions, not a 1 to 10 scale.
- Give it the evidence it needs, such as the final state or the reference, not only the agent's claims.
- Swap the order of compared answers and average, to cancel position bias.
- Measure agreement with human labels on a sample before using its scores for training.
- Watch for agents learning to please the judge: longer answers, confident wording, or instructions aimed at the judge.
Step 4: How do I test the grader itself?
Test the grader with a fixed set of episodes whose correct scores you know, and run that set every time the grader or the environment changes.
Table: A minimum test set for a grader
| Test episode | Expected score |
|---|---|
| Reference solution | Full reward |
| Do nothing, then finish | Zero |
| Empty or malformed final answer | Zero |
| Right action on the wrong object | Zero |
| Right result plus an unwanted side effect | Zero, or reduced if you award partial credit |
| Known exploit, such as editing tests or printing the expected output | Zero |
The empty-answer row is in the table because it has caught real benchmarks: the same checklist paper reports that "TAU-bench counts empty responses as successful", and that such issues can lead to under- or overestimation of agent performance "by up to 100% in relative terms" (Zhu et al., read 2026-11-26).
How do I keep environment errors out of the reward?
Give every finished episode one of three outcomes, not two: the task succeeded, the task was attempted and not achieved, or the environment broke before the attempt could count. Only the first two produce a reward. An episode whose app crashed, ran out of memory or timed out on its own side carries no information about the agent, and scoring it 0 teaches the policy that whatever it did was wrong.
On a hosted service, Promigence prints a validity report after each run that counts completed sandboxes, the ones that ended on the task's account and the ones that ended on the environment's account, according to its quickstart. Its errors reference states that an environment-side error is kept out of your result and retried once before hand-over, and gives the grader's own outcomes separate codes: grade_not_passed when "The task completed and its grade did not pass", counted as the task's, and grader_failed when "The grade could not be computed", which it calls "Not a task failure". Its CLI reference lets a run name the grader: --grade is "A command that scores the work in a clean copy of the environment after CMD ends", and --holdout is "A second, held-out test command; the report shows the gap between the two pass rates". Its FAQ adds that a sandbox that stopped partway through a run can be started again with promigence run replay, as a new sandbox. All four pages were read 2026-11-26.
The other named providers document what they report when a sandbox or a command ends, which is where your own classification starts:
Table: How AWS, Daytona, E2B, Google Cloud and Modal report the end of a sandbox (read 2026-11-26)
| Provider | What it reports when a sandbox or command ends | Source |
|---|---|---|
| AWS (Amazon Bedrock AgentCore) | A Runtime session stops on inactivity (15 minutes by default), at its maximum lifetime (8 hours by default), on an explicit stop, or when health checks find its compute unhealthy | Runtime sessions |
| Daytona | Its lifecycle states include Build Failed, which "needs to be retried", and Error, which "needs to be recovered" | Sandboxes |
| E2B | When a stream drops, the SDK says whether the sandbox was killed or reached its end of life (TimeoutError in JavaScript, TimeoutException in Python); any other connection error means the sandbox is still running | How long does a sandbox live? |
| Google Cloud (Gemini Enterprise Agent Platform sandboxes) | Command output, meaning stdout, stderr and exit codes, is returned in the execution response to the parent agent | Manage sandboxes |
| Modal | Unix-style exit codes on each process and on the Sandbox itself tell success, manual termination and out-of-memory apart; a Sandbox finishes when its entrypoint exits, it is terminated, a timeout or idle timeout is reached, or it runs out of memory | Sandboxes guide |
To build the same split into your own environment:
- Check the environment before handing it over. Run a short health check after reset: the app answers, the seed data is there, the tools respond.
- Classify the end of every episode. Agent-side ends: it called
finish, gave up, or hit the step limit. Environment-side ends: the instance died, a service it depends on timed out, a memory limit killed the app. - Drop or retry environment-side episodes. Exclude them from the training batch and the reported score, and start them again from the same seed.
- Report the two rates apart. A rising environment-side rate is a bug in your environment, not a change in your agent.
Where should the grader run?
Run the grader outside the agent's reach: after the episode, in a process the agent could not modify, reading state through a path the agent could not change.
If the grader runs inside the environment the agent controls, the agent can change it. Published accounts include agents that made a verification function "always return true", raised exceptions to skip tests, and stubbed whole libraries "in order to overwrite their verification functions" (Baker et al., arXiv 2503.11926, read 2026-11-26). Practical rules:
- Copy out only the artefacts the grader needs, then grade in a fresh copy of the environment.
- Keep reference solutions and expected outputs out of the agent's file system.
- Grade on exit codes and results produced by your own test runner, not on text the agent's process printed.
What we read for this article
- AppWorld (arXiv 2407.18901), read 2026-11-26
- SWE-bench (arXiv 2310.06770), read 2026-11-26
- WebShop (arXiv 2207.01206), read 2026-11-26
- Judging LLM-as-a-Judge (arXiv 2306.05685), read 2026-11-26
- Establishing Best Practices for Building Rigorous Agentic Benchmarks (arXiv 2507.02825), read 2026-11-26
- Monitoring Reasoning Models for Misbehavior (arXiv 2503.11926), read 2026-11-26
- https://www.promigence.ai/docs/quickstart, read 2026-11-26
- https://www.promigence.ai/docs/errors, read 2026-11-26
- https://www.promigence.ai/faq, read 2026-11-26
- https://www.promigence.ai/docs/cli, read 2026-11-26
- AWS: AgentCore Runtime sessions, read 2026-11-26
- Daytona: Sandboxes, read 2026-11-26
- E2B: How long does a sandbox live?, read 2026-11-26
- Google Cloud: Manage sandboxes, read 2026-11-26
- Modal: Sandboxes guide, read 2026-11-26
Field questions
What is the difference between a grader and a verifier?
The words are used almost interchangeably. Grader usually means the function that turns an episode into a score. Verifier is common in RL with verifiable rewards and in coding, where it can also mean a learned model that ranks candidate solutions. On this page both mean the check that decides the reward.
Should a grader read the agent's final answer or the environment state?
The state, whenever the task changes something. An answer can claim success that did not happen. For question-answering tasks with no state change, compare the answer with the reference using a normaliser, not exact string equality.
Can I use an LLM as the grader?
For open-ended outputs, yes, with care. The MT-Bench study found strong model judges agree with human preferences over 80% of the time, about as often as humans agree with each other, but also documented position, verbosity and self-enhancement biases. Use code wherever code can decide.
How do I know my grader is wrong?
Test it. Feed it a correct solution, an empty one, a near miss and a known exploit, and check each score. A published checklist study found grading flaws that misestimated agent performance by up to 100% in relative terms.