Observation space

On this page 7

An observation space is the set of all possible observations that an environment can return to an agent, together with their data type, shape and value bounds. At every time step, the agent receives one element of this space and uses it as the input to its policy or value function.

In reinforcement learning, the observation space is part of the interface between agent and environment, alongside the action space and the reward signal. It is distinct from the state space: the state is the complete description of the environment, while the observation is what the agent actually perceives, which may be partial, noisy or transformed. Designing it well is one of the most consequential engineering decisions in an RL project.

How an observation space is defined

An observation space is defined formally as a mathematical set with a structure that the learning algorithm can rely on. In widely used toolkits such as Gymnasium, the space is declared as an object that specifies its type, its dimensions and its bounds, and it offers methods to sample random elements and to check membership of a given observation.

This declaration serves two purposes. It tells the algorithm how to build the input layer of the neural network or the table of a tabular method, and it lets the environment validate its own outputs during testing. The most common space types are summarized below.

Space typeContentsTypical example
BoxReal-valued or integer arrays with lower and upper boundsJoint angles, velocities, image pixels
DiscreteA single integer from a finite rangeCell index in a grid world
MultiDiscreteSeveral integers, each with its own rangePositions of several game pieces
MultiBinaryA fixed-length vector of zeros and onesSensor on and off flags
Dict and TupleNamed or ordered collections of subspacesCamera image plus robot proprioception
Common observation space types

Observation space versus state space

The observation space and the state space coincide only in fully observable environments, where the observation contains everything needed to predict the future. In such cases the problem is a Markov decision process, and the agent can act optimally using the current observation alone.

In many practical problems the agent sees only part of the state, which turns the task into a partially observable Markov decision process (POMDP). A poker agent cannot see the opponents’ cards, and a robot camera cannot see behind obstacles. The agent must then infer hidden information from the history of observations.

ConceptWhat it containsWho sees it
State spaceComplete description of the environmentThe environment or simulator
Observation spaceSignals emitted to the agentThe agent
Belief stateProbability distribution over statesAn agent that models uncertainty
Action spaceChoices available to the agentThe agent, as output
Comparison of related concepts

Common remedies for partial observability include frame stacking, where several recent observations are concatenated, and recurrent or transformer policies that carry memory across steps. Both effectively enlarge the observation the policy conditions on.

Designing a good observation space

A well-designed observation space contains the information that is necessary for the decision and as little irrelevant detail as possible. Missing information makes the task unsolvable or forces the agent to learn memory, while excessive dimensions slow learning and invite spurious correlations.

Practitioners typically make several decisions when building the observation, each with a clear trade-off between learning speed and robustness. The table below lists the main choices.

Design choiceBenefitRisk
Raw pixelsNo manual feature engineeringHigh sample cost and slow training
Engineered featuresCompact and fast to learn fromDesigner may omit useful signals
NormalizationStable gradients and comparable scalesRunning statistics can drift
Frame stackingCaptures velocity and short historyLarger input dimension
Privileged informationFaster learning in simulationUnavailable on real hardware
Design choices and their effects

Normalizing observations to roughly zero mean and unit variance is one of the most reliable improvements for continuous control. Bounds in a Box space are often set to infinity for velocities, so the normalization must be estimated from data rather than taken from the declared limits.

Observation spaces in practice

Observation spaces vary greatly across application areas. Classic Atari benchmarks in the Arcade Learning Environment use stacks of downsampled grayscale frames, often four frames of 84 by 84 pixels. Continuous control tasks use vectors of tens to a few hundred numbers describing positions and velocities.

Robotics frequently combines camera images with proprioceptive signals such as joint encoders and force sensors in a dictionary space. In multi-agent reinforcement learning, each agent usually has its own observation space, which may include partial views of other agents. When language models are trained with reinforcement learning, the observation is the token sequence of the prompt and context.

The observation space also shapes the choice of network architecture. Image observations call for convolutional encoders, vector observations work well with small multilayer perceptrons, and dictionary spaces need a separate encoder per subspace whose outputs are concatenated. Discrete observations are usually one-hot encoded or embedded before they reach the policy, because feeding raw integer indices implies an ordering that does not exist.

Observation wrappers are the standard way to transform a space without changing the environment itself. Typical wrappers resize and grayscale images, clip outliers, stack frames or flatten dictionaries, and each wrapper must update the declared space so that downstream code sees a consistent definition.

Common mistakes and failure modes

Many failed RL experiments trace back to the observation rather than to the algorithm. The following problems appear repeatedly in practice and are often hard to diagnose because training still runs without errors.

  • Information leakage: the observation reveals the answer, such as a time counter that predicts episode end.
  • Missing temporal information: a single frame hides velocity, so the policy cannot anticipate motion.
  • Mismatched scales: one feature in thousands and another in fractions dominates the network input.
  • Sim-to-real gaps: simulated observations are cleaner than real sensor data, so the policy fails on hardware.
  • Inconsistent declarations: the environment returns values outside the declared bounds or with the wrong data type.

Explained without jargon

An observation space describes what a learning agent can see. Think of a driver in a car. The driver sees the road, the mirrors and the speedometer. The driver cannot see around corners.

The observation space lists all such signals and their possible values. A good one gives the agent exactly what it needs to decide. Too little, and the agent guesses. Too much, and it gets distracted and learns slowly.

A typical use case

A warehouse automation team trains a robotic arm in simulation to pick boxes from a conveyor. Their first observation space contains only a 64 by 64 camera image, and after millions of steps the arm still misses moving boxes because a single image does not show their speed.

The team redesigns the observation as a dictionary space with the image, two stacked previous frames, the seven joint angles and gripper force readings, all normalized with running statistics. They also remove the exact box coordinates that the simulator had leaked into an earlier version. With the revised design, the policy reaches a pick success rate above 90 percent in simulation in a fraction of the previous training time, and it transfers to the physical arm after modest fine-tuning.