Tech●●●●●Difficulty 3 of 5

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 story

It 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.

The agent loop
  1. Step 1: Reason

    The model writes out what it should do next.

  2. Step 2: Act

    It emits a structured tool call.

  3. Step 3: Run

    A separate program calls the tool.

  4. Step 4: Observe

    The result is fed back into the model.

  5. 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

  1. 1.Who actually runs the tool when an agent calls one?
  2. 2.What does ReAct add to simple tool use, according to its abstract?
  3. 3.Why do Anthropic's engineers stress getting ground truth from the environment at each step?

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.

Sources (6)

No source, no claim. Every fact in this lesson (16 claims) cites at least one of these.

  1. [1]ReAct: Synergizing Reasoning and Acting in Language Models Β· arXiv (Yao et al.)
  2. [2]Toolformer: Language Models Can Teach Themselves to Use Tools Β· arXiv (Schick et al.)
  3. [3]Large language model Β· Wikipedia
  4. [4]Building effective agents Β· Anthropic Engineering
  5. [5]AI agent Β· Wikipedia
  6. [6]Tool use with Claude (documentation) Β· Anthropic
More lessons in πŸ’» Tech (3) See all tech lessons β†’

One more light on your map.

Get one lesson like this every day, about the things you love. Free, in two or five minutes.

Get the share card for this lesson β†—