Environment
An environment is everything in a reinforcement-learning task that the learner does not directly control: the world it acts in, the rules that govern what happens next, and the feedback it receives. It can be as small as a grid maze or as complex as a physics simulator for a robot.
The other half of the learning loop
At each time step, the agent selects an action. The environment responds by producing a new observation (or state), a scalar reward, and possibly a signal that the episode has ended. Formally, the environment determines the task’s dynamics: given the current situation and action, it specifies what can happen next. These outcomes can be deterministic, such as moving one square north in a simple maze, or stochastic, such as a slippery surface causing an intended movement to miss its target.
What the environment defines
The environment is not merely a container around an algorithm. Its design fixes what the agent can learn and what “good behaviour” means:
- Observations: the information available for choosing actions.
- Action space: the choices the agent is allowed to make.
- Rewards: the objective signal, including unintended incentives.
- Dynamics and termination: how actions change the world and when a trial ends.
Why it matters in practice
Unlike labelled-data learning, reinforcement learning gets its training data by interacting with the environment. A policy therefore changes the experiences it collects. In a Gymnasium environment, DQN or PPO learns from repeated calls to step(action); poor reward design, unrealistic simulation dynamics, or observations missing crucial information can produce a policy that looks strong in training and collapses when conditions shift. Careful environment design and evaluation are therefore part of building the learning system, not setup work around it.
In reinforcement learning, the environment is everything outside the agent that receives its actions, changes in response, and returns observations and rewards. It defines the task’s dynamics, available feedback, and termination conditions. The environment matters because it determines what the agent can learn from interaction: its transition and reward structure shape which behaviours are valuable and how difficult they are to discover.
Think of a child learning to play a new video game. The screen, rules, obstacles, points, and other players are all the world the child has to deal with. In reinforcement learning, that world is called the environment.
The environment is everything outside the learner that responds to its choices. A robot’s environment might be a warehouse; a self-driving car’s could be a road full of traffic; a game-playing program’s is the game itself. The learner acts, the environment changes, and it may give a reward or penalty. The environment is what makes decisions matter: it provides the situations, consequences, and feedback the learner must learn to handle.