Kreisförmiges Ablaufschema einer Agentenschleife: Von einem zentralen Kasten namens Loop State führen Pfeile zu den Stationen Planen, Aktion ausführen und Ergebnis auswerten und wieder zurück zum Loop State; eine Abzweigung mit der Prüfung Ziel erreicht führt aus der Schleife heraus zur Ausgabe.

Loop State

The loop state is the collection of all information a program retains between two passes of a repeating sequence of work steps. In AI systems that work on a task across multiple rounds, this carried-over intermediate state determines whether the system makes progress or spins in circles.

Many programs repeat the same sequence of work steps over and over until a goal is reached. Such a repetition is called a loop. So that the repetition doesn’t start from scratch with every pass, the program has to remember certain things: how many rounds have already run, what has come out so far, what is still open. Precisely this carried-over information, taken together, is called the loop state. You can picture it as a notepad that gets updated after each round and carried into the next round. Without this notepad, every round would be a fresh start with no memory.

Why loops without memory fail

Modern AI systems often don’t solve tasks in a single step. A system might, for example, be tasked with planning a trip: searching for flights, comparing prices, finding a hotel, and combining everything into a single proposal. Such systems are called agents. They run through the same basic loop multiple times: think, execute an action, look at the result, continue. The loop state is the link between the rounds.

If this intermediate state is poorly maintained, typical errors arise. The system searches for the same flight three times because it didn’t retain the first result. Or it considers a task done even though a sub-step failed. Both cost money, because every pass consumes compute time. Commercial services bill per request, so a poorly built loop shows up directly on the bill.

The state also determines the ending. At some point the loop must terminate, otherwise it runs forever. The termination condition almost always checks the loop state: Has the goal been reached? Have ten rounds passed? Is the result repeating? A state that stores the wrong things makes a meaningful termination check impossible.

What’s on the notepad

A loop state usually consists of several clearly named fields. Typical ones include a counter for the round number, the original task, a list of the steps taken so far and their results, and a flag noting whether the goal has been reached. In text models, the conversation history so far is often added as well. These fields are updated at the end of each round and read at the beginning of the next.

It’s important to distinguish this from the context window. The context window is the limited amount of text a language model can read at once. The loop state exists outside of that, in the regular program. It can contain far more than what is ever sent to the model. Before each round, the program selects which part of the state fits into the context window. This selection is one of the hardest decisions in building such systems.

A common misconception is that the state is simply the entire history so far. In practice, it is heavily condensed. Long results get summarized, completed sub-tasks get removed from the active list. Otherwise the state would grow with every round, and beyond a certain point the system would no longer be able to find the important information in its own clutter.

Loop state in agent frameworks and products

Anyone looking at programming tools for AI agents encounters the term immediately. Libraries like LangGraph build their entire logic around a state object that is passed along from step to step. Developers there explicitly define which fields exist and how they change per round. The state is thus not a byproduct, but the central blueprint.

Users, too, notice the consequences without ever hearing the term. When an AI coding assistant fixes a bug, tests the result, and tries again on failure, it internally carries a loop state along. If it gives up after several attempts and reports that it can’t proceed, a termination condition has triggered on that state. If, on the other hand, the same assistant spins in circles and proposes the same solution three times, the state is obviously incomplete.

In articles and company announcements, the term usually comes up in connection with reliability. Providers advertise that their agents can sustain longer chains of tasks. Behind this is almost always better state management, not a smarter language model. Anyone trying to make sense of such announcements should therefore pay attention to how a system organizes its intermediate state.

Related Products

Latest News

Subscribe free. Unsubscribe the second it sucks.

High-signal news across AI, business, UX, and tech. Every morning.