Chatbot vs agent β€” one shot vs loop

A chatbot takes your question and gives one answer. That's it. A customer asks "What's the refund policy?" and ChatGPT replies with canned text from its training data.

An agent does something different. It looks at your question and decides: "I need to run a query, check the result, maybe call another tool, and loop until I have the real answer." It's the difference between a parrot (ChatGPT) and a detective (agent).

Chatbot (One Shot)
How it works

User: "What's Apple's stock price?"

ChatGPT: "Apple's stock price as of my last training (April 2023) was around $170."

Reality: Wrong. Training data is stale.

Agent (Looped)
How it works

User: "What's Apple's stock price?"

Agent: "I need to fetch this. Calling yfinance."

Result: Real price. Real data. Updated now.

The agent is only smarter because it has two superpowers: tools (functions it can call) and a loop (repeat until done). Without those, it's just a chatbot.

The agent loop: think β†’ act β†’ observe β†’ repeat

Every agent runs the same basic loop. It's simple but powerful.

🧠 Think: LLM decides next step
↓
βš™οΈ Act: Call a tool or return answer
↓
πŸ‘οΈ Observe: Get the tool's result
↓
πŸ” Done? Loop back or stop

Real example from Jumia Kenya support:

πŸ‘©
Scenario
Aisha handles a refund request

Customer: "I want a refund for order #4521."

Aisha (the agent) thinks: "I need to look up this order in the system."

She acts: Calls lookup_order(4521)

She observes: Order found. Status: delivered. Amount: KSh 4,500.

She thinks again: "Refund is valid. I should process it."

She acts: Calls process_refund(4521, 4500)

She observes: Refund successful. Status: pending_bank_transfer.

She thinks: "Done. I can reply now."

She returns: "Refund approved. You'll see KSh 4,500 in your account in 2–5 business days."

That's the agent loop in real life. One question. Multiple steps. Multiple tools. One final answer.

The three ingredients: LLM + tools + loop

An agent is made of exactly three pieces. Remove any one, and it stops being an agent.

Ingredient 1
LLM (decision maker)
The LLM is the brain. It reads the question, looks at past actions, and decides what to do next. No LLM = no reasoning.
Ingredient 2
Tools (actions in the world)
Tools are how the agent touches the real world. Without tools, the LLM can only talk. With tools, it can fetch data, write files, send emails, update databases.
Ingredient 3
Loop (repeat until done)
The loop keeps the agent running. After each tool call, the result goes back to the LLM, which decides what to do nextβ€”call another tool, or stop.
Why this matters:
You've already met ingredient 1 (LLMs). Lesson 07 introduces tools. Lessons 08–10 are all about the loop. By Lesson 11, you'll write a complete agent from scratch.

Why plain LLMs aren't agents (and what they can't do)

A plain LLM can only predict text. It has no access to tools, no memory of past actions, and no loop. Let's see what happens when you ask it a question it can't answer from training data.

Example: Stock price lookup

Same question, two different systems. Watch what happens.

plain_llm.py ChatGPT trying to guess
Output (hallucinated)
TCS (Tata Consultancy Services) stock price is approximately β‚Ή3,500–3,700 per share as of early 2024. For the most current price, check the NSE website. [This is a guess. The actual price might be β‚Ή3,800. The LLM doesn't know; it can't fetch live data.]
agent.py Agent with tools
Output (real data)
Agent thinks: "I need to fetch TCS stock price." Agent calls: fetch_stock_price("TCS", "NSE") Agent observes: β‚Ή3,820.50 Agent replies: "TCS is currently trading at β‚Ή3,820.50 on the NSE."

The difference: ChatGPT guesses. The agent knows. That's because the agent has a tool and a loop.

This is the core problem agents solve:
LLMs are unreliable for present-day facts, private data, and multi-step reasoning. Agents fix this by wrapping the LLM in a loop and giving it tools to fetch real data.

Pseudocode of the minimal agent loop

Here's what happens under the hood. This is pseudocodeβ€”we haven't implemented the tools yet. That's Lesson 07. But this is the skeleton every agent follows.

minimal_agent.py The agent loop in 15 lines

That's it. The agent is just a while-loop that keeps asking "What should I do next?" until the LLM says DONE.

The observation-step tension: how the agent knows to stop

The trickiest part of the loop is: when does the agent stop? It can't loop forever. Three strategies exist.

Strategy 1
Explicit DONE action
The LLM can output a special action: "DONE: I have the answer now." The loop sees this and returns the reply.
Strategy 2
Max iterations
The loop has a hard limit: "Run for max 10 iterations, then stop." After 10 loops, give whatever answer the LLM has.
Strategy 3
Stop tokens
The LLM is trained to output "DONE" when finished. If the output doesn't match an available tool, stop.
Best in practice
Combine all three
Use explicit DONE + max iterations + stop tokens together. This prevents runaway loops and handles edge cases.

The challenge is observation tension: the LLM needs information from past tool calls to decide what to do next, but if it loops forever trying to "understand" each result, the agent never completes. Good agent design balances exploring and deciding.

Real-world analogy: Aisha at Jumia Kenya support revisited

Let's map the agent loop onto a real human job. Aisha works at Jumia Kenya customer support. She handles refund requests.

🏒
The Agent Analogy
Aisha's daily workflow

Her question (goal): "Customer wants a refund for order #7834."

Her tools (available actions):

  • lookup_order(order_id) β€” check order status
  • check_policy(order_age, category) β€” is refund allowed?
  • process_refund(order_id, amount) β€” issue the money
  • send_email(customer, message) β€” reply to customer

Her loop (think-act-observe):

1. Think: "I need to check if this order is eligible for refund."
2. Act: Call lookup_order(7834)
3. Observe: Order found, 15 days old, electronics category
4. Think: "Jumia's policy: electronics can be refunded within 30 days. This qualifies."
5. Act: Call process_refund(7834, KSh 12,500)
6. Observe: Refund approved and queued
7. Think: "Done. I should confirm with the customer."
8. Act: Call send_email(customer@example.com, "Your refund of KSh 12,500 is on the way.")
9. Done. Close the ticket.

Aisha is an agent because she has three things:

  • Intelligence (LLM role): She can read the request and decide what to do.
  • Tools: She has access to the order system, refund system, and email.
  • A loop: She loops through multiple actions (lookup β†’ check β†’ process β†’ notify) until the problem is solved.

Without tools, she can't access data. Without a loop, she can't do multi-step work. The agent is the same idea, but for software.

What you'll build in Lessons 07–10

Now that you understand the three ingredients, here's your roadmap:

Lesson 07
Function calling β€” first tools
You'll define tool schemas and teach the LLM to call them. By the end, your agent can fetch real data from yfinance.
Lesson 08
The ReAct loop β€” reason + act
You'll implement the full think-act-observe loop. The agent will write out its reasoning at each step.
Lesson 09
Multi-step workflows β€” agents that plan
Instead of one-off tool calls, your agent will break complex goals into sub-tasks and loop through them.
Lesson 10
Web scraper agent β€” multi-domain looping
Your agent will browse the web, make decisions about what to click, and collect data autonomously.

By Lesson 10, you'll have built four complete agents from scratch, each tougher than the last.

How AI teams use this concept

Every time a large LLM chatbot like Claude or GPT-4 handles a complex question, it's using an internal agent-like loop. The model reads the query, decides if it needs to "call" knowledge (retrieve context from its memory), thinks about the answer, and loops through reasoning steps. The agent loop is how modern AI systems go beyond single-pass prediction to multi-step reasoning and tool use.

Try it yourself

Mini Challenge

Design an agent for a real scenario

Pick a customer support task (refund request, password reset, order tracking). Write down:

  • The question the agent receives
  • 3–5 tools it would need
  • The steps in the loop (think-act-observe-repeat)

Example: A password reset agent gets the question "I forgot my password." Tools: `validate_email()`, `send_reset_link()`, `confirm_reset_status()`. Loop: validate β†’ send β†’ confirm β†’ done.

Test your knowledge

Question 1 of 5
What is the key difference between a chatbot and an agent?
Question 2 of 5
Which of these is NOT an ingredient of an agent?
Question 3 of 5
What does "observe" mean in the think-act-observe loop?
Question 4 of 5
Why can't a plain LLM reliably answer "What is TCS's current stock price?"
Question 5 of 5
In the Aisha (Jumia Kenya support) scenario, what was the "loop"?
0
/5
Excellent! You understand agent architecture.
Africa & India's Best AI Academy
πŸ€– AI-first πŸŽ“ Placement Assistance

You understand the loop.
Now go build with it.

Join the Best AI Program: The AI-Era Agentic Engineer β€” 5 months, fully online, with placement assistance. Week 1 is free.

Explore The AI-Era Agentic Engineer β†’