Create AI Agents From Scratch With Python! (Free Course)

Hasan Aboul Hasan · Beginner ·🤖 AI Agents & Automation ·2y ago

Key Takeaways

The video demonstrates how to create AI agents from scratch using Python, integrating tools like Open AI API and JSON to mimic human behavior and automate tasks. It covers the basics of AI agents, autonomous workflows, and multi-agent systems, providing a comprehensive guide to building AI agents that can think, take action, and access real-time data.

Full Transcript

hi everyone in this mini course you will learn what are AI agents why and how to use them and how to build one totally from scratch without using any Services any plugins any libraries anything from scratch with a simple example that anyone can understand and build then we will build a real world AI agent that I'm sure will shock you and change the way you think about Ai and its capabilities something really super interesting if you are ready let's get started so what is an AI agent to make things simple super simple let's go with this example here I am in chpt and if I ask it this question please focus on this my website is lan.com what is the website's response time do you think chip can answer this question let's see I can directly access real time data or browse the internet so one of the main limitations of Chip or language models in general that they don't have access to real time data they don't have access to external functionalities and data other than what they were trained on so this is one of the main limitations of language models now when you build an AR I agent what you are going to do is to make this language model capable of accessing real time data it will have external functionalities it can call functions it can call apis it can mimics humans Behavior not only that AI agents can take actions based on thoughts so it will understand your request it will take action based on that so it mimics how humans work so that's AI agent in short it can think take action and use external functionalities and access real time data and all this very important all this will be automated it's an autonomous AI agent I hope you got the idea so that's AI agent now the second question why you should build AI agents and what's the main benefit in simple words just imagine you are hiring a virtual assistant that can help you in almost any task whether in programming in digital marketing in creating content in replying to emails in customer support in almost anything you have a virtual AI assistant that can think and take actions based on your own use cases this is really a a game changer it helps you save countless hours and be way more productive and talking about productivity one of the best places for mastering this skill is skill sh they have an entire section dedicated to productivity featuring some of the top teachers like Ali abdal and Thomas Frank and many others this year I'm planning to dive into Ali abd's learning path on productivity my goal is to understand all the tips and tricks and combine them with AI to be more productive imagine transforming a productivity tip into an AI agent that automates tasks and save you countless hours for example one method I learned is the GTD method this approach is about organizing tasks into actionable items and categorizing them so that you can focus on what needs immediate attention without getting overwhelmed to elevate this method I'm trying to integrate AI with GTD to help me sort my tasks automatically based on deadlines importance person productivity and other factors not only that on skillshare you will find my full course on building AI Agents from scratch this course will guide you step by step on understanding what are AI agents and how to build them totally from scratch I'll be also there on skillshare if you have any questions related to my courses skillshare is one of the largest online learning communities out there with thousands of classes covering almost everything from design illustration to marketing business freelancing and even programming and development there's something for everyone and what's unique and special about skure is the learning path section there are over 100 paths each containing a set of classes organized in a stepbystep order to help you master a specific skill from scratch not only that I partnered with skiler so the first 500 people to use my link in the description below will get one month free access go now get started learn skills from all over the world and shape your future thank you skillshare for this offer and thank you for supporting my adree video videos and supporting my channel okay let's now get into the real work and see how we can build AI Agents from scratch I will start with a very simple example then we move into an advanced real world AI agent so the first example is an agent that can answer questions like this what is the response time so here is a new empty python project so I will start start with a simple main script I will create a file for actions and a file for prompts so the AI agent mainly is a combination between external functions and a special prom so in the actions I will Define a simple action this is like a tool that the AI can use this is a very basic function that you give it a URL and based on the URL it will return a specific response time again this is very basic to understand the concept in the next example we will go the real world AI agent and see the magical power of AI agents please follow up now to understand the concept first so we defined an action for this AI agent then in the prompt section we will Define the AI agent system prompt and this system prompt is the main and the core of the AI agent this is what makes the agent mimics humans Behavior so please Focus very well on this part if you get it you can build any agent you want so let's pce The Prompt and here we are please Focus for 30 seconds you run in a loop of thought action pose and action response so we are telling the language model here that you will enter a Loop of thought and action and action response look at this use thought to understand the question you have been asked so the thought to understand the user's question the action to run one of the actions available to you and the action response will be the result of running those actions and then you tell the model what actions are available what tools the agent will have so in our case in this basic example we have this function get response time that we defined here this action so now the language model can call this function or have the capability of calling this function I will show an example the function with the parameter name and it will return the response time so this the description of the action and then and this is very important I will give the AI an example session how it will work so for example if I ask it what is the response time for my website first it will generate a thought it will think about it I should check the response time for the web page first this is how you think if I ask you now what is the response time of my website first you will go and use a tool to check the response time this is what the AI agent now is doing it thought about it and now it will pick an action so it picks an action and returns turn it in Json format in this structured format why you'll see a little bit but in short this Json will be returned in our code so we can call the function easily we can access Json easily then it will be called again with the action response it got the response from the action now it can use it to generate the final answer the response time for Hassan is for example 0.5 seconds so in short the agent here what I'm telling the agent is to think about the question and to pick a tool that can help in answering the question it will call the function return the result combine it with the question to generate the full answer I hope you got the idea it's somehow simple and now you can play with this prompt based on your case scenario so this is the system promt that we will use in our model and this is what we call the react prompt where the model can think and react based on that thought and take actions based on that thought anyway this is somehow related to prompt engineering if you are following my other videos maybe passed by this topic so this is a system prompt that we are going to use with our model perfect so now we have the actions we have the prompt that will power our agent we are ready to put put things together and create our simple agent okay so let's open a new terminal and get started create a new virtual environment let's activate perfect now since we are building an AI agent we need to power it with AI so I'll be using up and AI API pip install open AI I will keep all the code in just one script to make things simple for you and I will write the code in a very basic way for beginners and don't forget if you have any problem don't forget to join us on the Forum on my website I'll be there almost every day with the team with thousands of people to engage and learn together so we installed open AI let's create a new environmental file to save the open AI API key save it go back here and simply now import up Ai and load the environmental variables just create an open AI client with the API key and I created this simple function that generates text based on messages simply I'm calling the API open Ai and return back the response very basic simple function and here you can pass the model so now we have the function that calls open AI we will use it to build the agent first we Define the available functions for this AI agent so it can pick one from so simply create a list that contains the functions available remember that we may have multiple functions but since you are creating something basic here I'll keep it simple with one action and since this action is in the other module actions we will going to import here from actions import get response time perfect now we have a list of actions let's define The Prompt what you are going to ask this agent so prompt or let's say user prompt and let's say what is the response time of google.com for example and now I'll Define the messages the list of messages that will be passed to the AI model to the open AI API you can see here we have messages that is a parameter so I'm going to Define it and the system prompt will be our react system prompt so again let's go here and import it from prompts import system prompt and simply pass it here and for the user just pass the user prompt perfect the following code is almost the same in any agent will create a loop that allows the model to think and take action and then respond why we are in a loop remember because we are telling the model that you will run inside a loop so we will translate this Loop into a python Loop here for the agent to work properly so I'll paste the code let's explain it so I'll Define turn count and Max turns how many times you want the agent to think and repeat this process before answers I print the loop number or turn count then I will generate response using the messages parameter you see here the messages and then we will have the response from the AI model then remember I told you here I Define the functions in Json format why so the model or the code can extract Json and then can know the function name and the function parameters so when we extract the Json we are going to extract the function name look at this The Prompt we have the function name and the function parameters so now we can easily using Json extract these from the Json and then the model will run the action you see the printing running to simulate the process you will see now in action how this will happen then we will get the result then we will append the result to the messages and then loop again so in the second Loop we will have the response with the conversation so the model can answer the question it have now the response it have now the function output the results with the prompt it can answer the question it now have access to real data but everything is automated now we have only one small tiny problem this function extract Json to make things simple for you I created this function that helps you extract Json from any text so I will create here for example Json helpers and paste the code don't worry about the codes everything will be shared in detail in a full guide in the description just follow up and focus understand the concept then you can go and apply it yourself so from Json helpers input extract Json so now the function is ready and this is the code for our agent or autonomous AI agent so again we are defining a simple function that generates text with open AI it's a very basic function then we Define the available actions then we input our prompt whatever you want here and then the messages and then we run inside a loop to mimic humans Behavior so in the first step you will think what tool should I use then you call the tool you get a result then the second turn you use the result to answer the question this is how this works let's now try it and see if the AI agent is working perfectly so let's run python main.py oops we forgot to install n module so simply pip install it perfect let's run the script again and see the magic and perfect you can see now in Loop one the agent thought about the prompt I need to check the response time for google.com it got the action and then it ran the action for Google it got the result and in Loop two it combined the result with the prompt with the user query and answer the question the response time for Google is 0.3 seconds perfect let's try for example for another website for my website run the same it thought about it it got the response and answered the question based on the action so this is how you can build an AI agent from scratch now one note that this prompt is not the perfect prompt you can play with it change with it based on the results learn more about react learn more about prompt engineering you can check my full free course description below and get started anyway you can play with the prompt and see different outputs and how the results can change so this is how the basic AI agent work let's now see a real word example the SEO auditor AI agent this is really super interesting so this is the SEO auditor AI agent it's almost the same code we have the prompt we have the actions and we have the main AI agent code so in the AC now look at this I gave the AI agent access to this API if you open this API it's simply a website SEO analyzer you can get a report for any website with this API using a simple URL so now the agent with this action have access to any website and can analyze it this is the action and this is the prompt it's almost identical to the last one but now we have different AC ction name and a little bit different example session I should generate a full SEO reput here instead of getting the response time in the last example so it's now more powerful it have a lot of data about any website so in the main section here in the main script again I'm doing the same available actions user query messages and the loop the same exact logic but here in our case I'm using simple llm to make things simple it's an open source Library I developed to make interactions with language model super easy so when you define this you can call the language model directly with generate response very simple and you can even change here the the providers for Gemini anthropic and so on so it's super easy and helps you interact with any language model in a few lines of code and what's nice about simple LM has builtin tools like the Json helpers it's built in to extract Json and you see in the actions it allow you to call any rapid API with this simple class anyway so just to make the code easier I use simpler LM here if you go here now and ask the AI agent what is the response time let's see I will run this let's activate the virtual environment and let's run the main script perfect so the thought to find the response time I need to generate a full SEO report first so generates the full report you can see here the full report and then it answer the response time of Hass is 0.08 now this is a real value here again I will clear and make things more interesting for example I will say suggest some optimizations tips optimization tips for learnwith hassen.com a generic question it's like you have an AI expert in your company and you ask it any question about any website so let's run the script again and see now this generate SEO report and then perfect here are some optimization tips for web page lan.com improve imageo content link optimization the description keywords so B based on the SEO report it generates optimization tips it's really like magic so here an AI agent that analyze any website and you can ask any question about any website let's say here again another question how many images are there on let's pick another website 3 iid.com let's go here and run again we have five images any question about any website really like magic and if you want to learn more about AI agents and see more examples you can check out my full video library on my website and the last step this can be the back end of an AI chatbot on your website that your visitors can interact with and if you like to learn more about building an AI chatbot on WordPress press also from scratch and for free you can check out this video on my channel if you learn something new today smash the like button and see you in the upcoming videos

