I Built an AI Agent That Searches the Internet (Python Tutorial)

ChethanAIChronicles · Beginner ·🤖 AI Agents & Automation ·3mo ago

Key Takeaways

This video teaches how to build an AI agent from scratch using Python that can search the internet, use a calculator, and execute shell commands

Full Transcript

Hello guys, uh welcome back to my channel. Uh so last time I think we have done a simple AI agent uh using you know scratch from using Python. So what it will do is our agent will choose a goal you know choose the tools and execute actions right so that's what we have done the tools what we were used was calculator and shell command so that's what we have used uh you know in the last video so so by the end of this tutorial what we can do is we will uh create another agent okay uh which will search the web okay and retrieve the information and you know it can use the complete the task and at the end I will also teach you guys about how multiple tools can be called uh you know using the you know orchestrator I mean uh so how uh each and every tool uh LLM is deciding and you know what uh how the output is coming by using hybrid uh tools right so for example one tool how it is interacting with another tool to get the answer right so that also I will explain you guys uh so please stay stay till the end so that you guys will get lot of information uh so yeah so we can start uh with the uh so what I will do is I will start with the architecture overview first uh let me share my screen uh yeah so what I will do is I will Let's start with uh architecture. Okay. Uh just give me a minute, guys. Okay. Yeah. Uh hope you guys are able to see my screen. Yeah. So let CLS here. Let me you know minimize the panel so that you guys will understand. Right. So earlier what was there was right guys. So it is like a goal think LLM. So this is a basic concept of a guy. This one I explained you guys the the last video. Okay. So now I will explain old versus old versus new architecture which I'm going to build up. Okay, architecture which I'm going to build up. Okay. So first what I need to do is first it was goal, right? So goal I was tweaking and I was uh you know I was calling the uh okay lm will think that is there uh llm lm llm will things and local tools I was using local tools means uh so it was shell command shell command and calculator so I was using this two tools right this was this is local tools local to the machine okay and I was keeping at the end so this was my uh you know old architecture so I can just put old architecture okay this is my old architecture okay so now what it is doing is like my new architecture right so how what it is doing is new architecture yeah so now again the same thing go okay lm you know uh local plus web search right local plus web search we will do and at the end so it will give the result I mean again uh it's not it was just a result it will give so same thing here also so it's like a uh result also it will give okay so what is now happening is that so how our agent should be capable at the end of this video should be capable to do web search you know and also we can integrate that with our local tools also. So for example calculator you know uh something you will search in the web and you need to tell that okay uh you multiply by two or add by six or something like that right so that we will try to see like with the hybrid model also like how multiple agents can uh you know interact with themselves and also they'll provide the results so that also we will I will go through these things uh so that's where it's very important that you know you guys uh stay till end so that you know you guys will get the uh means you guys will get the information knowledge how agents are interacting okay so what I will do so this one you guys know uh last video only I have built all these things which is agent py lm py you know tools py uh you know schema py all I have built and I have built the architecture also okay so now what I will do is in requirement txt we have uh three you know uh installations right so three installed grog p identic and uh python okay so that is installed so fourth is the tool which is called as duct go search duct go search is uh you know uh is a python pip package so which will actually enable our the search web search Okay. So this is doug dug go search. So which is short form dbds we return. So this dependency we need to add here. Okay. So straight away what I will do I will just come to the terminal now. Okay. And I will just select command prompt here. So as you see my uh VNV is already activated. So what I will do? I will just do install same minus r requirements. txt. So I'll just enter this command. Okay. So I think all the packages got installed now. DDGS is also got installed. Everything got installed. So what I will do now is that I will straight away go to the tool section. Okay. So here if you see I have two tools. One is calculator. Let me close this. Okay. One is calculator and another is what? Another is runshell. So we have two tools. So next tool which is web search right. So what I will do I will define define you know define def web search. Okay. So web search query will be in string format. Yeah. So query will be in the string format. Okay. So now what I will do is let me remove this. Okay. So I will store this results in a empty array. Okay. So now with with DDGS as DDGS you know for loop we will add for R in DDGS sorry DDGS.ext text. Okay, this is the uh command where you know query result max equal to five and results dot append or what body. Okay, so this one is done and lastly what I need to do I need to return dot results. Okay. So this is one tool right I have built now. So what we have done guys we have done duck dug go search and you know doug dug go search is a the dependency and which is short form of gdgs. Okay afterwards you come here and you you know you create another tool which is web search uh you know web web search. I just created this name so that you guys will understand this. So afterwards we will add this tool in the this one. So afterwards what I will do I will create comma see I have created two tools right calculator and shell. Now I'll add another one called web search search. So this will be also under my tool list. So my tool will be capable enough to know that web search is also there. So this is one of the update what I need to do guys. Okay understood right. So this is this is very important thing what you need to make sure that you need to uh you know get those things right. Okay. So till here everybody understood I think right. So basically what I have done I have installed my package which is uh DDGS in the requirement.xt. Okay. So basically what I am making is my agentic AI powerful right because of uh because I am adding the web search also. Web search also. Okay. So till here I think everybody has understood. Okay. Now as you see my prompt right my prompt. So my prompt I need to update right. For example what are all my available tools? Earlier it was uh you know earlier only it was shell and uh calculator. Okay. So what I will do? I will just go to my llm. I already have the prompt here. So what I will do I will just copy paste that prompt here. Okay. So the prompt whatever I have I will explain that prompt also what it's what it is doing. Okay. So I have just copy pasted that prompt here. So what in prompt I have given guys is that available tools what I have one is web search which is searching the internet input is the search query what I need to give calculator used to evaluate the math expressions and execute the shell commands this is the shell command which we need to give okay so action must be one of this and never combines never return the multiple tools always return the valid JSON so this is how uh you know we have given the prompt here so please make sure that when you're giving prompt you giving the rules also otherwise it will straight away give some wrong output for you guys. Okay. So please make sure that when you are using anything uh you know you are straight away using uh you know rules also after the each and every commands are given. So basically what my agent has is that I have three available tools. One is web search another is calculator and another is run shell. So in the tools or py also I have three tools. One is calculator, one is run shell you know and another is web search guys. So hope you guys are understanding. I'm making it really really easy for you guys so that you guys can understand in tools. py we are listing all the tools. Okay. And let me explain llm. py what we are giving guys we we are importing the gra API key and afterwards we are giving the system property. Okay. And afterwards we are calling the LLM. Okay. So this prompt will directly feed into the LLM. Hope you guys are understanding this. Okay. So now schema schema is I mean uh schema will be always this is also this I not changed uh for anything. So let it be like that. And uh let me go to agent.py. Agent P.Y. Also guys it's same. I'm not changing anything in agent. py also only I'm changing tools by adding one tool that is web search okay and for that particular dependency I have added in the requirements txt okay and uh llm py I have changed the prompt okay and that's it that's it I mean only limited changes are there okay in main py okay so I have another tool right now another tool I have so what I will do I will just see whether my uh whatever I have done the changes right whether it's working or not. So what I will do I will keep one run agent another run agent you know which will search the latest you know search the internet with latest AI news. Okay let us see whether this will give answer or not. Okay, hope you guys are understanding this because only thing what I was was doing earlier with you guys. I have running the agent using this goal using this goal and the third goal is this. So let us see whether this will work or not. Okay. So what I will do I'll just go back to my terminal. Okay. Uh so already my terminal is already there. I'll just do cls. Okay. And what I will do guys is that I have now three run agents which is uh one is calculation calculate the things that is a goal for the calculator tool and list all the files in the run directory and search the internet for the latest. So, so let us see what will happen now in the this one python main.py PY I give okay so I am executing this five times so allow multiple two steps I have given so what I'll remove this I max steps is fine so let me see what kind of answers it will give so you can make it like two or three also that's fine but uh just make sure okay let us make it as three let me see how it works or five let me give as five no problem it's not a problem at Okay, let us do one thing. Let us start with python.py. Okay, so first thing, oh, it started to give something. Okay, let me check. Okay, I think it started giving guys started giving the answer. Uh, so yeah guys, so if you guys see my terminal right, it has it has given some of the validations which is proper. Okay. So, first thing, okay, let me do one thing here. You may uh appearance. Let me zoom in a little for you guys so that you guys will get the answer properly. Okay. So, first thing is that guys, let me scroll up here in the terminal. So here also let me drag like this so that you guys will get the proper things in a proper time. Okay. So if you guys see this right. So first what it has done guys. So first it has calculated the 45 * 2. So it has given it has actually told that this multiplication option I should use calculator tool. Okay. And the tool result is 540 and tool chosen is calculator. Okay. So this is this is these are the two outputs which we got for the calculator input. Okay. So that is there. So next next what it is doing is now coming to this diir command run shell right. So I should use the diir in the windows right. So once it is started using but I mean that's fine only thing is diir it is giving the proper output for us. um runshell and tool chosen is runshell. Okay. So uh as of now di is the main source and it is giving the answer for us. So like this it is giving the answer for us. It is giving the uh updated folder for us. So basically what I'm doing I'm just listing the directories inside my current folder in the run shell command. Okay. So hope you guys are understanding this thing. So one thing is that run shell ch uh see here you guys need to understand the tool chosen part also llm is very a very uh you know brainy enough to to think that okay I need to call this tool. So now first time for the multiplication what it done guys it has calculated for the calculator to okay so now what it is doing it is it is going for the run shell command. Now the important thing which we have implemented now which is goal for the search in search for the internet for the latest news. So see here guys to search the internet I should use web search tool which is really good. So the result is giving properly guys. Uh so again I have given five steps. So I should subscribe to the newsletter get the latest news you know join super newsletter. Now I'm getting lot of information here. I should search the internet you know. Uh so basically I'm getting lot of information here in the web search tool. So basically what it is doing guys it is going to this web search you know web search and it is giving the answer and also tool chosen is web search understood. So this this this is how you can add one agent for the existing agents. You can add a new agent you know using this framework. So you can add any number of agents now right. So because now as of now I have three agents. So you can just uh you know go to whatever agent you want. You can just go to requirement.txt just download that dependency you know go to llm. py you know update your existing system prompt you know add the tool add the tool like uh you know you create a function for the tool and what you want necessarily you do there and in tool section in tool section you create that function and add that as part of that's it guys that's it very simple you don't make this complicated at all you just think about these things as a beginner Later lot of enhanced frameworks will come. I will teach everything for you guys. But if you guys are not understanding this, please try to understand this because this is a very important thing. This is the foundation for everything what I'm going to teach at the later point of time. Okay. So hope you guys are understanding this. Okay. So now it's very important part that I am going to tell which is multiple agents call. So in one goal you will call multiple agents. How to do that? Let us see that. Okay. So now what I will do is guys I will go to my main. py again. Oh, let me clear this. Uh, hope you guys got this content right. So, it is calling three tools also. Okay, so now what I will do now very important thing what I'm going to teach now. Okay. So now what I will do is I will start running the agent. Okay, if you guys see my screen, sorry. If you guys see my screen, okay, search the internet for the population of Japan and multiply it by two. It means that it will search the internet population of Japan using which tool? Web search tool. Yeah. And it will start multiplying by two by calculator tool. See this is how it gets crazy guys. This is how agentic AI agents will get crazy because it is calling two tools. So basically what guys basic agent we have created. So now we are making the interaction of the agents. The one output will be the input for another agent and we are calculating the overall things. Hope you guys are understanding this. This is a very important step which is a hybrid uh agent uh you know interaction what I'm trying to do first the output will come from the AI which is allow the output will come from the web search right web search and later the output input output of that AI search sorry web search will be the input for the calculator to it will multiply by two and it will give the answer. So let us see. Okay. Uh looks very interesting right? Uh for me though it feels very interest concept here. Okay. So what I will do I will just do again the same thing which is python main.p let us see I mean see there is no harming seeing anything. Uh so if anything is fing let us see. I mean that's not a problem. Uh yeah, something is missing here. I will see. That's not a problem at all. One valid response. Thought I should read worldwide. Okay, let me check that. Oh, sorry. Sorry guys. I need to first save these things, right? Uh yeah, I'll just perform the action now. Okay. So now what it is doing it is searching the this one. Okay. It is searching the news first as of now. Okay. Previous results is complete and it searched the AI news. Okay. AI news it is searching and everything it is searching now the previous search search things are done doing there. So I mean five times since I looping uh all the things will come five times here. Okay. And so guys if you see here right if you see this query what I have given search the internet for the population multiply by two the goal is to give that okay so now what it is giving the output of see it is giving properly 128.5 million 24 and in 2026 May so it is taking the value of 2026 okay let it complete this uh because it's taking long time But let is complete. Let is let this complete. Uh so it is giving the answer for the web search. So it is to taking the web search uh things and it is giving the answer. Okay. It will take some time. So again it is giving the answer. Same things 128.5 million in 2010 and 2026. How much is for 2026? Japan has 128 million. 128 million, guys. Okay. So, web search has done. Web search has done uh one second. Web search has done one second. Okay. Uh maybe I think I not added the max steps as five because of that that agent got closed. Uh let me check with you know max steps as 10. Okay. So let me check max steps. Let me check this as 10. Okay. Let us see what answer will come here. And also guys for the simply purpose right? I will just comment this uh because I don't want you know unnecessary things coming here. I mean uh this is a search what I have already done. So I will just you know do that commenting thing and let us see what kind of uh this one will come. Okay. So search the internet you know. Uh so basically it is searching the things. Let us see. Yeah it has searched. Let us see. Okay. See, because it will repeat, right? It will repeat and it will start doing some activities. Let us see whether uh this will give the answer properly for us. Okay. I just given the max steps as more. Uh still executing. I don't know why it is not calculating the calculator. Let us see. Let us see that. Maybe I think that I think in the tool section I think web search should come first I think as per the format. Okay. Okay, let me check that one second guys. The tools section we have calculator first enter and this right. Uh okay check that one second. Uh guys I I got the reason what was the problem. uh let me explain that first. So in the goal right in the agent py you know so let us add like previous test and result if the information is already found use a calculator tool instead of search okay so why I am doing this is because already the information is found right so why I need to again go there and you know stop the value so what I will do in main py I will just do max step as two here because uh I just want two results right uh as of now I will do one thing. I will start uh in my main. py I will start with max2 and also I will as of now I will um not run this kind these agents because we already ran earlier. So what I will do is I will just add you know python main.py. So if you see the things right so what it is doing is see if you see here. Okay. So it has found the 128 billion in the uh so 2026 population is uh you know 123.4 million or something it has found somewhere okay 123.4 123.4 okay so let us use calculator tool and you know it is multiplying by two okay so it is like 248 246.8 8 million and it has given the calculator also to finish. So basically what I am trying to explain you guys understood right. So we can have multiple tool agents also. For example, if it is running for one agent, the output of one agent can be the input for other agent and also the LLM is very uh you know very intelligent to choose the tools also. So basically that is how you can you know put some hybrid model or see you can use multiple uh things for these things but only thing why I am showing you guys is because how to add this kind of web search agents right how to add this kind of web search agents and you know coming to here and later my calculator how to do the answer so that is why uh I wanted to say you guys that you know uh this is not difficult ult as you see right as you see it's not difficult at all so only thing is you guys need to do practice and other things right so that is very important okay so what I will do is I will add this I will add this to bitbucket also I mean GitHub and you guys can also refer some of the uh you know some of my initial things whatever I have done and other things and if you guys have any other agents to create please let me you know uh so that we can create it uh and uh you know in we can create in this framework basic things right this is all basic things what I'm trying to explain right so what I can do is I we can create the agents in a different format and different views so that you know you guys will understand and uh you know we can work towards you know building uh any anything which is genuine right so which is good for the uh for the country or good for the industries right so just this is a beginning guys this is a beginning what I'm trying to say is very basic so I'm building a basic agents right so so I just wanted to explain for beginners so that you know uh when I explain the deep concepts uh using langraph lang chain or hugging face or some embeddings or vector db or something so uh in rack pipeline anyways I may explain that but uh how can we integrate these kind of things how can we build one echospace ecosystem uh where you know all the things will get interacted and uh you know it's combined uh and so that you can you know we can build a you know production grade level uh applications using uh HTK production grade level uh you know solutions also we'll try to build but as of now these are the basic stuffs uh so what we can create is the agents and we have done like uh you know multi- aent uh concept also and we have created the uh this one so by the end of this as I explained you guys so this is the one this is how it works right this is how it works and we have created web search to this video so next we will see like how we can how we can uh you know what do you say build other other types of agents Or you know we can see how we can you know go one mile one mile away I mean one step away uh one step up uh up the game and you know how we can improve our uh you know uh building the agents right so this is what I wanted to explain that how to search web and how can we can you know interact with multiple tools right so this is what I wanted to explain in this video uh so if you have any questions or something uh please try to uh you know uh please try to reach me or comment it out uh so that I can explain you guys. Um and uh yeah I mean uh if you have any doubts please DM me or please comment in the uh you know uh comment section and if you if you really like this video because I have put some efforts to make these videos. Uh so if you like this video, please like you know and please subscribe to the channel so that you can follow for more updates and uh so so because this will take lot of efforts uh I need to research and I need to think as a beginner. Okay, I need to get all the things ready and so that you know you guys uh I so that I can present you guys. So that is um that is where I need to do some research and um I need to go to different tools uh sections like for example duck duck go search and everything right so earlier even I was not doing this kind of things so now also I'm exploring those kind of opportunities and also uh so basically how to do web search using aentk right so this is very important tool important dependency uh dug go search or any anything right I mean Um so next we are exploring chain everything right to whatever the framework what we can create. Uh so yeah I mean this is like upgradation for me also I am also learning the things uh along with teaching. Uh but yeah it's it's good fun right? Uh so I want you guys I want uh to share knowledge also and I want you guys also uh if you have any other information please share that knowledge uh so that I can also grab those informations and um yeah I mean uh so next we can see like uh how to do uh how to build or something like uh you know MCP servers or some other things right so we'll try to see uh how we can plan and how we can know get those videos ready for you guys. uh so that you know you will get a really upgrading things from uh you know uh so you you need to go step by step right if you are in if you're claiming any stairs or something you can't go to the uh you know last stair on you can't jump to the last step so you should step by step you need to go one step two steps you need to climb up climb the stairs right one step second step third step like that so that is where I am teaching you guys the first First step last video I taugh and this is the second step right second step we have climbed up and uh hope you guys are enjoying this uh journey u of climb this climbing the stairs so that we can reach um so we can reach to the uh the floor which we desired or something right so I just wanted to give some uh random uh story right so I mean that's how it works right so basically you can't climb like uh you know 10 steps are there means you can't climb 10 steps altogether right it is like one step to one step you need to climb and you need to start learning the things uh as a beginner and guys see advanced guys like for example there they have already learned the things it will be easy for them but basically my thought process is that uh everybody should know this kind of concepts right everybody should know that okay this occurs this uh these things will be these these things are there in the market because uh in industry right I think there are there is lot of uh you know uh it's a it's a like uh you know they are getting laid off or some other things are happening in the market right in the IT market so what I want is that if you guys have this kind of information so it will be uh really easy for you guys to um you know upskill yourself and also uh so basically you will become like a top 1% or top 2% of the employees top 10% of the employees out of top 100%. Right? So that is where you guys want to go in the stages because uh as of now uh so people are like uh people uh knows very basic things uh so they are getting laid off and you know there is enough chances that they will not get any jobs if they're not getting upsk like that I'm just telling you guys be ahead in the race ahead in the market uh so that you know you guys will have ample time or ample uh building the tools uh you will have ample uh you know projects you'll get ample sections right so or you can only build and you can only you know create your own company but again that's a too much risk you you need to take care about every sector right so I mean that is also there that is also a very good thought but what I think is like uh so you should be in the top 10% or top 20% of the employees is in your office right so that's how you will improve that's how you will you know get the attention from the leadership or managers or some other things right so that's how you will create your own reputation so that's why I wanted you guys to reach there uh so I wish I wish that to happen for all my I mean viewers and you know u I mean outside of my viewers also if somebody has doing some good things. Uh so again for them also I wish them that all the best for everybody. Um so hope you guys will acquire the knowledge on a daily basis and you know uh so that you guys will get the uh so basically yesterday's one and today if you compare so at least some of the information or some of the knowledge you should gain. uh so it's not like a overall uh journey like okay you will dump your brain with uh multiple things in one day no it can't happen like that right so basically you need to upskill day by day uh that's what I believe the process is should be very clear that you should upskill day by day so that at least at the end of the day at least you will reach to some level so if you're not upskilling and if if just you if you are in your personal life routine you know or some other things then it's very difficult for you guys sadly. Okay. Uh yeah I mean that's all from my side guys and uh if anything is there please uh please reach out to me and uh please like the video for more reaches more reach and you know please subscribe the channel for more updates uh so that lot of updates are lined up. So we will you know meet you in the next video. Uh hope everybody have a have a good day and u yeah that's all from my side guys. Uh see you in the next video. Yeah bye.

