Overview
SingleTurnEnv is a specialized version of MultiTurnEnv with max_turns=1. Each rollout follows this simple pattern:
- Send the prompt to the model
- Receive a single response (the completion)
- Score the response using reward functions
Your First Environment
Here’s a minimal single-turn environment for math problems:Real Example: Text Reversal
Let’s examine thereverse-text environment from the repository:
environments/reverse_text/reverse_text.py
- Uses
XMLParserto extract structured output from<reversed_text>tags - Computes continuous reward based on longest common subsequence
- Allows customization via
system_promptparameter
Advanced Patterns
Multiple Reward Functions
Combine multiple scoring criteria with custom weights:reward = 1.0 * check_keywords + 0.1 * length_reward
Parsing Structured Output
Use parsers to extract specific fields from model responses:Lazy Dataset Loading
For large datasets, defer loading until first access:- Avoid loading large datasets during environment initialization
- Better performance when running multiple replicas
- Parameterize dataset creation (splits, shuffling, filtering)
Metrics and Observability
Track additional metrics without affecting the reward:Evaluation Datasets
Provide separate train and evaluation datasets:prime eval run, the evaluation dataset is used automatically.
Common Patterns
Math Verification
Use symbolic math checking with the built-inMathRubric:
LLM-as-Judge
Use another LLM to score responses:Combining Multiple Rubrics
UseRubricGroup to combine different scoring approaches:
Testing Your Environment
After implementing your environment:Next Steps
- Multi-turn environments: Add turn-by-turn interaction → Multi-Turn Guide
- Tool use: Give your agent access to tools → Tool Environments Guide
- Training: Use your environment for RL training → Training Guide