Skip to main content

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 a State object that tracks the full interaction history.

Rollout Lifecycle

Every rollout follows this sequence:

1. State Initialization

Initial state fields:

2. Setup State (Per-Rollout Initialization)

Called before the rollout loop begins. Used for:
  • Creating per-rollout resources (sandbox sessions, game state)
  • Initializing environment-specific state fields
  • Queueing asynchronous setup (e.g., sandbox provisioning)

3. Rollout Loop

For MultiTurnEnv and subclasses:
Turn sequence:
  1. get_prompt_messages() - Build messages for model
  2. get_model_response() - Call model API
  3. add_model_response() - Record in trajectory
  4. is_completed() - Check all stop conditions

4. Completion Rendering

Extracts final conversation from trajectory. Default behavior:

5. Cleanup

All @vf.cleanup handlers are called after is_completed() returns True.

6. Scoring

Sets state["reward"], state["advantage"], and state["metrics"].

State Object

Type Definition

Field Forwarding

Accessing INPUT_FIELDS automatically forwards to nested input object:

Usage Tracking

Custom State Fields

Environments can add arbitrary fields:

Trajectory

The trajectory field records every turn in multi-turn rollouts:

TrajectoryStep Type

Accessing Trajectory

Custom Trajectory Handling

Override add_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 via is_completed():

Built-in Stop Conditions

MultiTurnEnv includes:
ToolEnv adds:

Custom Stop Conditions

Stop Condition Behavior

When any stop condition returns True:
  1. state["is_completed"] = True
  2. state["is_truncated"] set if any trajectory step was truncated
  3. state["stop_condition"] set to condition name
  4. Timing fields updated
  5. All @vf.cleanup handlers called
  6. Loop exits

Error Handling

Error Hierarchy

Automatic Error Catching

All vf.Error exceptions raised during rollout are caught and stored:

Configurable Tool Error Handling

Error Access

Timing

Rollout timing is tracked automatically:
Timing flow:
  1. start_time set in init_state()
  2. generation_ms computed when stop condition triggers
  3. scoring_ms tracked by rubric
  4. total_ms = generation_ms + scoring_ms

RolloutInput and RolloutOutput

RolloutInput

Input format for rollouts:

RolloutOutput

Serialized output from rollouts:
Conversion:

Generation and Evaluation

Generate Method

Returns:

Evaluate Method

Progress Callbacks

Monitor generation progress:
Callback signature:

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

Override get_prompt_messages() for non-linear conversations:

Custom Completion Rendering

Override render_completion() for custom output extraction:

Intermediate Rewards

Set per-turn rewards via add_trajectory_step():
Intermediate rewards are advanced features primarily used for RL training. For most evaluation use cases, final rewards computed by the rubric are sufficient.