From production traces to RL environments
A production trace records one run of your AI agent. An RL environment lets a model retry it. What a trace holds, what to add, and one refund trace as a task.
On this page
A customer asks a support agent to refund a $419 sleeping bag. The shop's policy sends any refund above $200 to a supervisor. The agent looks up the order, reads the policy, and issues the full refund on the spot.
You have the trace. Every model call, every tool call and every argument is in it. You can see the exact step where the agent went wrong.
What you cannot do with the trace alone is let a model try that same request again. The order, the policy page and the refund ledger existed in production at that moment. The trace kept what the agent saw and did. The world the agent was acting in is gone.
An RL environment is that world, rebuilt so a model can attempt the task as many times as you like, with a check at the end that says whether it succeeded. This post explains the parts of an environment, lines them up against the parts of a trace, and walks one refund trace through the conversion.
In short:
- A trace is a recording of one run. An environment is a task a model can attempt repeatedly.
- A trace already holds the task wording, the tool list, the path the agent took and the point where it went wrong.
- You still have to add four things: a starting state, tools that respond, a verifier and a reset.
- A failed trace is worth converting when the failure came from the agent's decision and the correct outcome can be checked from final state.
A production trace supplies the instruction, the tool list, the path and the failure point. A starting state, tools that respond, a verifier and a reset are added to make an environment that a model can attempt many times.
What comes from the trace and what you add.
What is an RL environment?
An RL environment is everything a model interacts with while it attempts a task, plus the check that scores the attempt. In reinforcement learning, the model tries the task, receives a reward, and its weights are updated toward behavior that earned more reward.
For AI agents, an environment has five parts.
The task. An instruction in plain language: what the agent is asked to do.
The starting state. The files, database rows, tickets or accounts that exist before the agent takes its first step.
The tools. The actions available to the agent, and something behind each one that responds and changes state.
The verifier. A check that runs after the agent stops, inspects the result, and returns a reward. Of the five, the verifier deserves the most care. Its verdict is the only feedback the model gets, so a model can never learn a distinction the verifier fails to make. Snorkel's guide to environment design makes the same point (Snorkel, 2026).
The reset. A way to return everything to the starting state, so the next attempt begins from the same place.
A task with its starting state leads to an attempt, where the model calls tools and changes state. A verifier checks the final state and returns a reward. A reset restores the starting state before the next attempt.
One attempt, then a reset and the next one.
Harbor, an open source framework built by the team behind Terminal-Bench, is one open format for packaging these parts. Its docs describe a task as "an instruction, environment, and test script", laid out as a directory:
my-task/
├── instruction.md
├── task.toml
├── environment/
│ └── Dockerfile
├── solution/
│ └── solve.sh
└── tests/
└── test.sh
The instruction is the task. The environment/ folder builds the starting state and the tools, usually as a container image, and starting a fresh container is the reset. The script in tests/ is the verifier: it has to write a numerical reward to /logs/verifier/reward.txt (Harbor docs). The solution/ folder holds a reference solution, which proves the task can be solved.
The same package serves evaluation and training. Run it once per model to compare models. Run it thousands of times and feed the rewards back, and it becomes training data.
What is a production trace?
A production trace is the record of one run of your agent, captured while it served a real request. It holds the user's message, each model call with its prompt and response, each tool call with its arguments and result, and the timing, token count and cost of every step.
In traceroot, a trace also carries the session and user it belongs to, any tags and metadata you attach, and git context: the repository, the commit, and the source file and line of each instrumented function.
A trace answers one question well: what happened in this run? You can read it, search it, score it and group it with similar runs. What it cannot do is run again with a different model.
Trace vs. RL environment
| Production trace | RL environment | |
|---|---|---|
| What it is | A recording of one run | A task that can be attempted repeatedly |
| Where it comes from | Captured automatically in production | Built on purpose |
| State | Only what the agent read or wrote, as tool results | The full starting state, restored before every attempt |
| Tools | Past calls with their recorded results | Working tools that respond to new calls |
| Outcome | Whatever happened | A reward from a verifier |
| How many times it runs | Once | As many as you need |
| Typical use | Understanding and improving a deployed agent | Evaluating or training a model on a task |
One more term sits between the two. In RL, each attempt at a task leaves a trajectory: a log of every step the agent took and what the environment returned. Harbor stores it as trajectory.json in its Agent Trajectory Interchange Format (Harbor docs). A production trace is a trajectory from the one environment you never had to build, which is production itself.
What a trace already gives you
A failed production trace is a strong first draft of a task. Four parts of the environment can be read straight out of it.
The instruction. The user's own words, at the top of the trace. In this run that is two messages: an earlier one about returning the bag, and a follow-up asking for the full $419.
The tool list. Every tool span names a tool and shows the arguments the agent passed. That gives you the tool names and their schemas as the agent really uses them.
The path. The order of calls tells you which records the agent touched: which order, which customer, which policy article. Those are the records your starting state has to contain.
The failure point. The step where the run went wrong tells you what the verifier needs to check.
Here is that run as it was recorded in our public demo project, a support agent for an outdoor gear shop. The tree keeps the agent and tool spans and leaves out the model calls.
support_agent
├── get_customer
├── route_message
└── refunds_agent
├── search_help_center
├── lookup_order
└── issue_refund(A-48333, 419) → status: "refunded"
└── lookup_order
Boxed: the $419 refund ended as refunded.
All four are in this run. The instruction is the customer's message: "Please refund the full $419." The tools are get_customer, lookup_order, search_help_center and issue_refund. The state that matters is one customer, one order and one policy article. And the failure is the last line: a refund above the limit that ended as refunded.
What you have to add
Four parts are missing from every trace, because production never needed them.
A starting state. The trace shows lookup_order returning a $419 sleeping bag. It does not hold the orders table. You have to seed one: this order, this customer, plus enough other records that the agent cannot guess the answer from an almost empty database.
Tools that respond. In the trace, issue_refund is a past event with a recorded result. In an environment it has to be a working function, because the model may call it with different arguments, in a different order, or not at all. A mock that replays the recorded result would only ever reward the original mistake.
A verifier. Production has no reward. Someone has to write down what a correct ending looks like and turn it into a check. For the refund, the check reads the refund ledger after the agent stops: the request for order A-48333 exists, and its status is pending_supervisor.
Checking final state is sturdier than checking the reply. An agent can write "I've sent this to a supervisor" and still have issued the refund. The ledger shows what it actually did.
A reset. The second attempt has to meet the same order in the same condition as the first. With a container, that means a fresh container for each attempt.
Most task formats ask for a fifth thing: a reference solution. Harbor's solution/solve.sh is a script that completes the task the intended way. If your own solution cannot earn the reward, the fault is in the task, and no model will earn it either.
One refund trace as a Harbor task
Put together, the refund trace becomes a small directory.
instruction.md carries the customer's request, kept close to the original wording:
You are a support agent for Acme Outfitters.
Customer C-1006 wrote earlier: "I want to return the Ultralight sleeping
bag (order A-48333). It is not what I expected."
They now write: "Please refund the full $419."
Handle the request according to the shop's policies.
The instruction leaves the $200 limit out on purpose. The policy lives in the help center inside the environment, where the production agent found it. With the rule in the prompt, the task would test whether the model reads its instructions. Leaving it in the help center tests the step that failed in production: looking the policy up and applying it.
environment/ builds the shop: a small service with the orders, customers and help-center articles the trace touched, and the four tools wired to it. In the environment version, sending a refund to review is a separate action the agent has to choose, so the decision sits with the model.
tests/test.sh is the verifier. This is a sketch of its shape:
#!/bin/bash
# Reward 1 if the refund went to supervisor review, 0 otherwise.
status=$(jq -r '.["A-48333"].status' /app/state/refunds.json)
if [ "$status" = "pending_supervisor" ]; then
echo 1 > /logs/verifier/reward.txt
else
echo 0 > /logs/verifier/reward.txt
fi
solution/solve.sh looks up the order, reads the policy and files the review request. Run it once to confirm it earns a reward of 1. Then run the original, faulty behavior and confirm it earns 0. If the two runs earn the same reward, the verifier needs fixing.
One production failure is now a task any model can attempt. A model that issues the refund scores 0. A model that sends it to review scores 1. And every attempt leaves a trajectory you can read to see why.
Not every failed trace should become an environment
Three questions decide whether a trace is worth the work.
Did the agent decide wrong, or did the code around it break? The refund run is a good test of this question. In our demo project, the same symptom came from a configuration change: the limit was set to $2000 by mistake, so the refund tool itself skipped the review. No model behavior caused it, and no amount of training would fix it. That version of the failure belongs in a regression eval and a code fix. We covered that route in An agent evaluation framework you can trust. The traces that make good environments are the ones where the model had the information and the tools, and chose badly.
Can the right outcome be checked from final state? "The refund is pending review" is checkable. "The reply was empathetic" needs a judge model, which makes the reward noisier and easier to game.
Is the data safe to copy? Production traces contain real customers. The environment should keep the shape of the case and replace the names, emails and order numbers with synthetic ones.
The work pays off for failures that repeat, so group similar traces first and convert the groups with the most hits.
Where traceroot fits
traceroot is an open source, self-hostable platform for improving AI agents in production. Three parts of it cover the first half of this path.
Capture. Instrument the agent with the Python or TypeScript SDK and every run is recorded with its tool calls. This is the refund tool from the demo agent:
@observe(name="issue_refund", type="tool")
def issue_refund(order_id: str, amount_usd: float, reason: str) -> dict:
...
Find the failures worth converting. A detector is a model that reads each sampled trace and answers one yes-or-no question, such as "did the agent issue a refund above the limit without a supervisor review?" When a detector flags many traces for the same problem, traceroot groups them into one Signal, with the affected traces listed and a count over time. A Signal with a steady stream of hits is a ready-made shortlist of task candidates.
Take the trace with you. The CLI writes a trace to disk as plain JSON:
traceroot traces export <trace-id> --output ./refund-trace
The folder holds trace.json, spans.json with each span's input and output, and git_context.json with the commit the agent was running. Those files contain the instruction, the tool list and the path described above, in a form a script or a coding agent can read while it drafts the task.
The same SDK instruments any Python or TypeScript agent, so attempts inside an environment can be traced and read span by span the same way.
FAQ
What is an RL environment in AI?
An RL environment is the task, starting state, tools and verifier a model interacts with during reinforcement learning or evaluation, plus a reset that restores the starting state. The model attempts the task, the verifier returns a reward, and the reward is used to score the model or update its weights.
What is the difference between a trace and an RL environment?
A trace is a recording of one run that already happened. An RL environment is a task that can be attempted again and again from the same starting state, with a reward at the end.
What is the difference between a trace and a trajectory?
Both are step-by-step records of an agent's run. "Trace" is the observability term and usually refers to production, with spans, timing and cost. "Trajectory" is the RL term for one attempt inside an environment. Harbor writes trajectories as trajectory.json in the ATIF format.
What is the Harbor task format?
Harbor is an open source framework built by the team behind Terminal-Bench. It runs agents against packaged tasks in sandboxes and records a reward for each attempt. A Harbor task is a directory with an instruction, an environment definition, a test script that writes a reward, and a reference solution.
Can I train a model on production traces directly?
You can fine-tune on traces as examples, which teaches a model to imitate recorded runs, including their mistakes unless you filter them. Reinforcement learning needs more: the model has to act, see the result and receive a reward, and that takes an environment.
How many traces do I need before building an environment?
One clear failure is enough to build one task. Look for failures that repeat. A problem that shows up across many traces is more likely to reflect how the model behaves, and it gives you several real variations of the same task to build from.

