TextArena is currently undergoing an update over the next 12 hours. If you face any issues, please try again later.

Action Wrapper

textarena.core.ActionWrapper(env: Env)

The ActionWrapper modifies actions before they are passed to the environment, allowing customization of behavior and ensuring actions remain within valid bounds.

Methods:

  • step(action: str) -> Tuple[bool, Info]: Applies a transformation to the action and passes it to the environment.
  • action(action: str) -> str: Transforms or preprocesses the given action.

Available Action Wrappers

ClipWordsActionWrapper

textarena.wrappers.ClipWordsActionWrapper(env: Env, max_num_words: int)

The ClipWordsActionWrapper limits actions to a specified maximum number of words. If the action exceeds this limit, it is truncated to the allowed number of words.

Example Usage:

# Example usage:
env = ClipWordsActionWrapper(base_env, max_num_words=5)
action = "move north with speed boost and be quick"
truncated_action = env.action(action)  # Output: "move north with speed boost"

ClipCharactersActionWrapper

textarena.wrappers.ClipCharactersActionWrapper(env: Env, max_num_characters: int)

The ClipCharactersActionWrapper limits actions to a specified maximum number of characters. If the action exceeds this limit, it is truncated to the allowed number of characters.

Example Usage:

# Example usage:
env = ClipCharactersActionWrapper(base_env, max_num_characters=7)
action = "move north with speed boost and be quick"
truncated_action = env.action(action)  # Output: "move no"