Overview
A rollout is a complete interaction sequence from initial prompt to final completion, including all model responses, environment feedback, tool executions, and computed rewards. Each rollout produces aState object that tracks the full interaction history.
Rollout Lifecycle
Every rollout follows this sequence:1. State Initialization
2. Setup State (Per-Rollout Initialization)
- Creating per-rollout resources (sandbox sessions, game state)
- Initializing environment-specific state fields
- Queueing asynchronous setup (e.g., sandbox provisioning)
3. Rollout Loop
ForMultiTurnEnv and subclasses:
get_prompt_messages()- Build messages for modelget_model_response()- Call model APIadd_model_response()- Record in trajectoryis_completed()- Check all stop conditions
4. Completion Rendering
5. Cleanup
@vf.cleanup handlers are called after is_completed() returns True.
6. Scoring
state["reward"], state["advantage"], and state["metrics"].
State Object
Type Definition
Field Forwarding
AccessingINPUT_FIELDS automatically forwards to nested input object:
Usage Tracking
Custom State Fields
Environments can add arbitrary fields:Trajectory
Thetrajectory field records every turn in multi-turn rollouts:
TrajectoryStep Type
Accessing Trajectory
Custom Trajectory Handling
Overrideadd_trajectory_step() to customize metadata:
Token-Level Data
For RL training, trajectories include token IDs and logprobs:Stop Conditions
Stop conditions are checked after every model response viais_completed():
Built-in Stop Conditions
MultiTurnEnv includes:
ToolEnv adds:
Custom Stop Conditions
Stop Condition Behavior
When any stop condition returnsTrue:
state["is_completed"] = Truestate["is_truncated"]set if any trajectory step was truncatedstate["stop_condition"]set to condition name- Timing fields updated
- All
@vf.cleanuphandlers called - Loop exits
Error Handling
Error Hierarchy
Automatic Error Catching
Allvf.Error exceptions raised during rollout are caught and stored:
Configurable Tool Error Handling
Error Access
Timing
Rollout timing is tracked automatically:start_timeset ininit_state()generation_mscomputed when stop condition triggersscoring_mstracked by rubrictotal_ms = generation_ms + scoring_ms
RolloutInput and RolloutOutput
RolloutInput
Input format for rollouts:RolloutOutput
Serialized output from rollouts:Generation and Evaluation
Generate Method
Evaluate Method
Progress Callbacks
Monitor generation progress:Result Persistence
Saving Results
Resuming Evaluations
Pushing to HuggingFace Hub
When resuming evaluations, the framework validates that environment configuration (env_id, model, num_examples, rollouts_per_example) matches the saved metadata to prevent accidental mixing of results.
Advanced Rollout Customization
Custom Prompt Messages
Overrideget_prompt_messages() for non-linear conversations:
Custom Completion Rendering
Overriderender_completion() for custom output extraction:
Intermediate Rewards
Set per-turn rewards viaadd_trajectory_step():