Definition
An AI agent is a system that works towards a goal by deciding its own steps and acting through tools. In today's usage, it's usually an LLM running in a loop: it decides the next action, calls a tool, reads the result and continues until the goal is met.
In simple words
A chatbot answers. An agent gets things done. Ask a chatbot about flights and it describes them. Ask an agent to book the cheapest flight on Friday and it searches, compares, checks your calendar and books, deciding each step as it goes.
Why it matters
Agents let LLMs do real work: writing and running code, handling support tickets, researching and filing reports. They also add risk, because a mistake becomes an action. A wrong sentence is annoying, while a wrong payment is a real loss. So safety and limits matter here more than anywhere.
How it works
The agent loop
- Think: given the goal and what has happened so far, what's next?
- Act: call a tool, such as search or a calculator.
- Observe: read what the tool returned.
- Repeat until finished, or until a limit is reached.
| Chatbot | Workflow | Agent | |
|---|---|---|---|
| Who decides the steps? | No steps, only a reply | A developer, in advance | The model, while running |
| Takes actions? | No | Yes, fixed ones | Yes, chosen by it |
| Predictable? | Fairly | Very | Least |
In code
The loop without a real LLM: a stand-in "model" chooses tools. A real agent gets each decision from an LLM, but the loop looks like this.
def calculator(expression):
return eval(expression, {"__builtins__": {}}) # never do this with untrusted input
def get_price(item):
return {"pen": 10, "notebook": 40}[item]
TOOLS = {"calculator": calculator, "get_price": get_price}
def fake_model(history):
if len(history) == 0:
return ("get_price", "pen")
if len(history) == 1:
return ("get_price", "notebook")
if len(history) == 2:
return ("calculator", f"2 * {history[0]} + 3 * {history[1]}")
return ("finish", f"The bill is Rs {history[2]}")
history = []
for step in range(5): # always limit the steps
action, argument = fake_model(history)
if action == "finish":
print(argument)
break
result = TOOLS[action](argument)
print(f"Step {step + 1}: {action}({argument!r}) -> {result}")
history.append(result)Output
Step 1: get_price('pen') -> 10
Step 2: get_price('notebook') -> 40
Step 3: calculator('2 * 10 + 3 * 40') -> 140
The bill is Rs 140Common mistakes
- Giving an agent more access than it needs, such as write access to production.
- Letting it loop forever. Always set limits on steps and spending.
- Skipping tests because it worked in a demo. Agents fail in surprising ways.
Check yourself
Summary
- An agent pursues a goal in a loop: think, act, observe.
- Use a fixed workflow when you can, and an agent when you must.
- Limit its permissions and steps, and require approval for risky actions.
Finished reading?