"Wait..this AI Agent does research for you 24hrs without hallucination?!" - Here is how

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today I want to talk about a real AI research agent if you remember in one of my previous videos I talk about this AI use case where Michael mentioned what if I can ask chat GPT to write a Twitter stress every other day about how a famous people get rich and automatically publish it and you can get 100K followers in just one year and this was a prime use case for gbt and in the first version I used a land chain to create a linear AI workflow where I will give a topic and it will go search online get a list of URLs then it will try to pick up URL might contain most relevant information for this topic scripting the website and then create a Twitter thread out of it the problem is in real research it is never a linear process when we do a research online normally we will open some URLs scripting information then we realize there's new topics to research further so it is a much more iterative process instead of linear flow and this is where Agents come in as it has ability to plan execute and reprioritize its tasks to achieve certain goals and is really just three components it used large language model as deletion engine and then it restore all the contacts in the memory so it can maintain a task list and know what was previous context and then we'll give it a list of tools to execute the tasks they are person on Twitter created much more detailed charts about how this could work in my experience 80 or even 90 of Agents often didn't deliver good results because it has two button next one is the quality of task execution how well it is actually to complete the certain tasks and the second is the reprioritization how well it is to make a judgment call that I already have enough information to finish this task or should I continue going that's why I think there are huge opportunities in terms of building agents that is specialized in certain tasks because unlike General agents Auto GPT or bbhi if you're building agents for specific use case then you can ensure the tools that will be used for those specific tasks is executed very well and also you can provide very good system prompt to help agents make right decisions here and research is such a fundamental use case that is not just used for create Twitter stress based its building blocks in many different business workflow for example we can actually trigger the whole workflow from someone receive an email use large energy model to extract all the information now feeds into a research agent to understand how big this company is How likely they are going to purchase this product and then putting all those information into Google Sheets or ad table as a prioritized list and when you expand the definition of research more than just Google search but about other systems like CRM Erp customer ticketing system then this research agent can really stitching together the information from different systems and enhance the deletion for human so today I'm going to show you a step-by-step process of how to build a research agent and embed in your real business workflow our platform like make.com and if you're not familiar with what make Docker is it is basically integration platform that allowed us to connect to thousands of different business apps like email Google Sheets MailChimp Facebook ads and a lot more it's kind of like the zapier alternative but much much more flexible and also provide a freemium version and we're going to set up something like this where it can trigger some requests to our research agent when I receive an email and send the prioritized leads list to air table so let's get started we'll firstly set up a research agent by launching in Visual Studio code and then we will deploy as a research agent as a web service while platform like render.com and in the end we were stitching together everything in make.com to trigger the research agent from different systems we use let's open Visual Studio code and as always as create a portrait folder called AI research agent create a python file called app.py and then let's read down this research agent into components so firstly we will create a tool for the agent to go on internet and search for useful links about the topic and then we will create another tool for scripting the website content and in the end we'll connect these two tools to a launching agent and give a system prompt as a researcher before we start firstly let's create a EMV file this is where we will import all the API Keys you're going to use for open Ai and other service and there will be free API key you will need one is open AI API key we will also use serper which is service that we're going to use to search on internet and then browser less which is another service we're going to use to script in one if you don't know what they are those are the URL that you should go and sign up this is for serper.f and browserless.io once you did that just come back and replace the API key here and then let's come back to app.py the first thing we're going to do is import a list of libraries that we're going to use there are quite a few I will explain one by one what and then we'll do load.env which will load the API key from the eme file and then we'll grab the API key for browser last and server next we'll create a Search tool for agent to go on internet grab useful links and I mentioned before we're going to use serper as a service to get results from Google and this function is pretty simple we basically just create an API call to the server API so we will create this function called search with query as a input we have the URL and then payload is a query uh we will put the header pointing to the API key that you have put in v file and then we will try to do the request.request so request is a python Library they're going to use to send the API request and we pass on the URL headers and payload that we defined above and this should return list of search results from Google on the other hand launching actually provide default Google Search tool you can use as well so you actually don't have to build your own custom tool if you do decide to use their Custom Tool making sure you're using this Google server API instead of the server API here because this server API didn't actually return the link and now let's try this our do search what is Mana thread product and we will click on this button on top right corner and let's try to run this by calling python app.py okay so you can see it actually returns a list of search results here based on the query I put in next is we will create a custom tool for scripting the website data and we will use browser less as a service to do the website scripting and the person is very similar we will pass on two inputs which is objective of the research and then the URL of the link that we're gonna script I will explain a little bit why do I need to pass on this objective input later but firstly that's using the scripting service from browsers we will Define the header and then you will pass on URL of the website that we're gonna script and making sure you convert that data into a Json format so that browser less can actually take this and once we did that the next thing is we will create this if condition so if response.status code equal to 200 which means it successfully extract the content from the website and then we're going to use a python Library called Beautiful soup to extract the text from the HTML and that's because at default browser last will return the whole HTML file like this which include a lot of information like tags and scripts that we don't really need by using this beautiful circular extract only the text and content so let's try the script website function that we just created so it says a scripting website and then it Returns the whole content so this is working but if you use this right away as a scraping tool one problem you face with very quickly is the token limit so every large language model including qpd4 or GP 3.5 all have token limits so GPD 3.5 can only take 4 000 tokens at one time even for the latest version that they released a couple weeks ago it can only take up to 16 000 token and to handle the token limit of large large model they are mainly in two ways one is called mapreduce which is basically summarize the content it will break down a 40 page content into small paragraph and then it will run a large language model called every single paragraph to summarize it and in the end we will merge summary of every single paragraph into one summary so this is one way to summarize a very large piece of content and the second method is called Vector search and this is basically creating a vector embedding of a large piece of content then we do a vector search to find the most relevant content for certain topics and these two methods have its Point cons but as a rule of some I would say if you are dealing with a huge amount of data you definitely have to use Vector search because that's the most cost effective one but for a smaller one let's say you are dealing with a couple pages of content then summary and or mapreduce it's also a decent way to contain the full content and for this demo I'm going to use a summary which should map reduce masses so to do that I will remove this and create a summary function and in the summary function I will pass in two inputs one is objective of the research and the other is content that we extract from browser-less and this is why we initially were passing on an objective input for the scripting tool because I want this summary function to actually summarize content with this objective of research in mind so we'll firstly create a large language model with GPD 3.5 turbo 16k version and then we will use text splitter this will break down a 40 page content into small chunks and each chunk is 10 000 token and then we'll create an array of all those chunks then we will create one prompt called map prompt and this is basically the problem it will use when it try to summarize the content write a summary of the following text for This research objective and this attacks and this summary we will will create a prompt template from this and in the end we will use land change load summarize chain and this basic package two steps one is it will do its summarization of every single chunks that we split and in the end it will merge them together so we'll pass on the large language model the chain type will be mapreduce which is this summary message we're going to use and then we'll pass on two prompts one is map prompt which is prompt that you were used to Summarize each chunk of text and then the combine prompt which is the one you will use when you try to combine the summary from each paragraph into one paragraph and just for this purpose I'm going to use the same prompt for both map and combining and in the end we're going to run the summary chain on documents and give the output and once we did that we will move back to the scripting website function and replace this return text to A if condition that if the length of the text is really big more than 10 000 then we will use this summary function but if the content is not that big then we'll just return the full content so this two function together is how you can script in the website and feed the content to agent no matter how big tax is and the last thing is for scripting website tool we're actually going to do something special and the reason is for search 2 is very simple it only have one input that the agent need to pass on before scraping I actually wanted to pass down two input objective URL and when there are multiple inputs we will need to Define it in advance so agent can have consistent performance to pass on both inputs and to do that we will create two cards one is called Script website input class this basically defines a list of inputs that agents should pass on and we will use the base model and in here we'll Define the two input we are going to use objective and URL and for each one we're going to give a description of what it is so the agent know what kind of information I need to pass on to this function and then once we create this input based model we will create another class called Script website tool this is basically Define this function name is scripts website the function will be useful when you need to get data from the website URL passing both URL and objective to the function and then we'll find argument schema to the script website input that we defined above here then you will Define what will happen when this tool is called so it will record this script website function and you also need to Define what happens if there's arrows so this is pretty much it for the script website tool just quick recap you will Define the script or FSI function and do a summarize function that will be called if the content is too big and in the end we will create custom tool from this function it could so now we can start stitching things together and create this agent firstly we'll create a tool list that can be passed on to agents and one is gonna use search which will Define the name of the function and this is function will be called when it will be run it will give description useful when you need to answer questions about current events data and you should ask Target questions which kind of force it to generate a good query for Google and then second is we will pass on this script website tool that we just defined here and you will notice that format here is a little bit different and that's because the search for is pretty simple and straightforward we just have one input but the other one since it is more common complicated has two inputs we are passing on this quick website tool and then next is I would Define a system message that I will pass on to the agent so I will give it a row that your world-class researcher who do detailed research on any topic and produce fact-based results and you do not make things up you will try as hard as possible to gather facts and data to backup research then I will give it a list of rules to follow so you should do enough research together as much information as possible about the objective if there is a URL of relevant links and articles you are scripted to gather more information and after scripting and research you should ask yourself is there any new things I should be searching and scraping based on the data I just collected to increase the research quality and if the answer is yes then it continue but don't do this process for more than three iterations because it will be very slow and cost more money and then you should not make things up you should only write facts and data that you gather and in the end I add two rules which is exactly the same in the final output you should include all the reference data and links to back up your research and the reason I repeated multiple times is I found this Behavior often is not followed so I just repeat it multiple times making sure it actually follow and then I will create this agent arguments where we will pass on the system prompt to the agent and now create a large language model using GPD 3.5 turbo 16k as a base model for the agent and now create a memory variable so the agent can remember the context of previous steps conversation summary buffer memory basically means the agent will remember word by word data of recent chat history the older memory it will do a summary that's why here I will Define the one thousand token so it will remember exactly what happened for the past one selling token but for the older one it will do a summary and in the end we're gonna initialize the agent by giving it two lists that we have passed on the large language model agent type I'm going to use the open AI function calling agent so it has better performance in terms of extracting information and pass on the inputs for the functions and variables equal to true 2 means we can see exactly what agents is thinking at every single step and we will pass on the arguments that were created here and pass on the memory okay great now we have our agent ready the last thing is we just quickly create a web app using streamlit so that we can see the results better if you don't know what a stream layout is it's basically a way to quickly create a web app from your python code so if you don't have account making sure you sign up and then do pip install streamlit so I will create this main function and then at bottom you will Define if name equal to main you record this main function so this basically means that this function will be called when the app is running and we will do streamlit dot set page config page title so this will Define the name of your website and then streamlit the header AI research agent and query equal to streamlit.txt input so this will create a text input from your web app with title research goal and if query exists which means user actually put content and text into this input then we will show a message says doing research for the this topic and we record this agent and in the end once it's finished we'll do streamlit.info to show the results alright let's save this and we are ready to go let's run stream lit wrong app.py all right so we have this AI research agent a problem let's try this for example I want to research about why did meta's new product stress go so fast how will this impact Twitter I click enter and you can see it starts searching for relevant information and return list of links and then it starts scripting website for Relevant articles alright so within 30 seconds you search across website and give me these results the Met has new product stress grow very fast because of instant credibility and integration with Instagram solving the co-star problem and a few others so this is pretty decent results and actually including a list of reference links about where did he get his information from so you can imagine you can use this information easily feed another large language model to write a Twitter stress from this but on the other side This research agent can also be awesome for lead score boring and background research for salespeople for example I can give you a research code that I receive an email from Jason Joe at prestif who is him and what does his company do so you can imagine we can ask gbt to extract information from the email and then trigger This research all right let's return the results that Jason Joe is a head of product design of questive they basically grab all the information available across multiple different links found linked into my own personal portfolio site already this can be a research agent for multiple different use case but what's much more interesting is actually not using this research agent as a standalone web app but use it as a web service that can be embedded in your actual business workflow and it's actually pretty straightforward to do because there are platforms that we can leverage like make a.com they already provide thousands of different Integrations with those servers and to do that we're gonna deploy This research agent to the cloud as a web service so that it can be called as API in platform like make.com we will use a framework called Fast API which allow us to turn this python app into an API endpoint very easily so go back to our ad.py and then at top you will insert fast API python library and then we will move down we'll command out the streamlined part because we are not going to use it as a web app and then we will add this part which will create a variable called app equal to fast API and then we will create a new class called query use base model and it has one attribute query which is string and then we will create this app.host and this is basically a way to define what will be triggered when someone creates a host request it will Define this function research agent and then you will pass on this query into the agent then you will return the content and that's pretty much it we can try to run this API endpoint locally to test it out to run it you will do this UV corn app the first part app is basically the name of your python file so if your python file is different you will rename this to be something else and we will Define the port and endpoint and click enter okay so now you can see the API endpoint has been running and this is a URL what I will do is create another file called test server.python to test this out so inside our import requests and then I will do a post request to our local API endpoint pass on this Json formats hurray what's meta's new product stress so I will create a new terminal by clicking this plus button and inside our ROM python test server.py all right great you can see it Returns the results but looks like there are a lot more stuff than we need because it includes the inputs memory a bunch of other stuff and what do we actually need is the output so I will go back and change the API endpoint here so we will return let's say actual content all right let's save this go back here around this again all right great so you can see now it Returns the actual results that we want and let's create a requirements.txt file and list out all the necessary libraries the cloud platform needs to install and once you do that making sure you commit to GitHub and then we will use render which is a platform that allow us to host all those web servers and after you create account you can click on this new button and click on web service and in here you will search and find the repo for your research agent and click on that given name and we just need to paste the same thing that we did locally UV corn app app Post 0.0.0 Port 10 000 and then we'll choose free before you move on also click on this Advanced button and add a few environment variables we will need to Define python version 3.11.2 which is the latest one and then you will also add the API key that we defined in the dot EMV file into here and once you did that you can scroll down and click create web service button it will take a while to deploy but once it is done you should see a message here your service is live okay and let's test it out we can copy this link here and move back to the test server.py and replace the URL to be this hosted web service and we can try to run this and as you're running it you should be able to see some message on the log as well so you can see on in the log it Returns the message properly and we also get the response in our test server.py file so now we have this AI research agent live and can be called directly through API endpoint we can start embedding it in real business workflow with different systems we are using with platform like make.com so I will create account on make.com in one use case I want to take you through is once you receive an inquiry email it can automatically extract core information about company and people and then feed those information into a research agent for background research then we can export all those information into Google sheet or air table and to do that let's firstly go to make.com can create account if you don't have make.com account yet you can click on the link I post in the description below which will give you one month's Pro Plan for free for 10 000 workflow operations and once you create account you can log in and you will see a page like this we will click on this create new scenario and scenario here basically means workflow from here we'll click on this plus button and we will type in Gmail but you can also use Outlook as well if you want and there is one trigger called watch emails which means this workflow will be triggered when a new email received and I will click on this add button to sign in with Google if you are using business account you are just signing their initial work file however if you're using personal Gmail account the process will be a bit more complicated as Google adds some extra security practice and I'm going to show you how as well but if you don't need this feel free to skip ahead so if you are using personal account you will click on this add button click on sign Google and sign with your personal account here and click allow then you'll probably say a warning message like this and you will need to click on this guide link to get more information but basically what you will need to do is go to the Google Cloud account sign in with the same Google account and then you will click on this button on the top left corner click on this create a new project button and in here we can give a name called make integration and then click create and once you did that and switch to the project that you you just create it and go to enable API and service Tab and then click on this enable button search for Gmail and click on this Gmail API and then enable it and once you did that you will click on this all consent screen choose external and click create then you will give app a name and let's say called make and you will choose the email that you want to support in the authorized domains you will add two domains here one is integromate.com which is older version of make.com and then you are putting make.com and for the developer content information you will just type in your own email address here and click on Save and continue then you will move to Next Step Scopes so you will click on this add or remove Scopes button and search for Gmail and you can select everything about gmails here and then you will click on update button here and we'll click on save it and continue button internal test user you can just add the email address that you want to connect Gmail to and click add once you did everything you can review it and click on back to dashboard then we will go to credentials Tab and click on create credentials choose all client ID and choose web applications given name like make and authorized redirect URI with this one and I post a link in the description below so you can follow and then we'll click create once it succeeds you should see a option here in the credentials for us 2.0 client ID you can click on that and things on the right for client ID and client secret is the ones that you need so we will go back to mac.com and then click on this show around settings button paste in your client ID and client secret from the Google Cloud platform and then click on sign in with Google again and you will see a page like this then you click on this Advanced Tab and click on this link at the bottom and then choose this checkbox move down and click continue and that's it you can see the Google account has been set up properly and then the next step is use open AI as the way to extract the name and Company info from this email so I will add this step with open AI I will use a chat completion methods and use the GPD 3.5 turbo June 13 model and I will add a few messages first I will give a system prompt you will help me extract information from email about send an email and their company and format it in certain way person name at the company name like bubble Wong at both concept and then I will add this user message I just received email from the sender and this is the email address this is the body of the email and I will just click on those item on the left side to insert the information from previous step and please help me extract who sent the email and their company and I'll click save and just for test purpose I just sent an email with this content and let's run this okay so once it's finished you should have a little bubble here you can click on that and see the output Choice the first one inside there will be message and it successfully extract the content surely from questive so this is information that we need to feed the research agent the next step is we will feed those information to the research agent API endpoint that we just created so I will click next step and search for HTTP and select make a request this is basically a way to send API requests and then map the information we received from previous steps into the columns in the air table and click save all right so now we get everything running all we need to do just turn on the scheduling and default every 15 minutes you will check all the email received and then trigger this workflow for every single email and as you can see in my air table it's already start generating a few different records like this one I sent from my own email address it is able to do the research about who this person is which company it is as well as a list of reference links so I can easily know who this person is How likely he's going to be a good potential clients this is just one example workflow you can trigger for This research agent you can click on the templates page on make.com and there are wide range of different systems and workflow you can build from your telegram bot Google form click funnel Facebook leads ad or even Shopify and as I mentioned before if you haven't created make.com account yet you can click on the link in the description below which will give you one month's Pro account for free and you can trigger workflow 10 000 times I'm super Keen to see what kind of use case you guys are creating and please comment below about the sound innovative ideas you are experimenting thank you and I see you next time
Info
Channel: AI Jason
Views: 163,825
Rating: undefined out of 5
Keywords: gpt, autogpt, chatgpt, ai, babyagi, babyagi ui, use babyagi, babyagi langchain, langchain, gpt 4, agent gpt, agent gpt tutorial, how to use agent gpt, ai agents, autonomous ai agents, best ai agent, what is ai agent, python conversational agent research toolkit, conversational agent research toolkit python, auto gpt install, how to use auto gpt, auto gpt tutorial, auto gpt 4, how to install auto gpt, what is auto gpt
Id: ogQUlS7CkYA
Channel Id: undefined
Length: 25min 58sec (1558 seconds)
Published: Wed Jul 19 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.