How does an AI agent work: think, call a tool, look at the result, repeat?
A language model can't check the weather or run a calculator. A small program around it can, and the loop that results is what we call an agent.
βΆ Start the storyIt works as a loop: the model decides what to do next, a tool does it, and the result goes back to the model. A language model on its own only produces text. Tool use is the mechanism that lets it interact with external systems, for example fetching real-time information from an API or executing code. A program separate from the model watches its output for a special tool-calling syntax, calls the tool when it appears, and feeds the output back into the model's input.
Why bother? Researchers behind a paper called Toolformer pointed out a paradox: language models struggle with basic functions such as arithmetic or factual lookup, where much simpler and smaller models excel. Their answer was that models can teach themselves to use external tools, a calculator among them.
One recipe for putting thinking and doing together is ReAct, described by Shunyu Yao and colleagues in an October 2022 paper. The model writes out reasoning and actions in turn: the reasoning helps it track and update its plan and handle exceptions, while the actions fetch more information from external sources. In the paper's tests, a model that consulted a simple Wikipedia API overcame hallucination and error propagation seen in plain chain-of-thought reasoning.
Step 1: Reason
The model writes out what it should do next.
Step 2: Act
It emits a structured tool call.
Step 3: Run
A separate program calls the tool.
Step 4: Observe
The result is fed back into the model.
Step 5: Stop
The task ends, or a stopping condition is hit.
Engineers at Anthropic summarize the result: agents are typically just language models using tools based on environmental feedback in a loop. At each step the agent should get ground truth from its environment, such as a tool result or the output of running code, to judge its progress.
Quiz me
0/3
Recap
Think, call a tool, observe, repeat, until a stopping condition.
π‘ A trick to remember it Β· Think, act, look; think, act, look: the model asks, the tool does, the result comes back.
Surprising fact Β· The model never runs the tool itself: it only writes a request, and a separate program carries it out.
Connects to
- ποΈ How does an AI agent remember, and look things up before it answers?
- π What is an API call, and how does one program ask another for something?
- π€ What turns a chatbot into an AI agent?
- π¬ How does a large language model write a sentence, one piece at a time?
- Hallucination artificial intelligence
Sources (6)
No source, no claim. Every fact in this lesson (16 claims) cites at least one of these.
- [1]ReAct: Synergizing Reasoning and Acting in Language Models Β· arXiv (Yao et al.)
- [2]Toolformer: Language Models Can Teach Themselves to Use Tools Β· arXiv (Schick et al.)
- [3]Large language model Β· Wikipedia
- [4]Building effective agents Β· Anthropic Engineering
- [5]AI agent Β· Wikipedia
- [6]Tool use with Claude (documentation) Β· Anthropic