In the previous sections, we learned:
In this section, we’ll explore the complete AI Agent Workflow, a cycle we defined as Thought-Action-Observation.
And then, we’ll dive deeper on each of these steps.
Agents work in a continuous cycle of: thinking (Thought) → acting (Act) and observing (Observe).
Let’s break down these actions together:
The three components work together in a continuous loop. To use an analogy from programming, the agent uses a while loop: the loop continues until the objective of the agent has been fulfilled.
Visually, it looks like this:
In many Agent frameworks, the rules and guidelines are embedded directly into the system prompt, ensuring that every cycle adheres to a defined logic.
In a simplified version, our system prompt may look like this:
We see here that in the System Message we defined :
Let’s take a small example to understand the process before going deeper into each step of the process.
We created Alfred, the Weather Agent.
A user asks Alfred: “What’s the weather like in New York today?”
Alfred’s job is to answer this query using a weather API tool.
Here’s how the cycle unfolds:
Internal Reasoning:
Upon receiving the query, Alfred’s internal dialogue might be:
“The user needs current weather information for New York. I have access to a tool that fetches weather data. First, I need to call the weather API to get up-to-date details.”
This step shows the agent breaking the problem into steps: first, gathering the necessary data.
Tool Usage:
Based on its reasoning and the fact that Alfred knows about a get_weather
tool, Alfred prepares a JSON-formatted command that calls the weather API tool. For example, its first action could be:
Thought: I need to check the current weather for New York.
{
"action": "get_weather",
"action_input": {
"location": "New York"
}
}
Here, the action clearly specifies which tool to call (e.g., get_weather) and what parameter to pass (the “location”: “New York”).
Feedback from the Environment:
After the tool call, Alfred receives an observation. This might be the raw weather data from the API such as:
“Current weather in New York: partly cloudy, 15°C, 60% humidity.”
This observation is then added to the prompt as additional context. It functions as real-world feedback, confirming whether the action succeeded and providing the needed details.
Reflecting:
With the observation in hand, Alfred updates its internal reasoning:
“Now that I have the weather data for New York, I can compile an answer for the user.”
Alfred then generates a final response formatted as we told it to:
Thought: I have the weather data now. The current weather in New York is partly cloudy with a temperature of 15°C and 60% humidity.”
Final answer : The current weather in New York is partly cloudy with a temperature of 15°C and 60% humidity.
This final action sends the answer back to the user, closing the loop.
What we see in this example:
Alfred’s process is cyclical. It starts with a thought, then acts by calling a tool, and finally observes the outcome. If the observation had indicated an error or incomplete data, Alfred could have re-entered the cycle to correct its approach.
The ability to call a tool (like a weather API) enables Alfred to go beyond static knowledge and retrieve real-time data, an essential aspect of many AI Agents.
Each cycle allows the agent to incorporate fresh information (observations) into its reasoning (thought), ensuring that the final answer is well-informed and accurate.
This example showcases the core concept behind the ReAct cycle (a concept we’re going to develop in the next section): the interplay of Thought, Action, and Observation empowers AI agents to solve complex tasks iteratively.
By understanding and applying these principles, you can design agents that not only reason about their tasks but also effectively utilize external tools to complete them, all while continuously refining their output based on environmental feedback.
Let’s now dive deeper into the Thought, Action, Observation as the individual steps of the process.
< > Update on GitHub