TextArenaEnv
Wrapper environment for TextArena text-based games.Overview
TextArenaEnv wraps TextArena game environments for multi-turn interaction with language models. It automatically converts TextArena games into Verifiers datasets and handles game state management.
Key features:
- Automatic dataset generation from TextArena word lists
- Efficient memory sharing for parallel rollouts
- Custom feedback transformation via
feedback_fn - Built-in XML parser for structured responses
Installation
Install with TextArena support:Inheritance
Constructor
Parameters
str
default:"Wordle-v0"
TextArena game ID (e.g., “Wordle-v0”, “TwentyQuestions-v0”).
int
default:"1000"
Number of training examples to generate.
int
default:"0"
Number of evaluation examples to generate.
str | None
default:"None"
System prompt for the model. If None, uses default from MultiTurnEnv.
vf.XMLParser | None
default:"None"
Parser for model responses. If None, uses
XMLParser(fields=["think", "guess"], answer_field="guess").vf.Rubric | None
default:"None"
Rubric for scoring. If None, uses default rubric.
Callable[[str], str]
default:"lambda x: x"
Function to transform TextArena observations before presenting to the model. Use this to filter or reformat game state messages.
int
default:"0"
Random seed for dataset generation.
Any
Additional arguments passed to MultiTurnEnv.
Key Methods
setup_state
- Creates a deep copy of the TextArena environment with memory sharing optimization
- Sets the secret word from
state["answer"] - Stores environment in
state["ta_env"]
env_response
- Parse guess from latest message using
parser.parse_answer() - Step the TextArena environment with the guess
- If game is done, set
state["final_env_response"]and return terminal message - Otherwise, get observation and apply
feedback_fnbefore returning
cleanup_ta_env
ta_env from state.
Example Usage
Basic Wordle Environment
Custom Feedback Function
Custom Parser and Rubric
TwentyQuestions Game
Memory Optimization
TextArenaEnv usesbuild_shared_memo() to share immutable data across environment copies:
- Problem: TextArena’s EnglishDictionary holds ~430K strings in 4 sets (~38MB). Without sharing, each rollout copies this data (~120ms + 38MB per copy).
- Solution: The shared memo dict allows deep copying to share these immutable objects, saving significant memory and time during parallel rollouts.
Available Games
Some popular TextArena games:Wordle-v0- Classic word guessing gameTwentyQuestions-v0- 20 questions gamePoker-v0- Poker game- Many more available in the TextArena repository
See Also
- TextArena Integration Guide - Setup and configuration details
- MultiTurnEnv - Base class documentation
- XMLParser - Parser for structured responses
- Wordle Example - Complete example environment