← Back to Agentic AI map
Lesson 1.4 · Agents From Scratch

What Makes It an "Agent"

The difference between a chatbot and an agent: tools, and a loop to use them in.

concept

What you will be able to do

  • Explain the difference between a chatbot and an agent
  • Name the three parts of an agent - LLM, tools, and a loop - and what each one does
  • Explain what a tool is, and why it is just an ordinary function
  • Explain why the model decides but never executes
  • Say why an agent can be more reliable than a chatbot on the same question

The idea, in plain English

A plain chatbot takes a prompt and gives back text. One shot, done. It has no way to check anything or do anything - ask it for the result of a sum and it produces the text that looks most like a right answer, which is not the same as the right answer.

That is not a hypothetical. We asked a local model for 47 × 89 three times and got 4193 once - wrong by ten. On larger products it was wrong every time. Nothing was broken: generating text that looks like arithmetic is simply not arithmetic.

An agent can do three things a chatbot cannot. It can decide it needs to do something rather than just say something, which means picking a tool. It can have that action run. And it can look at the result and decide what to do next, possibly going round again.

So the formula for the rest of this module is: Agent = LLM + tools + a loop that lets it act and observe repeatedly. Everything from here on fills in those three pieces - and none of them needs a framework.

Worked example: A mental model for "what is 47 * 89?"

ArchitectureChatbot and agent, side by side

The same question. The chatbot generates an answer and stops. The agent asks for a tool, your code runs it, and the result goes back to the model before it answers.

workflowDecide, act, observe - one roundstep 1 / 5

1 - The question arrives

Exactly what a chatbot would get. The difference is what happens next.

input
a question
tools known
calculate
loop
not started
answer yet
no

Step through the agent answering 47 * 89. Watch which part is the model and which part is your code.

The three parts of an agent

The LLM decides. Given the question and everything that has happened so far, it chooses what to do next: answer, or ask for a tool.

The tools act. A calculator, a weather lookup, a file reader, a database query - anything that does real work or fetches real facts.

The loop connects them. Decide, act, observe, decide again. Without the loop you have a single exchange; with it, the agent can take as many steps as the problem needs.

Agent = LLM + tools + loop
LLMDecides what should happen next.
ToolsDo the real work, or fetch real facts.
LoopRepeats decide -> act -> observe until done.

A tool is just a function

There is nothing exotic about a tool. It is an ordinary function in your code - calculate(expression), get_weather(city), read_file(path), search_database(query) - plus a description the model can read, plus some way for the model to ask for it by name.

The description matters as much as the function. The model has never seen your code; all it knows about a tool is what you tell it in the prompt. Lesson 1.5 writes that description and the request format by hand.

The model decides; your code executes

A model only ever produces text. When it "calls" calculate, what actually happens is that it writes a line of text asking for calculate, and your program reads that line and runs the function. The model never touches your filesystem, your network, or your database - your code does, on its behalf.

That boundary is the most important idea in agent design. It is where you decide which tools exist, what arguments are allowed, and what the model is never allowed to do. Every safety measure later in the course lives on your side of that line.

Tip: When an agent does something wrong, ask which side of the line it happened on. A bad decision is a prompt problem; a bad action is a code problem.

No framework required

LangChain, LangGraph, CrewAI, and AutoGen all do this - but none of them is needed to understand it. The loop is a for loop, the tools are Python functions, and the decision is a line of text the model writes. Lessons 1.5 to 1.7 build exactly that.

Building it by hand first means that when a framework hides these pieces behind a few lines of setup in Module 2, you know what those lines are doing.

Step-by-step code

