Notes

Episode

An episode is one complete attempt by an agent to interact with its environment: it starts from an initial situation, continues through actions and consequences, and ends when the task reaches a stopping point. A game of chess, one warehouse robot delivery run, or a single simulated lap around a track can each be treated as an episode.

What an episode contains

At each time step, the agent observes a state or observation, selects an action, receives a reward, and reaches a new situation. The resulting sequence is called a trajectory:

  • initial observation or state;
  • action chosen by the agent;
  • reward returned by the environment;
  • next observation, repeated until the episode ends.

The end is signalled by a terminal state, such as a robot reaching its destination, a game ending, or a cart falling over in Gymnasium’s CartPole environment. Environments also impose truncation: a run can be stopped because it hit a time limit, even though the underlying task did not truly end. Keeping termination and truncation distinct matters when calculating learning targets.

Why it matters for learning

For episodic tasks, the agent is commonly judged by its episode return: the sum of rewards collected from the beginning to the end, frequently with later rewards discounted. This is what lets reinforcement learning assign credit across time. An action that earns no immediate reward can still be valuable because it enables a high-reward outcome near the episode’s end.

Episodes also define practical training units. PPO commonly gathers batches of complete or fixed-length trajectory fragments before updating its policy; DQN stores individual transitions collected across many episodes in replay memory. A rising average episode return is useful evidence of progress, but it can conceal a reward-design bug: an agent might end episodes quickly because a shortcut accidentally pays more than completing the intended task.

Episodic versus continuing interaction

Not every reinforcement-learning problem has a natural finish. Temperature control or server scheduling can run indefinitely; these are continuing tasks. Training still uses artificial rollout boundaries for computation, but those boundaries should not be mistaken for genuine task completion. In an episodic setting, the reset after an episode is central: it provides fresh starting conditions and prevents the agent from treating one finished attempt as though it were part of the next.

An episode is one complete run of interaction between an agent and its environment, from an initial state to a terminal state or defined stopping point. It consists of a sequence of states, actions, and rewards, called a trajectory. Episodes define the unit over which episodic return is measured and provide complete experience for evaluating and improving a policy.

Think of playing a round of a video game. The round starts, you make choices, things happen, and eventually it ends: perhaps you win, lose, or run out of time. That complete round is an episode.

For a learning system, an episode is one full attempt at a task. A robot might start at one end of a maze and finish when it reaches the exit. A game-playing AI might begin a match and stop when the match is over. Each episode gives the system a chance to see how its choices turned out, then try to do better in the next one.