What does an agent loop do?
Anthropic defines agents as systems that dynamically manage their own processes and tool use. A task can begin with a user instruction or a conversation with the user. Once the task is clear, the agent can make a plan, work independently, and return to the user when it needs more information or feedback.
Anthropic describes an agent as an LLM that uses tools in a loop guided by feedback from its environment. That feedback can be the result of a tool call or the output of running code. The agent uses those results to assess its progress. It can pause for human feedback when it encounters a roadblock or reaches a particular milestone.
The ReAct study explores how a model interleaves task-related reasoning with actions. Reasoning helps the model create, track, and revise an action plan. Actions let it interact with the external environment and gather more information.
Reasoning, acting, and observing
In ReAct, a reasoning step can determine what needs to be done or revise the plan based on information from the previous action. The observation that follows an action contains the information returned by the external environment. The model can use that observation in subsequent reasoning and action steps.
The study treats reasoning as a language action that leaves the external environment unchanged. The step itself produces no observation from the environment. The model reasons over the current context to generate information that can support later reasoning or action steps.
Reasoning steps can serve different purposes. One step might break down the task goals and create an action plan. Another might extract key information from an observation, track progress, or revise the plan in response to a new development. The study also identifies synthesizing available information into a final answer as a function of reasoning steps.
The ReAct study's information retrieval setup uses three types of actions. search returns the beginning of the relevant Wikipedia page if it exists and suggests similar titles otherwise. lookup returns the next sentence on the page that contains the specified phrase. finish ends the task with an answer.
How an observation changes the next search
In one example from the study, the model is asked for the elevation range of the area into which the eastern sector of the Colorado orogeny extends. The model first searches for the Colorado orogeny. The initial observation leaves out the eastern sector mentioned in the question. The model then uses Lookup to search for the relevant phrase.
The resulting observation says that the eastern sector extends into the High Plains. In its next reasoning step, the model uses that information to search for the High Plains. The search result shows that the name refers to more than one region. The model then changes its search to High Plains (United States).
The next observation contains the elevation range the question asks for. The model uses that information to formulate its answer, and the example ends with a Finish action. Each new search target comes from the preceding observation. The more specific search follows the observation that identifies multiple regions with the same name.
In the ReAct study, the order of reasoning and action depends on the type of task. In examples that rely heavily on reasoning, the model alternates between reasoning and action. In decision-making tasks that can involve many actions, reasoning steps may occur less frequently, at relevant points in the sequence.
In Anthropic's description of agents, tool results also help the agent assess its progress. The run can end when the task is complete. Anthropic notes that adding a stopping condition is also a common way to keep the loop under control.
How does a tool call return its result?
According to Anthropic's Claude documentation, the model uses the user's request and the tool description to decide when to call the tool. It then returns a structured call. Where the call runs depends on whether the tool is a client tool or a server tool.
A client tool runs in the application. Claude's response sets stop_reason to tool_use and contains one or more tool_use blocks. The application runs the operation and sends the result back as a tool_result. Claude can then use the result to respond.
In Anthropic's weather example, the initial request defines the get_weather tool. The model returns a tool_use block containing the tool name and inputs. Once the application has the result, it adds the previous assistant content and the result to the messages in the next request. The tool_use_id field links the result to the corresponding call. Claude then answers the original question.
In the example, the tool's input_schema defines a location property and lists it as required. The user's message includes the location. The call Claude generates contains the tool name and inputs, and the application passes the tool result to the model in the next request.