The mental model
You: "What's 47 * 89?" Plain chatbot: generates an answer from patterns (might be wrong) Agent: 1. Decides: "I should use the calculator tool" 2. Acts: your code calls calculate("47 * 89") 3. Observes: gets 4183 4. Answers: "47 * 89 = 4183"
Chatbot versus calculator
import ollama def ask_model(question): response = ollama.chat( model="llama3.1", messages=[{"role": "user", "content": question}], ) return response["message"]["content"].strip() # The chatbot generates an answer. Python computes one. for a, b in [(47, 89), (4783, 2917), (98765, 4321)]: guess = ask_model(f"What's {a} * {b}? Reply with just the number.") print(f"{a} * {b}: model said {guess}, Python says {a * b}")
Output - from a real run
47 * 89: model said 4183, Python says 4183 4783 * 2917: model said 14,000,111, Python says 13952011 98765 * 4321: model said 425441555, Python says 426763565 Across nine runs the model got 47 * 89 right twice in three, and never got the larger products right.
The whole agent, in outline
for step in range(max_steps): # the loop decision = ask the LLM # the model decides if decision is a final answer: return it result = run the requested tool # your code acts add result to the conversation # the model observes next time

Watch out: A tool makes the answer reliable only if the model actually uses it. Deciding when to call a tool is still the model generating text - Lesson 1.5 shows how often it gets that part right, and what to do when it does not.

Chatbot and agent

Chatbot

Prompt in, text out, done.

prompt -> LLM -> answer
Agent

Decides, acts through tools, observes, repeats.

decide -> act -> observe -> repeat
Tool

A function the model may ask for by name.

def calculate(expression): ...
Observation

A tool result handed back to the model.

Observation: 4183
Loop

What turns one exchange into many steps.

for step in range(max_steps):

Try it yourself

The code does not change. Swap the content string and the program does something else entirely.

Bigger numbers

“What's 4783 * 2917? Reply with just the number.”

Something it cannot know

“What is the weather in Mumbai right now?”

Today

“What is today's date?”

Counting

“How many times does the letter r appear in "strawberry"?”

What usually goes wrong

Calling any chatbot an agent

A model that only generates text is a chatbot, however good the text is. An agent can act - through tools - and react to the results.

Thinking the model runs the tool

The model writes a request. Your code decides whether to run it, and runs it. Forgetting this is how agents end up with more power than intended.

Trusting generated facts

Arithmetic, dates, current weather, and file contents are exactly the things a model generates convincingly and gets wrong. Give it a tool for them.

Reaching for a framework first

A framework makes the three parts easier to write and harder to see. Build the loop by hand once, and the framework becomes a convenience instead of a mystery.

Key points

  • A chatbot generates text once; an agent decides, acts, observes, and repeats.
  • Agent = LLM + tools + loop.
  • A tool is an ordinary function, plus a description the model can read.
  • The model decides; your code executes. That boundary is where safety lives.
  • Generated arithmetic looks right and often is not - a local model got 47 × 89 wrong in one of three tries.
  • The loop is a plain for loop. No framework is needed to build an agent.

Quick check before you move on

What is the key difference between a chatbot and an agent?
An agent can take actions through tools and react to their results, not just generate text.
What are the three parts of an agent?
An LLM, tools, and a loop.
Who runs the tool - the model or your code?
Your code. The model only asks for it.
Why can an agent give a more reliable maths answer?
It hands the calculation to a real calculator instead of generating digits that look right.

Quiz

  1. 1.

    What is the key difference between a chatbot and an agent?

  2. 2.

    Name the three parts of the "Agent = ___ + ___ + ___" formula.

  3. 3.

    Why might an agent give a more reliable math answer than a plain chatbot?

  4. 4.

    A model writes "calculate(47 * 89)". Has the calculation happened?

Interview questions

What is an AI agent?

An LLM connected to tools and run in a loop: the model decides what to do, the application executes the chosen tool, the result is fed back as an observation, and the cycle repeats until the model produces a final answer.

Does the LLM execute tools itself?

No. It only generates a request. The application parses the request, decides whether to allow it, runs the function, and returns the result. That boundary is where permissions, validation, and safety checks belong.

Do you need a framework to build an agent?

No. A loop, a set of functions, and a prompt describing them are enough. Frameworks add convenience - tool schemas, memory, tracing - on top of the same pattern.

Comments

Sign in to leave a comment. Your name and photo come from Google; nothing else is shared.

Loading comments...