SyntaxPilot
Courses/AI: Zero to Agents/Lesson 1

AI: Zero to Agents · Lesson 1 of 40 · 11 min

AI vs ML vs DL vs GenAI vs Agents

published

These are the notes for AI episode 1. Instead of memorising definitions, you invent each idea yourself, starting from one problem: a spam filter. Every time the old idea breaks, the fix becomes the next term: rules, then machine learning, then deep learning, then generative AI and LLMs, and finally AI agents. Every Python example below runs as-is in the SyntaxPilot compiler, and the outputs shown are real.

The problem: your phone is full of spam

Every day your phone gets messages like "Congratulations, you won a lottery!" Your job is to build a spam filter.

The obvious way is to write a rule: if the message contains the word lottery, it is spam. But spammers adapt. Tomorrow the message says "claim your free prize", or spells lottery with zeros: "l0ttery". So you write another rule, and another. Even after a thousand rules, a new trick shows up.

Demo 1: hand-written rules fail

# Rules written by a human
def check(msg):
    if "lottery" in msg:
        return "SPAM"
    return "OK"

print(check("win free lottery"))
print(check("claim your free prize"))
print(check("w1n fr33 l0ttery"))

Output:

SPAM
OK
OK

Two of the three spam messages slipped through. A human writes the rules, and no human can predict every future trick.

A rule only knows what you wrote into it.

The fix: learn from examples (machine learning)

Think of teaching a small child what a mango is.

Way What you do What happens
Way 1: rules "It's yellow, oval, smells sweet" A raw green mango fails the rule; a yellow lemon passes it
Way 2: examples Show 100 mangoes and 100 things that are not mangoes, no rules The child picks up the pattern and recognises new mangoes

We can do the same with a computer: give it examples, not rules.

Demo 2: a spam filter that learns

# The computer learns from examples
spam = ["win free lottery", "free recharge offer", "claim your prize now"]
normal = ["meeting at 5 pm", "send me the notes", "call mom tonight"]

score = {}
for msg in spam:
    for word in msg.split():
        score[word] = score.get(word, 0) + 1
for msg in normal:
    for word in msg.split():
        score[word] = score.get(word, 0) - 1

def check(msg):
    total = sum(score.get(w, 0) for w in msg.split())
    return "SPAM" if total > 0 else "OK"

print(check("free prize for you"))
print(check("notes for the meeting"))

Output:

SPAM
OK

How it works:

  • Every word seen in a spam message gets its score raised by 1; every word seen in a normal message gets it lowered by 1.
  • To check a new message, add up the scores of its words. A positive total means SPAM.
  • We wrote no rule about which words are spammy. The computer built the score dictionary itself, from six examples.

"free prize for you" was never in the data, yet it is caught. Learning a pattern from examples and answering correctly on new cases is machine learning (ML).

Where the names came from

  • Artificial intelligence (AI) means machines doing tasks that need intelligence. John McCarthy chose the name in the 1955 Dartmouth proposal; the Dartmouth workshop took place in the summer of 1956.
  • Machine learning was coined by Arthur Samuel in 1959. He worked at IBM, and his checkers program got better by playing game after game.
Old way New way
You write the rules You give examples (data) and the computer learns a model

A model is just the learned pattern, like our dictionary of word scores.

Next problem: photos have no words

A fruit seller wants an app: put in a photo, and it says mango or lemon. Spam had words that were easy to count. A photo has no words. It is lakhs (hundreds of thousands) of tiny coloured dots called pixels.

The obvious approach: decide yourself what to measure, for example how yellow is the photo? A measured property like that is called a feature.

Demo 3: a hand-made feature fails

# A hand-written feature: how yellow is the photo?
mango = ["Y", "Y", "Y", "G", "Y", "Y"]
lemon = ["Y", "Y", "Y", "Y", "G", "Y"]

def is_mango(photo):
    yellow = photo.count("Y") / len(photo)
    return yellow > 0.6

print("mango photo:", is_mango(mango))
print("lemon photo:", is_mango(lemon))

Output:

mango photo: True
lemon photo: True

Each "photo" has six pixels (Y = yellow, G = green). Both are 5/6 yellow, so the feature calls both of them mango. A human picked the feature, and we don't really know whether we recognise a mango by its shape, its texture or something else. Hand-writing the right features for lakhs of pixels is almost impossible.

The fix: let the computer learn the features (deep learning)

Picture a factory line that sorts fruit:

Factory line Deep learning
Worker 1 spots edges and colours Early layers learn simple patterns
Worker 2 spots curves and shapes Middle layers combine them into shapes and texture
The final checker says mango or lemon The whole line is a neural network

The big idea: what each layer looks for is also learned from examples. A neural network with many layers is called deep learning: "deep" just means many layers. Your phone's face unlock and voice typing run on it.

Next problem: labelling is not writing

So far our models choose a label from a fixed list:

in : "win free lottery"
out: SPAM

in : photo.jpg
out: mango

Now: "Write a leave application to my teacher." There is no list of answers to pick from. A brand-new text has to be created every time, and a label-picking model is stuck.

The fix: predict the next word (generative AI)

Your phone keyboard already shows the way. Type good and it suggests morning · night · luck. Keep tapping a suggestion and a whole sentence appears. Creating text is predicting the next word, again and again. The keyboard learned which word usually follows which by seeing lots of text: learning from examples again. Scale that up to internet-sized text and a giant deep learning model, and it writes letters, stories and code.

Demo 4: a tiny text generator

# Generative AI in miniature: predict the next word
text = "chai is hot . chai is sweet . coffee is hot . chai is life"
words = text.split()

follows = {}
for a, b in zip(words, words[1:]):
    follows.setdefault(a, []).append(b)

def next_word(w):
    options = follows[w]
    return max(set(options), key=options.count)

w = "chai"
sentence = [w]
for _ in range(3):
    w = next_word(w)
    sentence.append(w)
print(" ".join(sentence))

Output:

chai is hot .
  • zip(words, words[1:]) pairs every word with the word after it, and follows remembers them. After is we saw hot, sweet, hot, life, so the most common next word is hot.
  • Starting from chai, the loop appends the most likely next word three times.

Nobody told the program to print that sentence. It built it word by word. That is generative AI in its smallest form.

Generative AI and LLMs

Term Meaning
Generative AI Models that create new content: text, images, audio, code
LLM (Large Language Model) A huge next-word predictor for text. "Large" = trained on enormous amounts of text, with billions of learned numbers
Prompt Your question or instruction to the model
Answer New text, generated word by word

OpenAI launched ChatGPT on 30 November 2022, and since then LLM chatbots have reached everyone's phone.

Your prompt  ->  LLM (next word, again and again)  ->  Answer (new text)

Next problem: an answer can't book a ticket

You say: "Book me a train ticket from Delhi to Mumbai for tomorrow." A chatbot tells you the steps: open the booking site, search trains, check seats. But you still book it yourself.

It is like phoning a chef for a biryani recipe: the chef tells you, you cook. Now imagine the chef comes to your kitchen, buys the vegetables, cooks, tastes and serves. That chef needed three things:

  • a goal,
  • tools (hands),
  • a loop: act, look at the result, decide again, until the job is done.

Demo 5: a tiny agent

# An agent: goal -> think -> use a tool -> look -> repeat
trains = {"12951": 0, "12953": 4}   # train number: seats left

def search():
    return list(trains)

def seats(t):
    return trains[t]

def book(t):
    trains[t] -= 1
    return "BOOKED " + t

goal_done = False
memory = []
while not goal_done:
    if not memory:
        memory = search()
        print("search ->", memory)
    t = memory.pop(0)
    left = seats(t)
    print("seats", t, "->", left)
    if left > 0:
        print(book(t))
        goal_done = True

Output:

search -> ['12951', '12953']
seats 12951 -> 0
seats 12953 -> 4
BOOKED 12953

The agent has three tools (search, seats, book) and a loop. Train 12951 has zero seats, so it does not stop: it tries the next train, finds four seats, and books. Act, look, decide, repeat.

Here the agent's "brain" is a single if. In a real AI agent, an LLM decides which tool to use and when.

AI agent = LLM + tools + a loop.

How they nest: the tiffin box

Box Term Example from this episode
The whole tiffin (biggest box) Artificial Intelligence: machines doing smart tasks, even rule-based ones The rule-based spam checker
A box inside it Machine Learning: learns from data The word-score spam filter
A smaller box inside that Deep Learning: neural networks with many layers The fruit-sorting factory line
The special dish inside Generative AI: creates new content (LLMs) The next-word generator

AI ⊃ ML ⊃ Deep Learning ⊃ Generative AI. An AI agent is not another box: it gives an LLM tools and a loop so it can get work done.

Glossary

Term One-line meaning
Artificial intelligence (AI) Machines doing tasks that need intelligence
Rule-based system A human writes the rules; it only knows what was written
Machine learning (ML) Learning a pattern from examples (data) instead of hand-written rules
Data The examples a model learns from
Model The learned pattern (e.g. the word-score dictionary)
Feature A measured property of the input (e.g. "how yellow")
Label An answer picked from a fixed list (SPAM/OK, mango/lemon)
Pixel One tiny coloured dot of an image
Neural network Layers of learned pattern-finders, each building on the last
Deep learning A neural network with many layers
Generative AI AI that creates new text, images, audio or code
LLM Large language model: a huge next-word predictor
Prompt The question or instruction you give an LLM
Token A small piece of a word that real LLMs work with (covered later in the course)
AI agent An LLM using tools in a loop to reach a goal

Common mistakes and misconceptions

A word the model has never seen

