{ Akbar NoorMohamed }

My Notes - Understanding AI Agents from Scratch

May 31, 2025
     #learning   #ai  
3 minutes

Writing down the simplest explanation of AI Agents I can find - for me to remember, and for others just starting out. Capturing this as my personal reference of my learnings into the AI Agents space.

What’s an AI Agent?

An AI agent is like a smart helper that can:

  • Understand what you ask (like Alexa or Gemini)
  • Make decisions (like a robot vacuum deciding where to clean)
  • Do tasks automatically (like a chatbot answering customer questions)

Think of it as a tiny robot inside your computer that follows instructions but can also “think” a little on its own.

How Do AI Agents Work?

Here’s a simple breakdown:

  1. They listen (get input from you, a sensor, or the internet)
  2. They think (process the info using rules or AI)
  3. They act (respond, move something, or do a task)
  4. They learn (sometimes) - some agents get better over time

Different Types of AI Agents

Not all AI agents are the same. Some are simple, some are smarter:

  • Rule-based agents - Follow strict “if this, then that” rules (like a thermostat turning on when it’s cold)
  • Smart assistants - Understand language (like ChatGPT)
  • Self-learning agents - Improve with experience (like Netflix recommending shows you might like)

How to Make Your Own Simple AI Agent

You don’t need to be a coding expert! Here’s how to build a basic chatbot-style AI agent in a few steps.

Step 1: Get a Free AI Brain (API Key)

We’ll use OpenAI’s free tools (like ChatGPT).

  1. Go to OpenAI’s website and sign up
  2. Get an API key (this lets your code talk to OpenAI)

Step 2: Write a Tiny Program

We’ll use Python (a beginner-friendly coding language).

  1. Install Python from python.org
  2. Open a code editor (like Notepad or VS Code)
  3. Run the following command to install openai module
pip install openai==0.28
  1. Copy and paste this: https://gist.github.com/Akbarsait/783696f671bdb724882050a84ed1d2b4
import openai

openai.api_key = "your-api-key-here"  # Replace with your key

def ask_openai(question):
    try:
        response = openai.ChatCompletion.create(
            model="gpt-3.5-turbo",
            messages=[
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": question}
            ]
        )
        return response['choices'][0]['message']['content']
    except Exception as e:
        return f"An error occurred: {e}"

if __name__ == "__main__":
    user_question = input("Ask me anything: ")
    answer = ask_openai(user_question)
    print("AI Response:", answer)

Save the file as my_ai_agent.py

Step 3: Run Your AI Agent

  1. Open Command Prompt (Windows) or Terminal (Mac/Linux)
  2. Type:
python my_ai_agent.py
  1. Ask it anything, like “What’s the weather tomorrow?” or “Tell me how credit card transactions work?”

Boom! We just made an AI agent. 🎉

Title Photo by Akbar Noormohamed on Unsplash