What Is an AI Agent?
A large language model (LLM) is a program that, given some text, predicts the text most likely to come next. On its own, that is all it does: text in, text out. Yet chat apps like ChatGPT and Claude can also search the web, read files, or check a calendar. That ability comes from an AI agent.
An AI agent combines two things: a language model, which decides what to do, and code, which does it. You give the agent a goal. The model picks a tool, the code runs it, and the model reads the result to choose the next step. This loop repeats until a stop condition ends the run. This post explains the loop and the five elements of an agent: the model, tools, state, stop conditions, and approvals.
If you are new to how language models generate text, read What Is an LLM? first.
The loop #
An agent runs a model in a four-step tool-use loop popularized by patterns like ReAct.1

- Read the goal and context. The code sends the user’s goal, past steps, and available tools to the model.
- Propose a tool call. The model outputs structured text naming a tool and its arguments (or returns a final answer to end the loop).
- Run the tool. The code outside the model executes that tool and captures its output.
- Append and repeat. The code appends the tool output to the context and returns to step 1.
For example, if you ask “Am I free tomorrow at 3 pm?”, the model proposes a list_events tool call, the code queries your calendar and appends the result, and on the next turn the model answers.
In step 4 of What Is an LLM?, the model appends one token inside a single generation. Here, the code appends a whole tool result between separate model calls.
Five elements of an agent #
Each element maps to a part of the loop. The model proposes the action in step 2, and tools run in step 3. State is the context that steps 1 and 4 read and extend. Stop conditions decide when the loop exits, and approvals hold risky tool calls before step 3. Every agent needs the first four. Approvals matter once tools can change things.

Model #
The model reads the context and proposes the next action. It can only output text, so it cannot run anything itself. A stronger model makes better tool choices, yet it still depends on the surrounding code.
Tools #
Tools are functions the code exposes to the model. Each tool has a name, a description, and an input schema. The model reads those schemas to pick a tool and fill in its arguments. The tool list sets the agent’s reach.
State #
The model keeps nothing between calls, so the code owns the task history. That history holds the goal, past tool calls, and their outputs. The context window caps how much history the model sees on each call. Long tasks must summarize or drop older steps to fit.
Stop conditions #
Every loop needs clear rules that end execution. An agent stops when:
- The model returns a final answer with no tool call, which claims the goal is met.
- The run hits a step, token, cost, or time budget.
- The code hits an error the agent cannot recover from.
Unless code checks the result, “goal met” is the model’s claim, not a verified fact.
Approvals #
Approval rules split actions into what runs freely and what waits for a human. Read actions usually run without a prompt, while writes and irreversible actions wait for approval. Reads are not always safe, though. Fetched content can hide instructions that steer later writes. This is called prompt injection. Reads can also expose sensitive data.
Agent or workflow #
Use a workflow when you know the steps in advance.2 In a workflow, code fixes the sequence of steps and calls the model at set points. In an agent, the model chooses the next step at runtime. Workflows cost less and behave more predictably, while agents handle open-ended tasks.
Practical limits #
The agent inherits each LLM limit, and acting on the output raises the stakes:
- Plausible wrong text becomes a wrong action. A hallucinated argument can delete a file or send bad data.
- Knowledge stops at a cutoff date. The agent needs tools that read live state, such as files, databases, or APIs.
- No memory between calls. See State: long tasks must fit their history inside the context window.
- Varied answers across runs. Because the model samples tokens probabilistically, the same task can take different tool paths and reach different results.
- Compounding cost, latency, and errors. Each step re-sends the growing history to the model, and multi-step chains multiply latency, token cost, and the chance of an early mistake derailing the run.
References #
Yao, S., et al. (2023), “ReAct: Synergizing Reasoning and Acting in Language Models,” ICLR (arXiv:2210.03629). ↩︎
Anthropic (2024), “Building effective agents” (anthropic.com/engineering/building-effective-agents). ↩︎