Agent Architectures: Control Loops, State & Planning › The Agent Loop

Michael BrenndoerferFebruary 4, 20266 min read
Language AI HandbookAll chapters
Part 48 of 67Tool Use and Agents
Chapter 367Agent Architectures: Control Loops, State & Planning › The Agent Loop
Reading section 2 of 11 · The Agent Loop · 6 minSection 2 of 11 · 6 min

Book contents

Section 2 of 11 · 6 min read

Agent Architectures: Control Loops, State & Planning › The Agent LoopOne section · Sections in this chapter2 / 11 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

At the heart of every agent architecture lies a control loop that governs the interaction between the language model and its environment. This pattern, often called the Observation-Thought-Action loop, gives the basic rhythm of agent execution. The concept draws inspiration from cognitive psychology and control theory, where intelligent behavior emerges not from static input-output mappings but from continuous interaction with an environment through feedback cycles.

The loop is the basic unit of agent cognition. Without it, an LLM is a advanced text completion engine that responds to a fixed input and halts. With it, the LLM becomes an actor situated in a dynamic world, capable of pursuing a goal across time by repeatedly sensing and reasoning before acting. The loop is what distinguishes reactive tools from purposeful agents.

The Basic Cycle

The agent loop operates through a continuous cycle of three basic operations.

Observation is the first stage of every iteration. The agent receives input from its environment: a user query, the result of a previous tool execution, an error message from a failed action, or a system event like a timeout. The observation grounds the agent in the current state of the world. This gives the raw material upon which decisions are made. Without accurate observation, the agent operates on false premises, much like a navigator trying to plot a course with an outdated map. Every piece of information the agent receives in this phase, no matter how small, shapes the subsequent reasoning.

Reasoning is where the cognitive work happens. The LLM processes the observation in the context of its goal and available tools, generating an internal representation of what needs to be done next. This might mean deciding which tool to call and with what arguments, recognizing that the goal is already achieved, or concluding that the current strategy is not working and should be replaced. The reasoning step turns raw observations into structured intentions. Critically, the quality of this step depends on everything that has come before it: the richness of the conversation history, the clarity of the current plan, and the relevance of information in working memory. A well-designed architecture ensures that the LLM has exactly what it needs for this reasoning step, no more and no less.

Action is the agent's attempt to change the state of the world based on its reasoning. Actions can take many forms: calling a tool and awaiting its result, generating a response for the user, updating internal state, or deciding to terminate. The action bridges intention and effect. It is the moment when the agent's internal deliberation becomes external consequence. Every action produces an outcome that becomes the next observation, closing the loop and beginning the next cycle.

This three-phase cycle repeats until a termination condition is met, which we discuss in detail later. Each iteration consumes the previous action's output as its observation input, creating a chain of dependent operations where the context evolves based on the history of interactions. This chaining creates temporal coherence, letting the agent to build upon previous work rather than starting fresh with each exchange. The agent accumulates understanding across iterations the way a researcher accumulates evidence across a literature review: each source adds a piece to a growing picture.

Loop Variants

Not all agent loops have the same structure. The complexity of the loop should match the demands of the task and the dynamics of the environment.

Single-step loops execute one thought-action pair per user query. The agent receives input, generates a plan, executes all necessary actions in a predetermined sequence, and returns. This works for simple tasks where the environment is predictable and actions are largely independent of each other. For example, an agent asked to calculate the total cost of items in a shopping cart might use a single-step loop: it reads the items, calls the calculator tool once, and returns the result. However, single-step loops struggle with dynamic environments where intermediate results should influence subsequent actions. If the agent needs to check inventory before calculating shipping, and shipping options depend on warehouse locations determined by inventory checks, a single-step approach cannot adapt its course based on what it discovers at each stage.

Multi-step loops allow the agent to iterate many times, using each action's result to inform the next decision. This makes reactive behavior possible: if a web search returns insufficient results, the agent can reformulate its query; if code execution fails, the agent can diagnose the error and retry with corrections. Multi-step loops create the possibility for true interaction with external systems, where the agent engages in a dialogue with the world, learning and adjusting as it goes. This resembles how a human researcher pursues a line of inquiry, following references, revising hypotheses, and adjusting the search strategy based on what each source reveals. The cost is complexity: multi-step loops require reliable state management and carefully designed termination conditions to prevent infinite cycles.

Hierarchical loops nest agent execution within higher-level planning. A top-level planner agent decomposes a complex goal into subtasks, then delegates each subtask to specialized worker agents, each running their own internal loops. The results from the workers feed back to the planner, which coordinates their efforts and resolves dependencies between outputs. This architecture mirrors organizational structures in human enterprises, where managers coordinate specialists who possess deep expertise in specific domains. A software development agent might have separate sub-agents for requirements analysis and code generation as well as testing and documentation, with a meta-agent sequencing their work and managing the handoffs between stages. Hierarchical loops introduce significant coordination overhead but enable the agent to tackle problems that are too large or complex for any single agent to handle.

The choice of loop structure depends on task complexity, the dynamics of the environment, and the cost constraints of the deployment. Simple information retrieval might use single-step loops, while autonomous research assistants require multi-step or hierarchical architectures to handle the uncertainty and branching paths inherent in exploratory tasks.

Why the Loop Matters

The loop embodies a philosophical shift in how we conceptualize language model capabilities. A single-shot LLM interaction is fundamentally limited by the quality of the input prompt: if the user does not frame the question correctly, or if the task requires information not present at query time, the model cannot compensate. The agent loop removes this limitation by letting the model to actively seek missing information, correct its own errors, and adapt its strategy to what it learns along the way.

This shift also changes how we think about failure. In a single-shot system, a poor answer is a dead end. In an agent loop, a poor action is a learning opportunity: the next observation reveals that the action failed, and the agent can reason about why and try something different. This error-recovery capacity is one of the most practically important properties of agent architectures, letting them to succeed at tasks where fixed sequences of actions would inevitably fail due to environmental variability.