An AI agent is a system in which an LLM repeatedly chooses the next action towards a goal, carries it out through tools, and looks at the result, until the goal is reached or it stops. A chatbot answers once, and an agent acts over many steps.

Chatbot and agent

PointChatbotAgent
WorkYou ask, it replies onceWorks towards a goal over many steps
ToolsNoneSearches, adds to cart, pays
A mistake isA wrong sentence that you can ignoreA wrong action, such as money spent or an order placed

Remembering tip

A chatbot is a knowledgeable friend on the phone. An agent is a new intern who has been given the company credit card, so it needs training, checking, a spending limit and supervision.

Parts of an agent

PartRole
LLMThe brain, which chooses the next action
ToolsThe hands, which act on the world
MemoryThe notebook, which keeps what happened
LoopKeeps going until the goal is reached
GoalSays when to stop

Workflow or agent

The difference is who decides the next step (Anthropic, 2024):

TypeWho decides the next stepExample in a shop
WorkflowYour code, fixed in advanceAlways search, then filter, then show the top 3
AgentThe LLM, while it runsSearch again, compare, or go to checkout

Use the simplest option that works. An agent is more flexible, but it is slower, costlier and riskier.

Notation

SymbolMeaning
The goal, in the words of the user
The action at step : a tool call, or "finish"
The observation at step : what the tool returned
The history: everything seen and done so far
The policy: the LLM, with weights , that picks actions
The step limit

Parts of the formula:

  • the LLM reads the goal and the history, and writes the next action
  • means the action is sampled from the probabilities of the LLM, so 2 runs can differ
  • the environment, such as the shop, carries out the action and returns an observation
  • the loop stops when the LLM writes "finish", or after steps
  • the history grows at every step, because each step adds one action and one observation, which matters for cost

The LLM only decides, and the code does. That gap is where every safety control lives, see Guarded Agent Loop.

The next question is how the LLM should choose its actions, see ReAct.