← govind p lal
AI and ML Bootcamp · Lecture 17 · lecture notes

RL ENVIRONMENTS FOR LLMs

In short — What is an RL rollout and rubric together; where a model is trained or evaluated.">environment, and why are labs and startups spending so much on them? An environment is a dataset, a rollout and a rubric. The same pieces can train, evaluate and generate data. A basic one takes about 50-60 lines to build. Reward hacking and output parsing are the main pitfalls.

Why environments matter

builds on Lecture 16: Week 15 - AI&ML | RLVR | 25/04/2026, Lecture 15: Week 14 - AI&ML | Fine-tuning - Part 3 | 17/04/2026

Environment - the place where a model is trained and evaluated. Classic RL already had them: gym / gymnasium for Atari, chess, Go.

Build one good environment once. Reuse it many ways. Why the hype: every lab goes through post-training. More and better environments (coding, maths, science, computer use, browser use) means better models. Example: Intellect-3 from Prime Intellect, trained on a fully open-source stack.

Open-source angle: find a task where models are weak, turn it into an environment, publish it. A lab may use it in its next training run.

Mapping classical RL to an LLM

adds to earlier · Concrete state/action/environment/policy mapping to a chat window · builds on Lecture 15: Week 14 - AI&ML | Fine-tuning - Part 3 | 17/04/2026
RL termMeaningIn an LLM chat
StateWhere the agent currently isConversation history, steps taken so far
ActionWhat the agent does nextNext token or full response
EnvironmentReturns next observation and rewardThe chat window / task setup
RewardDid it do good or bad, and how muchScore on the evaluation task
PolicyBrain of the agentThe LLM powering it

The environment trinity: dataset, rollout, rubric

builds on Lecture 15: Week 14 - AI&ML | Fine-tuning - Part 3 | 17/04/2026
inputresponsescorenext stepDatasetprompts + answersRolloutmodel acts, env respondsRubricscores the resultReward
Environment loop: data in, rollout, rubric scores, repeat.
PartSchool exam analogyRole
DatasetList of questionsInput to the environment
RolloutStudent's answers (and retries after feedback)The whole loop of action, next state, reward
RubricHow the teacher gradesAssigns reward

Rubric varies by task. MCQ or one-word answer -> exact match. Subjective maths paper -> partial marking for steps. Real datasets: GSM8K, Tau-bench, SWE-bench, BrowseComp (school maths to PhD maths, GitHub issues, research, computer use).

Types of rollout

builds on Lecture 9: Week 8 - AI&ML | From APIs to Agents | 07/03/2026, Lecture 9: Week 8 - AI&ML | From APIs to Agents | 07/03/2026
!

Single-turn environments are mostly used for benchmarks and evaluation. Multi-turn, tool use, computer use and browser use are where real RL training happens. For both, build both versions.

Types of rubric

adds to earlier · Three rubric types and their use cases · builds on Lecture 16: Week 15 - AI&ML | RLVR | 25/04/2026, Lecture 15: Week 14 - AI&ML | Fine-tuning - Part 3 | 17/04/2026

Reward hacking

adds to earlier · LLM-judge essay example, why verifiable rewards resist hacking (step function) · builds on Lecture 15: Week 14 - AI&ML | Fine-tuning - Part 3 | 17/04/2026

Reward hacking - the model finds a shortcut that earns reward without doing the real task.

Example

Task: judge essays. Judge rule: a certain style of opening gives +3 points. The model learns that starting every response with that phrase earns +3 regardless of content. Rewards climb. Real essay-judging skill stays the same. Similar: starting with "great question".

Why verifiable rewards are unhackable (in principle)

!

If an environment has any edge case, the model will find it and exploit it. Money gets wasted while the model improves at nothing. Always compare rewards with a real evaluation.

Evaluating harnesses: Terminal-Bench

builds on Lecture 9: Week 8 - AI&ML | From APIs to Agents | 07/03/2026

Terminal-Bench - benchmark of tasks for coding agents (Codex, Claude Code, OpenCode, etc.) working in a terminal.

Open-source ecosystem

!

Environments do not depend on the RL framework. The same environment works in prime-rl, TRL or on Tinker. (Portable)

Building an environment from scratch

builds on Lecture 9: Week 8 - AI&ML | From APIs to Agents | 07/03/2026

Pipeline: problem -> rollout (model writes code) -> sandbox runs tests -> rubric score.

Problem

First run gave 0% passing even on trivial problems. The code was correct, but the model wrapped it in markdown backticks. Backticks are invalid Python syntax, so every test errored.

Solution

Add a parser: strip the backticks and other wrapping, then run. Pass rate then became correct.

!

Parser - component that pulls structured information (runnable code) out of unstructured model output. Real environments need one. Even the biggest environment is just dataset + rollout + rubric at its core.

Same environment with the verifiers library

~70-80 lines of raw code became ~30 lines. Same behaviour; better abstractions, async runs, parsers (strips XML tags and thinking), hub sharing, direct link to prime-rl training.

Multi-turn and comparing models

Multi-turn: model writes code, failure output goes back to it, it fixes the code, repeat until it passes or max turns is reached. In verifiers you define how the environment responds and an is-completed condition (all turns used or task done).

ModelPass rate
Gemini100%
GPT-4o mini60%
Small open model20%

Differences come from output format: some models add backticks, others need much more parsing. With an existing dataset (e.g. GSM8K) you only write the rollout and rubric.

Training later: GRPO. Run several rollouts per prompt, use the group average to update the policy.

What to build and what to explore

builds on Lecture 15: Week 14 - AI&ML | Fine-tuning - Part 3 | 17/04/2026

Outcome reward model (ORM) - reward on the final output. Process reward model (PRM) - reward on every step, e.g. each step of a maths solution. Also read: elicit vs create debate, sandboxes (systems), synthetic data generation.

Glossary

Environment
Dataset, rollout and rubric together; where a model is trained or evaluated.
Rollout
How the model interacts with the dataset: actions, next states, feedback.
Rubric
The function that assigns reward to a rollout.
Reward hacking
Exploiting rubric flaws to get reward without real capability gain.
Sandbox
Isolated machine where model-generated code runs safely.
Parser
Component that extracts structured, usable output from raw model text.
verifiers
Prime Intellect library for building RL environments.
Harness
The agent scaffold around a model, such as a terminal coding agent.