Overview

Wrappers offer a flexible approach to enhancing or modifying an existing environment without changing its core implementation. By leveraging wrappers, you can reduce redundant code, promote modularity, and streamline your workflow. A significant advantage of wrappers is their ability to be stacked, allowing you to combine multiple enhancements seamlessly.

To apply a wrapper, you first need to initialize the base environment. Afterward, you can instantiate the wrapper by passing the environment and any required parameters to its constructor.

Python
1# Example usage:
2import textarena as ta
3
4env = ta.make(env_id="UltimateTicTacToe-v0")
5env = ta.wrappers.LLMObservationWrapper(env=env)
6env = ta.wrappers.PrettyRenderWrapper(
7 env=env,
8 record_video=True,
9 video_path="ultimatetictactoe_game.mp4"
10)

There are three common things you might want a wrapper to do:

  • Transform actions before applying them to the base environment
  • Transform observations that are returned by the base environment
  • Apply a render to base environment for friendly visualisations

Base Wrapper Class

class textarena.core.Wrapper(env: Env)

[source]

The base class for environment wrappers. It intercepts all calls to the wrapped environment and forwards them unless explicitly overridden.

Methods

Wrapper.step(action: str) -> Tuple[bool, Info]

[source]

Executes a single step in the environment based on the action provided by the agent.

Wrapper.reset(seed: Optional[int])

[source]

Resets the environment and initializes it with a given seed. If no seed is provided, a random one is used.

The reset method is critical for initializing the environment to a consistent state, ensuring reproducibility when a seed is provided.

Wrapper.get_observation(self)

[source]

Retrieves the current player ID and their observations, providing insights into the current state of the environment.

Wrapper.close(self)

[source]

Closes the environment and performs cleanup operations. This is essential for releasing resources or saving final states.