agent-environment loop
/ AY-junt en-VY-run-munt loop /
The agent-environment loop is the heartbeat of reinforcement learning, and the whole field is built on it. Picture a player and a video game. At each moment the player (the agent) sees the screen (the state), presses a button (an action), and the game responds: the screen changes and the score ticks up or down (the next state and a reward). Then it happens again, and again, thousands of times. That endless cycle — observe, act, get a consequence, observe again — is the loop.
Said more precisely: the world is split into two pieces. The agent is the decision-maker we are trying to train; everything else is the environment. At each time step the environment hands the agent a state, the agent picks an action, and the environment returns a reward and a new state. The agent's only goal is to choose actions that pile up as much reward as possible over time. Crucially, the environment is a black box to the agent — it doesn't get told the rules, only the consequences of what it tries.
This framing matters because it is deliberately minimal. It makes no assumption about whether the agent is a robot, a game-player, a thermostat, or a recommendation system — anything that takes actions and lives with the results fits. The flip side is that drawing the line between agent and environment is a modeling choice, not a fact of nature, and a sloppy choice (a misleading state, a reward that doesn't capture what you actually want) quietly poisons everything downstream.
A robot vacuum: state = where it is and what its sensors see; action = move forward, turn, or dock; reward = +1 for each new patch of floor cleaned, -1 for bumping a wall. Over many runs it learns a route that cleans the most while bumping the least.
One turn of the loop: observe state, choose action, receive reward and next state — repeat.
What counts as 'the agent' is the part you can change by learning; everything you can't is environment. Drawing that boundary wrong — say, hiding crucial information from the state — can make a problem unlearnable, even with a perfect algorithm.