Original Description

The first 500 people to click my link will get a 1-month free trial of Skillshare 👉 https://skl.sh/heducate04241 Full Guide and Codes: 👉 https://learnwithhasan.com/blog/create-ai-agents-with-python/ ⭐ My Courses: https://learnwithhasan.com/courses 🌍 Website - https://learnwithhasan.com/ 🔗 Follow on X - https://x.com/hasan_ab_hasan 🧰 MY FAVOURITE TOOLS: https://learnwithhasan.com/tools-i-use/ Content: Topics covered in the course 0:00 What is an AI Agent? 0:38 Why Build AI Agents? 2:27 How to build AI Agents? 5:32 Build a Real World Example 18:10 #aiagents #generativeai #aritificialintelligence
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Hasan Aboul Hasan · Hasan Aboul Hasan · 10 of 49

1 How I Make Money With APIs (Revealing My Secrets!)
How I Make Money With APIs (Revealing My Secrets!)
Hasan Aboul Hasan
2 ChatGPT Prompt Engineering Course
ChatGPT Prompt Engineering Course
Hasan Aboul Hasan
3 7 ChatGPT Prompts No One Is Talking About 🤯
7 ChatGPT Prompts No One Is Talking About 🤯
Hasan Aboul Hasan
4 This is How Professionals Use ChatGPT (Advanced Course)
This is How Professionals Use ChatGPT (Advanced Course)
Hasan Aboul Hasan
5 Use ChatGPT Chains To Get Maximum Results!
Use ChatGPT Chains To Get Maximum Results!
Hasan Aboul Hasan
6 How To Build and Sell an API Without Coding!
How To Build and Sell an API Without Coding!
Hasan Aboul Hasan
7 6 Ways To Earn Money With Prompt Engineering
6 Ways To Earn Money With Prompt Engineering
Hasan Aboul Hasan
8 How To Make Money with APIs & AI (Full Guide)
How To Make Money with APIs & AI (Full Guide)
Hasan Aboul Hasan
9 Digital Marketing with AI Free Course (20+ Practical Examples)
Digital Marketing with AI Free Course (20+ Practical Examples)
Hasan Aboul Hasan
Create AI Agents From Scratch With Python! (Free Course)
Create AI Agents From Scratch With Python! (Free Course)
Hasan Aboul Hasan
11 I built 10 AI Tools, and am giving it for free!
I built 10 AI Tools, and am giving it for free!
Hasan Aboul Hasan
12 The Fastest Way To Get Traffic To Any Website ( Free Tool )
The Fastest Way To Get Traffic To Any Website ( Free Tool )
Hasan Aboul Hasan
13 Build & Sell AI Chatbots Without Coding | Beginner's Guide 2025
Build & Sell AI Chatbots Without Coding | Beginner's Guide 2025
Hasan Aboul Hasan
14 How To Build & Sell Simple APIs (Step by Step)
How To Build & Sell Simple APIs (Step by Step)
Hasan Aboul Hasan
15 How To Build & Sell Tiny AI Agents Quickly! ( 3 Methods )
How To Build & Sell Tiny AI Agents Quickly! ( 3 Methods )
Hasan Aboul Hasan
16 Create a Comic in 1 Minute With AI #ai #chatgpt
Create a Comic in 1 Minute With AI #ai #chatgpt
Hasan Aboul Hasan
17 How I Saved $700/Month With Self Hosting
How I Saved $700/Month With Self Hosting
Hasan Aboul Hasan
18 3 AI Tools I Use Everyday to 10X My Learning & Business #aitools #ai
3 AI Tools I Use Everyday to 10X My Learning & Business #aitools #ai
Hasan Aboul Hasan
19 7 Vibe Coding Rules To build production ready apps with #ai
7 Vibe Coding Rules To build production ready apps with #ai
Hasan Aboul Hasan
20 This Is Getting Scary!  #chatgpt
This Is Getting Scary! #chatgpt
Hasan Aboul Hasan
21 My Weird Tech Stack!
My Weird Tech Stack!
Hasan Aboul Hasan
22 The Easiest Online Business To Start Today – No Code, No Budget
The Easiest Online Business To Start Today – No Code, No Budget
Hasan Aboul Hasan
23 The BEST Way to Build AI Tools That Actually Make Money
The BEST Way to Build AI Tools That Actually Make Money
Hasan Aboul Hasan
24 How To Get Free Traffic From ChatGPT in 2025 (AIO Course)
How To Get Free Traffic From ChatGPT in 2025 (AIO Course)
Hasan Aboul Hasan
25 Google’s NEW AI Image Model Is Insane (Nano Banana)
Google’s NEW AI Image Model Is Insane (Nano Banana)
Hasan Aboul Hasan
26 Stop Freelancing. Do This Instead.
Stop Freelancing. Do This Instead.
Hasan Aboul Hasan
27 Stop Building Automations to Save Time Only... Do This Instead
Stop Building Automations to Save Time Only... Do This Instead
Hasan Aboul Hasan
28 3 Steps to Launch your First Online Business With WordPress & AI
3 Steps to Launch your First Online Business With WordPress & AI
Hasan Aboul Hasan
29 How I' Would Make My First $1000 in 2025 (If I Had to Start Over)
How I' Would Make My First $1000 in 2025 (If I Had to Start Over)
Hasan Aboul Hasan
30 Get Traffic From ChatGPT in 2025
Get Traffic From ChatGPT in 2025
Hasan Aboul Hasan
31 How I Built a Business Using Google’s Nano Banana
How I Built a Business Using Google’s Nano Banana
Hasan Aboul Hasan
32 The Easiest Way To Make Money Online Without Any Skill
The Easiest Way To Make Money Online Without Any Skill
Hasan Aboul Hasan
33 3 Ways To Make Money With Nano Banana
3 Ways To Make Money With Nano Banana
Hasan Aboul Hasan
34 AI-Powered Affiliate Marketing — Full Course for Beginners (2026)
AI-Powered Affiliate Marketing — Full Course for Beginners (2026)
Hasan Aboul Hasan
35 How to Create Motion Graphics with ONE Prompt (No Design Needed)
How to Create Motion Graphics with ONE Prompt (No Design Needed)
Hasan Aboul Hasan
36 How To Earn MONEY With Images (No Bullsh*t)
How To Earn MONEY With Images (No Bullsh*t)
Hasan Aboul Hasan
37 Use this Trick to find business ideas
Use this Trick to find business ideas
Hasan Aboul Hasan
38 How to Build and Sell Simple Data Files in 10 Minutes
How to Build and Sell Simple Data Files in 10 Minutes
Hasan Aboul Hasan
39 How To Build and Sell Mini Apps With AI ( Full Practical Guide )
How To Build and Sell Mini Apps With AI ( Full Practical Guide )
Hasan Aboul Hasan
40 I Built a FREE Tool to Rank in Google AI Answers
I Built a FREE Tool to Rank in Google AI Answers
Hasan Aboul Hasan
41 Make Unlimited AI Videos for Free with Claude
Make Unlimited AI Videos for Free with Claude
Hasan Aboul Hasan
42 Stop Coding With AI Until You Know This #ai #aicoding #vibecoding
Stop Coding With AI Until You Know This #ai #aicoding #vibecoding
Hasan Aboul Hasan
43 Watch This Before you build Your AI App.... #ai #aiapps #aicoding
Watch This Before you build Your AI App.... #ai #aiapps #aicoding
Hasan Aboul Hasan
44 Prompt Engineering 2.0 Course ( 2026 Edition )
Prompt Engineering 2.0 Course ( 2026 Edition )
Hasan Aboul Hasan
45 How To Generate Unlimited Carousals With AI (Free Tool)
How To Generate Unlimited Carousals With AI (Free Tool)
Hasan Aboul Hasan
46 Video Editors Will Hate Me For This Video!
Video Editors Will Hate Me For This Video!
Hasan Aboul Hasan
47 Claude + VidTSX = Unlimited Free Video Creation!
Claude + VidTSX = Unlimited Free Video Creation!
Hasan Aboul Hasan
48 95% of Claude Code Users Don't Know #claude #vibecoding
95% of Claude Code Users Don't Know #claude #vibecoding
Hasan Aboul Hasan
49 The One Rule Most Vibe Coders Miss #claude #claudecode #vibecoding
The One Rule Most Vibe Coders Miss #claude #claudecode #vibecoding
Hasan Aboul Hasan

