open AI agents SDK a powerful agents framework released by open AI it is restricted to use only open AI models but we have a good news now we are able to create AI agents 100% local private using open AI agents SDK 100% free using oama and I'm going to teach you how you can create a single agent create a custom tool create multiple agents and create a user interface first we'll be creating a research or internet search agent capable of searching the internet and we are going to provide a custom tool that is the internet search tool then that data is passed to the editor agent and finally we'll get the output this is a basic example so that you can get started I will put all the code and commands in the description below so you can just get started straight away at the end I will create a user interface like this and I'll teach you how you can create the same user interface it's a news assistant I can ask for latest a news and at the backend it's searching the internet paing that to the editor agent and will give us an output as you can see here now let's get started first step make sure you go to ama. com and download olama next we are going to use llama 3. 2 model so we going to download llama 3.
2 first open your terminal in your computer next o llama pull llama 3. 2 and then click enter this will download the latest llama 3. 2 model next pip install open AI agent and chain lit open AA agents is the main AA agents package and chain lit is for creating user interface so after typing like this click enter now installation is completed next let's create a file called app.
py so this is a terminal command instead you can right click create new file app. py first we'll be focusing on creating a single agent inside the file from Agents import agent Runner open AI completions model and asnc open aai then we are going to initialize this open a chat completion model function with the model llama 3. 2 then we are defining so this is the key line which integrates this with o llama so this is the base URL to integrate this o Lama so after this first creating the agent agent equals agent name then instructions then model then final result Runner run sync create a meal plan for a week after that printing the result that's it only this bit of code and the key Chang is here where we set the model name long 3.
2 and the base URL now I'm going to run this code in your terminal Python app. py and then click enter and here is the output meal plan for a week because that's what we asked here meal plan for a week and the answer is here the Monday Tuesday Wednesday Thursday Friday Saturday Sunday meal plan that is really nice so that's the basic example next creating a custom tool and multiple agents together let's do that and in this example first we are going to do the research or the internet search agent with the customer some internet search tool that is dougd go search then the output from that research is passed to the editor Regent and we'll get the output so in your terminal I'm also going to install another package called dougd go search that's for using internet search and now it's installed inside the file from Duck du go search import ddgs and same like before importing agents date time for giving the time to get the latest news then getting the current dates now we are defining the completion model with llama 3. 2 and the base URL same as before now step number one is to create internet search tool so here we going to define a function called function tool there we are creating a function called get news article so this is like a decorator so this we have imported that here at the top so this get news article will use the dugdug go search search the internet based on the provided topic and the current date so that the results are latest then returning the results a simple function just to search the internet so whatever topic you provide it will return the relevant latest news article step number two is to create AI agents first is the news agent to fetch news so we are providing name instruction you provide the latest news articles and the tools is get news articles so that is the function name I'm just defining directly here and the model equals model same as before next agent number two that is the editor agent with instruction rewrite and give me a news article ready for publishing and then defining the model name now we are going to create the workflow for that I'm going to create a function called run news workflow so here the first step is to fetch news article using the first agent so I'm just running the first agent news agent and that agent is going to fetch the news article when I provide the topic then we get the data from the first agent and passing it to the next agent so raw news is posed to the next editor agent and we are running the editor agent like this that is the step two in the workflow then the output from the editor agent is returned or printed that's it so literally the workflow is to first run the news agent then pass the data to the editor agent and give the final answer so that's what we see here first the news agent and then the editor agent and we'll get out and I'm going to run this function by just providing a topic for it to search so the topic is AI That's it as a quick overview first we created the internet search tool that is just a function using dugdug go search next we created two agents news agent and editor agent third step we made those agent to run using run sync function running the first agent and running the second agent and finally returning the output and here we are providing the topic that is AI this AI will be passed to this run news workflow function so AI will be passed here that AI will be replaced here and we'll get the news about about AI on the current date that is today so that's a quick overview now I'm going to run this code in your terminal Python newsp and then click enter now running the news agent workflow using duck du go search it's searching the internet getting the relevant information now we got the news articles and it's clearly formatted and we got the each individual news as well so that is really nice so now we have created multi- agents and a custom tool to make it work you can even change the Custom Tool to any tool to integrate any of your application even your own custom application even you could make this call any API now the final step is to create the user interface so I slightly modify the code I'm just importing the news agent which we created that is the news workflow and whenever we type a message in the chatbot that is a topic the topic will be paused to the Run news workflow so that's what we created before run news workflow and whatever we type in the chat box will go as the topic and it will search for the results and return the results after passing that to two agents so the whole on message function is to run the workflow with the topic and return the results that's it so next we have another decorator that is on chat start so as soon as the UI opens you will get this message welcome to the news assistant that's it only this bit of code and we we have created a user interface now I'm going to run this in your terminal chain lit run ui.