text = "chai is hot . chai is sweet . coffee is hot . chai is life"
words = text.split()
follows = {}
for a, b in zip(words, words[1:]):
    follows.setdefault(a, []).append(b)

def next_word(w):
    options = follows[w]
    return max(set(options), key=options.count)

print(next_word("pizza"))
KeyError: 'pizza'

Our tiny model never saw pizza in its data, so it has no next word for it. A model only knows what was in its data. Real LLMs train on huge data and break words into small pieces called tokens, so nothing is totally unseen.

"Machine learning is magic and catches everything"

Feed the learning spam filter from Demo 2 the zero-spelled message:

print(check("w1n fr33 l0ttery"))
print(check("free notes"))
OK
SPAM

w1n, fr33 and l0ttery never appeared in the six examples, so they all score 0 and the message is called OK. And "free notes" is wrongly called spam, because free scored +2 and notes only -1. The fix is not more rules: it is more and wider examples.

Other mix-ups

Misconception Reality
"AI and ML are the same thing" ML is one part of AI. A rule-based program is AI but not ML
"Deep learning means the AI thinks deeply" "Deep" just means many layers
"An AI agent is a smarter chatbot" A chatbot answers; an agent uses tools in a loop to finish a goal
"Generative AI is separate from deep learning" Generative AI sits inside deep learning (LLMs are deep learning models)

Practice

  1. Without running it, predict what the Demo 2 filter says for "claim your free prize". Then run it.
  2. Add three more spam and three more normal messages to Demo 2 so that "w1n fr33 l0ttery" is caught.
  3. Add a third train to the agent and make the first two full. What does the agent print?
  4. In the agent, make every train full. What happens, and how would you stop it?
  5. Name three apps on your phone that use machine learning, and say what each one predicts.
Solutions and hints

1. SPAM. The scores are claim +1, your +1, free +2 (it appears in two spam messages), prize +1: total 5, which is above 0.

2. Add spam examples that use those spellings, plus a few more normal ones:

spam = ["win free lottery", "free recharge offer", "claim your prize now",
        "w1n a fr33 phone", "l0ttery winner today", "fr33 gift card"]
normal = ["meeting at 5 pm", "send me the notes", "call mom tonight",
          "lunch at noon", "see you at class", "notes are ready"]

Now check("w1n fr33 l0ttery") prints SPAM: w1n +1, fr33 +2, l0ttery +1. The model learns only from what is in its data.

3. With trains = {"12951": 0, "12953": 0, "12955": 2} the output is:

search -> ['12951', '12953', '12955']
seats 12951 -> 0
seats 12953 -> 0
seats 12955 -> 2
BOOKED 12955

4. It loops forever: when memory empties it searches again and keeps checking full trains. Real agents need a stop condition, such as a step limit:

trains = {"12951": 0, "12953": 0}

def search():
    return list(trains)

def seats(t):
    return trains[t]

goal_done = False
memory = []
steps = 0
while not goal_done and steps < 5:      # a step limit stops a hopeless loop
    steps += 1
    if not memory:
        memory = search()
    t = memory.pop(0)
    print("step", steps, "seats", t, "->", seats(t))
if not goal_done:
    print("gave up: no seats on any train")
step 1 seats 12951 -> 0
step 2 seats 12953 -> 0
step 3 seats 12951 -> 0
step 4 seats 12953 -> 0
step 5 seats 12951 -> 0
gave up: no seats on any train

5. Examples: a spam folder (spam or not), a photo gallery that groups faces, a keyboard that suggests the next word, a maps app that predicts arrival time.

Quick quiz

Which one is an AI agent?

  • A. An app that answers questions
  • B. A model that labels fruit photos
  • C. An AI that books your train ticket: searches, checks seats, pays, confirms
  • D. All of them
Answer

C. An agent works towards a goal by using tools in a loop. A only answers (that is generative AI). B only picks a label (that is machine learning).

Interview questions

  • What is the difference between AI, machine learning and deep learning? Draw how they nest.
  • Why do hand-written rules fail for problems like spam detection?
  • What is a feature? Why is deep learning useful when features are hard to design by hand?
  • What does "deep" mean in deep learning?
  • How does an LLM generate text? (It predicts the next token, again and again.)
  • What makes something an AI agent rather than a chatbot? (A goal, tools, and a loop that acts and checks results.)

Summary

  • Rules break, so we learn from examples: machine learning.
  • Hand-made features break, so learned layers find the features: deep learning.
  • Labels can't write a letter, so we predict the next word: generative AI and LLMs.
  • Answers can't book a ticket, so we give an LLM tools and a loop: an AI agent.
  • AI ⊃ ML ⊃ Deep Learning ⊃ Generative AI; an agent is an LLM using tools in a loop.

Next episode: we said the computer learns from examples, but how does learning actually happen? Data, features, labels, training and inference, with a chai stall example.