The four ingredients
Most AI agents share four basic ingredients:
- Model: a language model that can reason and decide what to do.
- Environment: the world or interface the agent interacts with, such as a file system, browser, or code editor.
- Tools: specific functions the agent can call, like searching the web, running code, or querying a database.
- Memory: the agent's record of what happened, including the conversation, observations, and intermediate results.
The model is powerful, but it is the loop of thinking, acting, and observing that turns an LLM into an agent.
Key idea: an agent is not one model. It is an architecture: a model plus a control loop, tools, and state.
ReAct: reason and act
A popular agent pattern is ReAct, short for Reason + Act. In each loop, the model produces a thought explaining what it wants to do, then an action to take, and finally receives an observation from the tool. That observation becomes context for the next thought.
This loop continues until the agent decides it has finished, hit a safety limit, or needs human help. The structure makes the reasoning explicit and easier to debug.
Tools and APIs
Tools give an agent capabilities the LLM does not have natively: up-to-date search, calculator functions, code execution, version control, and more. The model learns to describe which tool to call and with what arguments.
Tool calling is often implemented with a special output format, such as JSON, that the program parses and routes to the correct function. The result is fed back to the model as an observation. This turns the LLM into a controller that can orchestrate real-world systems.
Memory and state
Memory matters because the context window of an LLM is finite. A simple agent stores the entire conversation. A more advanced agent maintains summaries, a scratchpad, and a plan that persist across turns.
State also includes information about the environment: which files were edited, which tests passed, what the user already confirmed. Without this state, an agent would repeatedly make the same mistakes or ask the same questions.
Design note: good agents do not just pass the entire history to the model. They summarize, filter, and structure memory so the most relevant context fits in the window.
Run an agent loop
The demo below simulates a simple ReAct agent. The goal is to find the current weather for a city. Click Run one step to watch it think, act, and observe.
A ReAct agent in Python
ReAct means Reason, Act, Observe. The agent thinks out loud, picks a tool, runs it, and then reasons again until it has an answer.
Check yourself
Describe how tools make an LLM into an agent.
Your answer:
Sample answer: Tools give the model the ability to affect the world or access information it does not have, such as running code or searching the web. The model decides which tool to use and what arguments to pass, then observes the result and reasons about the next step.
Quick quiz
1. In the ReAct pattern, what comes after an action?
2. Why do agents need memory?
3. What is the role of the environment in an agent?
Keep learning
You now understand the agent loop. Next, see how agents become coding agents that read, write, and debug code.
Part of the advanced remake of the “Are LLMs Smarter Than a 5th Grader?” series.