The agent loop
An AI agent is a system where a model interacts with an environment. At each step the model reads the current situation, decides what to do, executes an action, and observes the result. Then it loops.
The most common pattern is ReAct: reason then act. The model writes out its reasoning in text, then picks a tool, then reads the tool's output, then reasons again. It keeps going until it has enough information to answer.
Core idea: an agent is not a single prompt. It is a running program where the LLM is the decision-maker and tools are its hands and eyes.
Tools and APIs
Tools are functions the agent can call. A tool has a name, a description, and a required set of arguments. The model does not run the tool itself; it outputs a JSON request like:
{
"tool": "get_weather",
"arguments": { "city": "Austin", "day": "tomorrow" }
}
Common tools include web search, code interpreters, calculators, databases, calendar APIs, and robotics control interfaces. The model only needs to know what each tool does and what it returns; it does not need to understand how the tool works inside.
Planning
Planning matters because agents can get stuck or waste time. A good plan breaks a big goal into subtasks, picks the right tools, and knows when to stop. Some agents even make plans in advance; others plan one step at a time.
Challenges include Toolformer-style hallucinations where the model calls a tool incorrectly, loops that repeat the same action, and long tasks where the context becomes too long. Researchers are working on memory, hierarchies, and error recovery to make agents more reliable.
Plan a trip
You are the agent. Your goal: decide whether to pack an umbrella for a trip. You need the weather for both cities. Call the right tools in the right order, then submit your answer.
What makes an agent different from a plain LLM?
An LLM only returns text. An agent can keep acting. What does it need besides a model?
It needs tools it can call, an environment that returns results, and a loop where the model reasons, acts, and observes.
Three questions
1. What is a tool in an AI agent?
2. What does the ReAct pattern do?
3. Why is planning hard for agents?
Keep learning
Now that you have seen the ideas, the last tutorial in this series walks through building a tiny neural network from scratch in PyTorch.
Part of the AI Explained tutorial series.