Skip to main content

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:
Or when developing in the verifiers repo:
See the TextArena integration guide for setup details.

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

Initialize TextArena environment for this rollout. Implementation details:
  • 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

Process model’s guess and return game feedback. Flow:
  1. Parse guess from latest message using parser.parse_answer()
  2. Step the TextArena environment with the guess
  3. If game is done, set state["final_env_response"] and return terminal message
  4. Otherwise, get observation and apply feedback_fn before returning

cleanup_ta_env

Clean up TextArena environment after rollout by removing ta_env from state.

Example Usage

Basic Wordle Environment

Custom Feedback Function

Custom Parser and Rubric

TwentyQuestions Game

Memory Optimization

TextArenaEnv uses build_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.
This optimization is automatic and requires no user configuration.

Available Games

Some popular TextArena games:
  • Wordle-v0 - Classic word guessing game
  • TwentyQuestions-v0 - 20 questions game
  • Poker-v0 - Poker game
  • Many more available in the TextArena repository
Check the TextArena documentation for the full list of available games.

See Also