Original Description

In this video, we build an AI Agent from scratch using Python. GitHub Code: https://github.com/chethannj/MultiAgent.git Instead of just calling an LLM, we create an agent that can reason about a goal, choose tools, and execute actions automatically. Our AI agent supports multi-tool calling, allowing it to use tools like: • 🌐 Web Search • 🧮 Calculator • 💻 Shell Commands The agent can search the internet for information and then use the calculator to perform calculations, demonstrating how modern agentic AI systems orchestrate multiple tools. You'll also learn: • Agent reasoning loop • Tool orchestration • Memory for previous steps • Structured JSON outputs By the end, you'll understand the architecture behind modern AI agents used in autonomous systems. #AIagents #AgenticAI #PythonAI #LLM #AIengineering #python #orchestration
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Related Reads

📰
Building a Telegram AI Agent for Personal Use
Build a personal Telegram AI agent with conversation memory and security features using Bun, Telegraf, SQLite, and Composio
Dev.to · Shubham
📰
Terence Tao Is Vibe Coding Now — A Fields Medalist Ports His 1999 Applets With AI Agents
Learn how Terence Tao, a Fields Medalist, uses AI agents to port his 1999 applets, and discover the potential of vibe coding in mathematics
Dev.to · TerminalBlog
📰
🚀 Calling all DevOps, SRE, and Platform Engineers! Let’s build the future of AI for DevOps together.
Learn how AI agents can revolutionize DevOps and how you can contribute to building the future of AI for DevOps
Dev.to · Prashant Lakhera
📰
Calling all DevOps, SRE, and Platform Engineers!
Learn how to build AI for DevOps and improve production infrastructure with specialized AI agents
Medium · LLM
Up next
Building the future of agentic infrastructure
Claude
Watch →