Agent Loop
Agent Loop is a core operational architectural pattern in autonomous agent systems, referring to the working mechanism by which an agent completes complex tasks through continuous cyclic execution of steps such as perception, reasoning, action, and observation. In each iteration, the agent invokes a large language model for reasoning, generates action instructions, calls tools or interacts with the environment, and feeds the results as new input into the next reasoning round until the goal is achieved or a termination condition is met. This pattern is a foundational design principle for agent frameworks such as ReAct and AutoGPT.
Core Facts
The underlying operational logic of an Agent Loop is an iterative cycle of 'perception–planning–action–observation.'
Common termination strategies for Agent Loop include three layers: semantic termination (such as detecting the Final Answer marker), an iteration limit (max_iterations typically defaults to 10–15), and timeout protection (the timeout parameter).
Claude Code's Agent Loop is responsible for sending user messages to the Claude model, parsing the tool-call instructions returned by the model, executing tool operations, and feeding the results back to the model for iterative execution.
Timeline (last 90 days)
In a cloud Agent architecture, the Agent Loop does not run inside the sandbox; the Agent and the sandbox are separate.
Both the Claude Agent SDK and the OpenAI Agents SDK take over the Agent Loop, greatly simplifying the model invocation, tool dispatching, history maintenance, and loop control logic that previously had to be written by hand.
Every round of calls sends the complete conversation history again, so the longer the task, the larger the context, and the slower and more expensive the calls become.
The termination logic of an Agent Loop is to loop until the model no longer initiates any tool calls.
After receiving a request, the model may return a structured tool call rather than directly providing an answer.
Large language models are responsible for thinking and decision-making but never directly execute actions themselves; the code outside the model is what actually executes the actions.
When an application sends a user request to the model, it includes a list of tools the model can use, with each tool having a name and an input schema.
A turn limit and a budget should be set for the Agent loop to prevent it from getting stuck in an infinite loop and to avoid runaway costs.
The essential differences between an Agent Loop and a single LLM API call can be structurally compared across four dimensions: lifecycle, tool invocation, memory, and deliverables.
The Maker/Checker pattern is an important basis for designing exit conditions in an Agent Loop; only when the Checker passes verification is the loop allowed to terminate and deliver results.
26 more timeline events
All Facts (20)
The underlying operational logic of an Agent Loop is an iterative cycle of 'perception–planning–action–observation.'
80%VerifiedCommon termination strategies for Agent Loop include three layers: semantic termination (such as detecting the Final Answer marker), an iteration limit (max_iterations typically defaults to 10–15), and timeout protection (the timeout parameter).
65%Unverified在Agent Loop中如果只将工具结果塞回messages而漏掉assistant消息,模型会陷入无限循环,不断重复调用工具
90%UnverifiedA typical Agent execution loop includes perception, reasoning, action, and observation, forming the ReAct (Reasoning + Acting) pattern
85%UnverifiedAgent Prompt模板通常包含四个部分:System Message、Chat History、User Input和Agent Scratchpad
85%Partially VerifiedClaude Code's Agent Loop is responsible for sending user messages to the Claude model, parsing the tool-call instructions returned by the model, executing tool operations, and feeding the results back to the model for iterative execution.
65%UnverifiedThe "Loop" in Loop Engineering and the "Loop" in Agent Loop are not the same concept: the former is a loop of multiple Skill calls and multi-Agent collaboration, while the latter is a loop of tool calls and reasoning.
60%UnverifiedIn multi-step tasks, small errors at individual steps accumulate progressively into a snowball effect, where errors in early steps contaminate the input context of subsequent steps
60%UnverifiedThe project uses an Agent loop (ReAct architecture) to allow the LLM to autonomously determine the next action based on the current page state, rather than executing pre-set scripts.
60%UnverifiedIn a cloud Agent architecture, the Agent Loop does not run inside the sandbox; the Agent and the sandbox are separate.
50%UnverifiedBoth the Claude Agent SDK and the OpenAI Agents SDK take over the Agent Loop, greatly simplifying the model invocation, tool dispatching, history maintenance, and loop control logic that previously had to be written by hand.
50%UnverifiedWhen an application sends a user request to the model, it includes a list of tools the model can use, with each tool having a name and an input schema.
50%UnverifiedLarge language models are responsible for thinking and decision-making but never directly execute actions themselves; the code outside the model is what actually executes the actions.
50%UnverifiedThe termination logic of an Agent Loop is to loop until the model no longer initiates any tool calls.
50%UnverifiedEvery round of calls sends the complete conversation history again, so the longer the task, the larger the context, and the slower and more expensive the calls become.
50%UnverifiedAfter receiving a request, the model may return a structured tool call rather than directly providing an answer.
50%UnverifiedA turn limit and a budget should be set for the Agent loop to prevent it from getting stuck in an infinite loop and to avoid runaway costs.
50%UnverifiedThe Maker/Checker pattern is an important basis for designing exit conditions in an Agent Loop; only when the Checker passes verification is the loop allowed to terminate and deliver results.
50%UnverifiedA single LLM API call is an instantaneous question-and-answer cycle that ends once the request is sent and the response is returned, whereas an Agent Loop is a continuously running loop structure that persists until the goal is achieved or an exit condition is triggered.
50%UnverifiedA single LLM call typically does not involve external tools, whereas an Agent Loop can actively invoke external tools such as file systems, databases, and various APIs.
50%