AI Agents Tutorial menu

What Are AI Agents?

An AI agent uses a language model as its "brain" to decide which actions to take, one step at a time, until a goal is reached.

Chatbot vs Automation vs Agent

ChatbotFixed automationAI agent
What it doesReplies with textRuns the same steps every timeChooses its own steps
Example"Explain RAG""Every night, email the sales report""Find why sales dropped and draft a report"
Handles surprisesOnly in wordsNo, it breaksOften, by trying another step
RiskLowLow, predictableHigher, it acts in the real world

The Parts of an Agent

  1. Model: the language model that thinks and decides.
  2. Instructions: the goal and rules (a system prompt).
  3. Tools: functions it can call: search, calculator, read file, send email, query a database.
  4. Loop: think, act, look at the result, repeat.
  5. Memory: what it has done so far, and sometimes facts saved for later.

A Tiny Agent-Like Program

This program is not intelligent yet, but it has the same shape: a goal, tools and a loop that stops when the goal is done.

Example

python
def check_stock(item):
    stock = {"chargers": 4, "earbuds": 0}
    return stock.get(item, 0)

def place_order(item, qty):
    return f"Ordered {qty} {item} from supplier"

items = ["chargers", "earbuds"]
for item in items:
    count = check_stock(item)
    print(f"{item}: {count} in stock")
    if count < 5:
        print(" ->", place_order(item, 10))
Output
chargers: 4 in stock
 -> Ordered 10 chargers from supplier
earbuds: 0 in stock
 -> Ordered 10 earbuds from supplier

Here the rule "order if fewer than 5" is fixed. In a real agent, the model would read the situation and decide, for example, "earbuds sell fast before Eid, order 20".

Real Examples of Agents

  • Coding agents: read a project, change several files, run the tests and fix failures.
  • Research agents: search many websites, read them and write a summary with sources.
  • Browser agents: fill forms, compare prices and book things on websites.
  • Customer support agents: look up an order in the database and start a return.
  • Data agents: open a spreadsheet, clean it and make charts.

A Goal in Plain English

You give an agent a goal, not a list of steps:

Example

text
Goal: Prepare a one-page summary of our September sales.
You can use: read_sales_file, calculator, write_document.
Rules: Do not email anyone. Ask me before saving any file.

The agent decides it should read the file, calculate totals and best sellers, then write the summary, and it asks before saving.

What Agents Are Not (Yet)

  • They are not fully reliable. They can misunderstand, loop or take a wrong step.
  • They are not always cheap: each step is another AI call.
  • They should not be trusted with important actions (payments, deleting data) without a human check.

A good agent task is one where mistakes are easy to spot and undo, such as drafting, researching or organising, before you trust agents with bigger jobs.

Exercise

Exercise

Which part of an agent lets it act in the outside world, like searching or reading a file?

Learn AI Agents with a teacher

Join the AI & Prompt Engineering course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp