# How to Create New Environments This guide explains how to create new environments for VAGEN using **Blackjack** as an example. Understanding the BaseEnv interface is key to building effective LLM training environments. > For the specific rules of Blackjack, please refer to [Blackjack Rules](https://en.wikipedia.org/wiki/Blackjack). > For the gym-formated Blackjack details, please refer to [Blackjack-v0](https://gymnasium.farama.org/environments/toy_text/blackjack/). ## Directory Structure ``` vagen/env/blackjack/ ├── env.py # BlackjackEnv - main environment wrapper ├── env_config.py # BlackjackEnvConfig - configuration class ├── prompt.py # Prompt templates and format configurations ├── blackjack.py # Core gym environment (standard gym interface) └── __init__.py # Environment registration ``` **File Responsibilities:** - `blackjack.py`(Optional): Your core game logic (usually a standard gym environment) (`step`, `reset`) - `env_config.py`: Configuration parameters and settings for your environment - `env.py`: VAGEN wrapper that bridges LLM responses to your game logic - `prompt.py`: System prompts and LLM interaction format definitions - `__init__.py`: Registration info to make your environment discoverable by VAGEN ## Understanding BaseEnv Interface VAGEN environments inherit from `BaseEnv`, which defines the contract between your game logic and the LLM training system. Here's what each required method does: ### Core Methods Overview **`step(llm_raw_response)`** - The heart of LLM interaction - Takes the raw text response from the LLM (e.g., `"I should hitHit"`) - Parses it to extract valid actions (e.g., `["Hit"]`) - Executes actions in your game - Returns the next observation, reward, completion status, and metrics **`reset(seed)`** - Initialize a new episode (these seeds are read from train/test parquet file) - Resets the game to starting state - Uses seed for reproducible episodes - Returns initial observation for the LLM **`system_prompt()`** - Define the LLM's role - Returns the system prompt that tells the LLM what game it's playing - Includes rules, available actions, and formatting instructions **`close()`** - Clean up resources - Called when the environment is no longer needed **`compute_reward()`** - Optional final reward - Usually returns 0.0 since step rewards are accumulated - Use only if you need extra reward at episode end ## Key Data Structures ### Observation Format Every observation must follow this structure: ```python { 'obs_str': "You see showing your cards. The dealer shows .", 'multi_modal_data': { '': [player_cards_image, dealer_card_image], '