← 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 chatbot takes a prompt and gives back text. One reply, done. It cannot check anything or do anything. Ask it for 47 × 89 and it writes the number that LOOKS most like the right answer - which is not always the right answer.

An agent can do more. It can decide "I need a tool for this", have that tool run, look at the result, and decide again - as many times as the job needs.

So the formula for the rest of this module is: Agent = LLM + tools + a loop. This lesson explains the three parts. No code to build yet - Lessons 1.5 to 1.7 build them by hand, without 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.

An everyday example: a shop owner and a helper

A customer asks a shop owner: "47 packets at ₹89 each - how much?"

  • Like a chatbot: the owner answers from memory, fast and sure - "₹4193." It sounds right. It is ₹10 off.
  • Like an agent: the owner thinks "I should not guess this", and tells the helper at the counter: "Type 47 × 89 on the calculator."
  • The helper presses the buttons and reads out the screen: "4183."
  • The owner hears the number and tells the customer: "₹4183."
  • If the customer then says "add ₹50 for delivery", the owner asks the helper again. That is the loop: ask, hear the result, decide again.
  • Notice that the owner only TALKS. He never touches the calculator - the helper does. The table shows who is who in an agent.
The story -> the agent
The shop ownerThe LLM. It decides what to do next, but only by talking (writing text).
"Type 47 × 89 on the calculator"A tool request: text the model writes, naming the tool and what to give it.
The helper who presses the buttonsYour code. It reads the request and runs the tool.
The calculatorThe tool: an ordinary Python function.
The helper reads out "4183"The observation: the tool’s result, handed back to the model.
Asking again for the delivery chargeThe loop: decide, act, observe - and repeat until done.
"₹4193" from memoryA chatbot: text that looks like a right answer.

Chatbot or calculator? We measured it

The program below asks a local model three multiplications, and prints its answer next to Python’s:

  • 47 × 89: the model was right in this run. Across three runs it said 4193 once - wrong by 10.
  • 4783 × 2917 and 98765 × 4321: wrong every time, by thousands.
  • Nothing is broken. The model generates text that looks like arithmetic. Generating is not calculating.
  • Python’s a * b is right every time. That is why an agent hands sums to a tool.
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 three parts of an agent

  • The LLM decides. It looks at the question and everything so far, and chooses: answer now, 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 get one exchange. With it, the agent can take as many steps as the problem needs.
One round, in words
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"
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 special about a tool. It has three pieces:

  • 1. An ordinary function in your code: calculate(expression), get_weather(city), read_file(path).
  • 2. A short description the model can read: what the tool does, and what to give it.
  • 3. A way for the model to ask for it by name - an agreed text format.
  • The description matters as much as the function. The model never sees your code; it only knows what the prompt tells it.
  • Lesson 1.5 writes the description and the request format by hand.

The model decides; your code runs the tool

  • A model only ever writes text. When it "calls" calculate, it really writes a line like "use calculate on 47 * 89".
  • Your program reads that line and runs the function - like the helper pressing the calculator buttons.
  • So the model never touches your files, your network or your database. Your code does, for it.
  • This line between the two is the most important idea in agent design. Your side decides which tools exist, which inputs are allowed, and what is never allowed.
  • Every safety check later in the course lives on your side of the 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

The whole agent fits in a few lines of plain Python:

  • The loop is a for loop.
  • The tools are Python functions.
  • The decision is a line of text the model writes.
  • LangChain, LangGraph, CrewAI and AutoGen all do this for you - but you do not need them to understand it.
  • Build it by hand first (Lessons 1.5 to 1.7). Then in Module 2, when a framework hides these pieces behind a few lines of setup, you know what those lines do.
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

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