This video provides a comprehensive guide to creating AI agents from scratch using Python, covering the basics of AI agents, autonomous workflows, and multi-agent systems. It demonstrates how to integrate AI with task automation tools and build autonomous workflows that can automate tasks. By following this guide, viewers can create AI agents that can think, take action, and access real-time data.

Key Takeaways
  1. Create a new empty Python project
  2. Define a simple action (function) to return a response time based on a URL
  3. Define the system prompt that mimics human behavior by entering a loop of thought, action, and action response
  4. Give the AI an example session to demonstrate how it will work
  5. Install Open AI API using pip
  6. Create a new environmental file to save the Open AI API key
  7. Import Open AI and load the environmental variables
  8. Create a simple function that generates text based on messages
💡 The key insight from this video is that AI agents can be created from scratch using Python and integrated with tools like Open AI API and JSON to mimic human behavior and automate tasks.

Related AI Lessons

My agent kept reading data it wasn't allowed to. The prompt was never going to stop it.
Learn how to secure autonomous agents with proper credential management to prevent unauthorized data access
Dev.to AI
8 Must-Know AI Chatbot Tools That Actually Help Small Businesses
Discover 8 essential AI chatbot tools that can genuinely benefit small businesses, and learn how to choose the right one for your specific use case
Dev.to AI
Agent-Ready Commerce, Part 9: Evidence and Audit Are Part of the Product
Learn how to design agent-ready commerce platforms that provide evidence and audit trails for their decisions, enabling transparency and trust.
Dev.to AI
Agent-Ready Commerce, Part 8: Generated Claims Need Review, Evidence, and Expiry
Learn to review and validate generated commerce text to ensure accuracy and safety
Dev.to AI
Up next
Building Great Agent Skills: The Missing Manual
AI Engineer
Watch →