AI CONCEPT AND AGENT LOOP
When talking about Artificial Intelligence, we need to discuss the concept of AI and how it works. First, you need to understand that we have a lot of different providers, like Anthropic, Google, and OpenAI, that provide AI models and products, including agent harnesses like Claude Code and Codex. A harness is like the armor that the Agent uses to control a specific configuration of the Agent.
Agents can be considered the combination of an LLM Model, instructions, Tools, context, and an execution loop. Tools are functions that the Agent can consume from our system. For example, let's think that we have a weather system, and in this system we have a function that looks up the weather of a specific city (get_weather) based on the user's input.
Now that we already know what a tool is, let's look at the Agent Loop, the place where the inference model ( the LLM) will receive the input: “How is the weather in São Paulo?” and will look at our system to know which tool calls it can use. It sees that the get_weather function can be called and calls it. The tool returns the answer: “The weather in São Paulo is sunny, 32 degrees” to the Agent, and the Agent returns the answer to the user if the answer is the requested one.
The Agent Loop is oriented by goal, and it has this core concept: First, observe the input → then plan → then act by calling tools → then repeat until the goal is reached. One of the most important things in the agent loop is the context window. When a loop starts, it has the main prompt that is called the System Prompt. Each message is saved in the messages array, and the previous messages are kept in the context history.
Other interesting concepts are that each agent's context window has a specific number of tokens, and each iteration consumes a quantity of tokens. These tokens can be managed with strategies like compaction, summarization, context pruning, and truncation. The compaction process is very important too. Other strategies like retry policies, schema validation, error handling, and permissions are also important to make the Agent more reliable and safe. As the context approaches its limit, the harness may compact older information into a summarized representation, freeing space for subsequent interactions.
In this article, we talked about some important concepts of AI and how it works behind the scenes. In the next articles, we're going to talk more about the importance of context and how we can add short- and long-term memory to the Agent.