1.2 Composition and Operating Principles of Agents
1.2.1 Task Environment Definition
To understand how an agent operates, we must first understand the task environment in which it operates. In the field of artificial intelligence, the PEAS model is typically used to precisely describe a task environment, analyzing its Performance measure, Environment, Actuators, and Sensors. Taking the intelligent travel assistant mentioned above as an example, Table 1.2 below shows how to use the PEAS model to specify its task environment.
Table 1.2 PEAS description of intelligent travel assistant

In practice, the digital environment in which LLM agents operate exhibits several complex characteristics that directly affect agent design.
First, the environment is typically partially observable. For example, when a travel assistant queries flights, it cannot obtain all real-time seat information from all airlines at once. It can only see partial data returned by the flight booking API it calls, which requires the agent to have memory (remembering queried routes) and exploration (trying different query dates) capabilities.
Second, the results of actions are not always deterministic. Based on the predictability of results, environments can be divided into deterministic and stochastic. The task environment of a travel assistant is a typical stochastic environment. When it searches for ticket prices, two adjacent calls may return different ticket prices and remaining seat numbers, requiring the agent to have the ability to handle uncertainty, monitor changes, and make timely decisions.
Additionally, there may be other actors in the environment, forming a multi-agent environment. For a travel assistant, other users' booking behaviors, other automated scripts, and even airlines' dynamic pricing systems are all other "agents" in the environment. Their actions (for example, booking the last discounted ticket) directly change the state of the environment in which the travel assistant operates, placing higher demands on the agent's rapid response and strategy selection.
Finally, almost all tasks occur in sequential and dynamic environments. "Sequential" means current actions affect the future; while "dynamic" means the environment itself may change while the agent is making decisions. This requires the agent's "perceive-think-act-observe" loop to be able to quickly and flexibly adapt to a continuously changing world.
1.2.2 Agent Operating Mechanism
After defining the task environment in which an agent operates, let's explore its core operating mechanism. An agent does not complete tasks in one go but interacts with the environment through a continuous loop. This core mechanism is called the Agent Loop. As shown in Figure 1.5, this loop describes the dynamic interaction process between the agent and the environment, forming the foundation of its autonomous behavior.

Figure 1.5 Basic loop of agent-environment interaction
This loop mainly contains the following interconnected stages:
- Perception: This is the starting point of the loop. The agent receives input information from the environment through its sensors (for example, API listening ports, user input interfaces). This information, i.e., Observation, can be either the user's initial instruction or feedback on environmental state changes caused by the previous action.
- Thought: After receiving observation information, the agent enters its core decision-making stage. For LLM agents, this is typically an internal reasoning process driven by large language models. As shown in the figure, the "thought" stage can be further subdivided into two key links:
- Planning: Based on current observations and its internal memory, the agent updates its understanding of the task and environment and formulates or adjusts an action plan. This may involve decomposing complex goals into a series of more specific subtasks.
- Tool Selection: Based on the current plan, the agent selects the most suitable tool from its available tool library to execute the next step and determines the specific parameters needed to call that tool.
- Action: After decision-making is complete, the agent executes specific actions through its actuators. This typically manifests as calling a selected tool (such as a code interpreter or search engine API), thereby influencing the environment with the intent to change its state.
Action is not the end of the loop. The agent's action causes a state change in the environment, which then produces a new observation as result feedback. This new observation is captured by the agent's perception system in the next round of the loop, forming a continuous "perceive-think-act-observe" closed loop. It is through continuously repeating this loop that the agent gradually advances the task, evolving from the initial state toward the goal state.
1.2.3 Agent Perception and Action
In engineering practice, to enable LLMs to effectively drive this loop, we need a clear Interaction Protocol to regulate information exchange between it and the environment.
In many modern agent frameworks, this protocol is embodied in the structured definition of each agent output. The agent's output is no longer a single natural language response but a piece of text following a specific format that explicitly shows its internal reasoning process and final decision.
This structure typically contains two core parts:
- Thought: This is a "snapshot" of the agent's internal decision-making. It articulates in natural language how the agent analyzes the current situation, reviews the observation results from the previous step, engages in self-reflection and problem decomposition, and ultimately plans the next specific action.
- Action: This is the specific operation the agent decides to impose on the environment based on its thinking, typically expressed as a function call.
For example, an agent planning a trip might generate the following formatted output:
Thought: The user wants to know the weather in Beijing. I need to call the weather query tool.
Action: get_weather("Beijing")The Action field here constitutes an instruction to the external world. An external Parser will capture this instruction and call the corresponding get_weather function.
After the action is executed, the environment returns a result. For example, the get_weather function might return a JSON object containing detailed weather data. However, raw machine-readable data (such as JSON) typically contains redundant information that the LLM doesn't need to focus on, and the format doesn't conform to its natural language processing habits.
Therefore, an important responsibility of the perception system is to play the role of a sensor: processing and encapsulating this raw output into concise, clear natural language text, i.e., observation.
Observation: Beijing's current weather is sunny, temperature 25 degrees Celsius, light breeze.This Observation text is fed back to the agent as the main input information for the next round of the loop, for it to conduct a new round of Thought and Action.
In summary, through this rigorous loop composed of Thought, Action, and Observation, LLM agents can effectively combine their internal language reasoning capabilities with real information and tool operation capabilities from the external environment.