To build an RL environment, pick a workflow with a checkable outcome and write down one task. Then snapshot the world before the task, expose tools the agent can call, add a verifier that scores the end state, and reset cleanly between runs. Test it with a known-good solution and an agent trying to cheat before you train on it.
GuidePart of: RL environments
How to Build RL Environments for Agents: 7 Steps That Hold
Published 5 min read

On this page
This guide is for lab and vendor teams building environments for LLM agents. It covers the build order and the tests. For which enterprise records suit which part, see our overview of RL environments from enterprise workflows.
What are RL environments, and what's inside one?
An RL environment is a program that hands an agent a task, reveals part of a world, accepts actions and returns a score. It has five parts.
| Part | Job | Small example |
|---|---|---|
| Task | What to achieve | "Refund the duplicate charge" |
| State | The world before the agent acts | A table of payments |
| Tools | What the agent can do | find_payments, refund |
| Verifier | Turns the result into a score | Did the right payment get refunded? |
| Reset | Restores the start | Reload the snapshot |
A verifier is the grader: code that looks at the result and returns a number. If it's wrong, the model learns the wrong thing. So most of the care goes there.
How do you build an RL environment, step by step?
Build from the check backwards. Decide how you'll know the task was done, and only then write the rest.
- Pick one workflow. Choose work that happens often and ends in a recorded result. Refunds, code fixes and order changes all qualify.
- Write the verifier first. State the correct end state in code. If you can't, the task isn't ready.
- Snapshot the state. Freeze the data as it was when the task began. Nothing from later should leak in.
- Expose the tools. Offer a small set of calls, each with a clear schema and error messages an agent can act on.
- Add a simulated user if needed. Service tasks need someone to reply. Script it to reveal facts only when asked.
- Make runs repeatable. Each attempt starts from a clean copy, with a fixed step limit and logged tool calls.
- Test it, then scale. Prove one task end to end before you write fifty.
A minimal environment in Python
Here's the whole loop, with a fictional refund task. It's small on purpose, so you can see each part.
START = {"p1": {"amount": 89, "refunded": False},
"p2": {"amount": 89, "refunded": False}}
class RefundEnv:
task = "Booking B-1042 was charged twice. Refund the duplicate, p2."
def reset(self):
self.db = {k: dict(v) for k, v in START.items()}
self.steps = 0
return self.task
def step(self, tool, **args):
self.steps += 1
if tool == "find_payments":
obs = self.db
elif tool == "refund" and args.get("id") in self.db:
self.db[args["id"]]["refunded"] = True
obs = "ok"
else:
obs = "error: unknown tool or id"
done = tool == "finish" or self.steps >= 10
return obs, self.verify() if done else 0.0, done
def verify(self):
refunds = [k for k, v in self.db.items() if v["refunded"]]
return 1.0 if refunds == ["p2"] else 0.0
The shape follows Gymnasium's reset and step pattern, trimmed down. Note what the verifier does. It refunds nothing itself and never reads the agent's words. It only checks the database at the end, so a confident wrong answer scores zero.
Copy the shape of a public benchmark
Two public benchmarks are worth reading before you design your own. SWE-bench takes real GitHub issues and scores a patch with tests. The tau-bench paper puts an agent in a retail or airline service role with a written policy, then compares the final database with a goal state.
That second design matters for enterprise work. Different conversations can reach the same correct end state, so you don't have to grade the wording. And it exposed how fragile agents were: gpt-4o passed about 61% of retail tasks once, but only about 25% when it had to pass 8 times in a row. So run each task several times, not once.
How do you design the reward?
Use hard checks wherever a right answer can be computed. Add softer scoring only where it can't.
| Reward type | Checks | Use it for | Main risk |
|---|---|---|---|
| Outcome | Tests pass, exact database state | Code, records, transactions | Too strict on valid variants |
| Partial credit | Weighted checkpoints reached | Long multi-step tasks | Farming easy checkpoints |
| Rule check | Required steps happened in order | Policy-bound work | Long list of brittle rules |
| Rubric or LLM judge | Named criteria for written output | Summaries, advice | Drift between runs |
Gate the partial credit. If the core outcome failed, cap the score, so an agent can't earn most of the reward for tidy steps around a wrong result.
Check the path when the rules matter. A refund granted without the required approval is still a failure, even if the database ends up correct. Our guide to what training records look like shows how a scored trajectory is stored once you have one.

How do you test an RL environment before training?
Try to prove it wrong. An environment that hasn't been attacked will teach the model to exploit it.
Four checks to run on every task
- The solver test. Run a scripted correct solution from a clean reset. It must score full marks. If it doesn't, the task or the verifier is broken.
- The null test. Run an agent that does nothing, then one that gives up early. Both must score near zero.
- The cheat test. Point a strong model at it and read the top-scoring runs by hand. Look for answers that scored well for the wrong reason.
- The repeat test. Run the same task many times. Unexplained swings mean a flaky tool or a hidden dependency on time or order.
Why the cheat test matters most
Reward hacking means getting a high score without doing the task. It's common. METR's reward hacking report describes an early version of o3 patching an evaluator so it always returned a perfect score, and overwriting a timer to fake a speed result.
The rate depended heavily on the task set. It was 0.7% of runs on one suite and 30.4% on another. METR also says it may have missed cases. So don't borrow someone else's number. Measure your own.
Some simple defences go a long way:
- Keep verifier code, expected answers and test files out of the agent's reach.
- Remove the recorded outcome from anything the agent can read.
- Run tools with the fewest permissions that still work.
- Keep a held-out set of tasks, split by organisation or by time, that never touches training.
Where do the tasks come from?
You can write tasks, generate them or draw them from real records. Writing them by hand gives you control but little variety. Generated tasks scale, but they follow the patterns their author imagined.
Real records bring the long tail: vague requests, missing details and exceptions to policy. They also bring privacy work. If the same customer has to appear across two systems, you need tokens that stay consistent across sources, and that needs to be agreed up front. Our support ticket dataset guide compares public and licensed tickets for this kind of use. The source code dataset spec lists the history and test fields that coding tasks need.
If you're asking a supplier for this data, ask for the outcome codes, the state around each task and the written policies people followed at the time. Without those, you can't write step 2.