How AI Agents Work: The Four Core Elements and ReAct Loop Decision-Making Mechanism Explained

A deep breakdown of AI Agent's four core elements and ReAct loop decision-making mechanism
This article systematically introduces the core composition and working mechanism of AI Agents. An Agent consists of four key elements: the LLM (decision-making brain), Tools (execution hands), Prompts (reference manual), and Tool Executor (action bridge). It operates following the ReAct (Reason + Action) paradigm: completing complex tasks through an iterative loop of receiving input, model reasoning and decision-making, executing tools to update context, and determining whether to terminate.
What Is an AI Agent?
In the field of large model application development, the Agent (intelligent agent) is the most critical deployment pattern — bar none. Many people have heard the concept, but don't truly understand its internal composition and working mechanism. This article starts from the four core elements of an Agent and dives deep into the ReAct loop decision-making mechanism, helping you build a systematic understanding of intelligent agents.
The Four Core Elements of an Agent
All AI Agents, regardless of which framework they're built on, consist of four core components:
1. Large Language Model (LLM): The Agent's "brain," responsible for providing decision-making and reasoning capabilities. It determines the upper bound of how well the agent can understand problems and plan steps.
A Large Language Model (LLM) is a neural network model based on the Transformer architecture, trained on massive amounts of text data. Representative models like GPT-4, Claude, and Gemini typically have parameter counts exceeding hundreds of billions. The reason LLMs can serve as an Agent's "brain" lies in two emergent core capabilities: Instruction Following enables the model to understand complex task descriptions, and In-Context Learning allows the model to dynamically adjust its reasoning path based on conversation history. Notably, different models vary significantly in their Function Calling capabilities, which directly determines whether an Agent can accurately identify and invoke the correct tools — this is why choosing the underlying model is one of the most critical decisions in Agent engineering.
2. Tools: The "hands and feet" that enable an Agent to perform concrete actions. For example, querying weather requires a weather API tool, creating an order requires an order tool, and checking train tickets requires a ticketing tool. Without tools, an Agent can only "theorize without practice."
Tool invocation at the technical implementation level relies on the LLM's Function Calling mechanism, a capability first commercially deployed by OpenAI in 2023 with GPT-3.5/GPT-4. The principle works as follows: developers inject the tool's name, functional description, and parameter Schema (typically in JSON Schema format) into the model's request. When the model determines during reasoning that a tool needs to be called, it outputs a structured JSON rather than natural language, containing the tool name and parameter values. The tool executor parses this JSON, executes the corresponding function, and appends the result as a "tool message" to the conversation history, triggering another round of model reasoning. This mechanism is the foundational layer of modern Agent frameworks (LangChain, LlamaIndex, AutoGen, etc.).
3. Prompts: Here we need to correct a common misconception — prompts are not just the system description written by programmers. In the Agent ecosystem, "prompts" is a broad concept that includes: system-level functional descriptions, the functional description of each tool, and detailed descriptions of each tool's parameters. Together, these form the "reference manual" the LLM uses when making decisions.
4. Tool Executor: When the LLM decides that a specific tool needs to be called, the executor is responsible for actually running that tool and returning the results. It's the bridge connecting "decision" to "action."

The ReAct Paradigm: The Loop Mechanism of Reasoning and Action
All intelligent agents follow one core working paradigm — ReAct (Reason + Action), meaning "reasoning + action." This isn't a specific type of agent, but rather the universal working method of all Agents.
The ReAct paradigm was formally proposed by Google Research in 2022 in the paper "ReAct: Synergizing Reasoning and Acting in Language Models." Its core insight is: pure reasoning chains (Chain-of-Thought) lack interaction with the external environment, while pure action sequences lack reasoning support — combining both enables models to robustly complete complex tasks in dynamic environments. Each step of ReAct includes three sub-steps: Thought (thinking process), Action (tool invocation), and Observation (tool return results). These three form a minimal execution unit, and multiple units chained together form the complete task resolution pipeline.
Core Flow of Loop Execution
An Agent's working process is an iterative loop, with the following specific steps:
Step 1: Receive Input and Restore State
The user provides input (which can be a question or a request), and the system combines the user input with historical conversation records into a complete Context. The purpose of restoring state is to give the Agent "memory" — for example, if a user says "what's the weather like in this city today," the Agent needs to find from the context which specific city "this city" refers to.
The "memory" here essentially relies on the LLM's Context Window — the maximum number of tokens the model can process in a single inference. GPT-4 Turbo supports 128K tokens, and the Claude 3 series supports up to 200K tokens. As loop iterations proceed, tool return results are continuously appended to the context, and token consumption grows steadily. When task complexity is high and tool calls are frequent, the context may approach the window limit. For this reason, enterprise-level Agent systems typically introduce external memory modules (such as vector databases) to store long-term memory, retrieving only the most relevant historical fragments back into the context to overcome window limitations.
Step 2: LLM Reasoning and Decision-Making
The LLM reasons based on the context and all tool descriptions, determining which tool should be called next. This process entirely relies on the LLM's semantic understanding and logical reasoning capabilities — it's not hardcoded by programmers using if-else logic.
Step 3: Execute Tool and Update Context
The tool executor runs the selected tool and appends the returned results to the context. At this point, the context information becomes richer.
Step 4: Determine Whether to Terminate the Loop
The LLM re-examines the updated context to determine whether it has collected enough information to answer the user's question. If not enough, it returns to Step 2 to decide on calling the next tool; if sufficient, it generates the final answer and the loop ends.

Loop Termination Conditions
Many people worry that this loop might become an infinite loop. In practice, there are two termination conditions:
- Normal termination: The context already contains complete information sufficient to answer the user's question
- Abnormal termination: After approximately three repeated thinking attempts without finding a suitable tool, the LLM proactively returns an error message informing the user
There's no fixed limit on the number of loop iterations — it might take just one, or it might require multiple iterations.
Practical Example: The Complete Flow of Querying Shanghai's Weather
Let's use a concrete example to walk through the entire process. User input: "What's the weather like in Shanghai today? Tell me in Celsius."
Round 1: Think → Act
Think (Reason): The LLM reasons that the user wants to know Shanghai's real-time weather and requires Celsius. I don't have real-time data myself, so I need to use a tool. In the tool list, I find a tool named get_weather that can query weather.
Act (Action): Call the get_weather tool through the tool executor, passing in the parameter "Shanghai"
Related articles
Deep Dive into AI Agent Skill Design: …
Deep Dive into AI Agent Skill Design: Engineering Practices from Anthropic and Perplexity
A deep dive into Skill design philosophy from Anthropic's Claude Code team and Perplexity's Agent team, covering the Tax Test, Gotchas Flywheel, progressive disclosure, and Eval-First practices for building high-quality AI Agent skill systems.
Deep Dive into OpenAI's Official GPT-5…
Deep Dive into OpenAI's Official GPT-5.6 Prompting Guide: The Shift from Manual to Automatic
A deep dive into OpenAI's official GPT-5.6 Sol prompting guide: conciseness-first, outcome-oriented design, autonomy boundaries, tool routing, and reasoning intensity tuning.
Deep DivesDeep Dive into How OpenClaw (Open-Source Crayfish) AI Agent Works
Deep analysis of OpenClaw AI Agent internals: System Prompt, tool calling, SubAgents, Skill system, memory, and Context Engineering explained.