Build Multi-Agent AI Teams with RAG & Custom Tools! (No-Code) | FlowiseAI β
Flowise AI (2024) TutorialAgingπ
2024-06-24
Build Process β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BUILD CHATBOT WORKFLOW β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β PLANNING β
β ββββββββ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Define βββββΊβ Choose βββββΊβ Setup β β
β β Scope β β Stack β β Project β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β β
β βΌ β
β DEVELOPMENT β
β βββββββββββ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Build βββββΊβ Add AI βββββΊβ Test & β β
β β Features β β Logic β β Debug β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β β
β βΌ β
β DEPLOYMENT β
β ββββββββββ β
β βββββββββββββββ βββββββββββββββ β
β β Deploy βββββΊβ Chatbot β βββ LIVE! β
β β to Cloud β β Running β β
β βββββββββββββββ βββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββKey Components β
- Project architecture
- Core features implementation
- Best practices
Transcript β
[00:00] In this video, I will show you how to add custom tools and vector stores to your multi-agent teams in Flowise. If you're new to Agent Flows, it allows you to create AI teams with the different agents in the team, while work together to achieve a goal. It's similar to frameworks like Crew AI and Autogen, but without the need to write any code. Let's have a look at what we'll be building in this video. Here, we have a research team that will do the following. The supervisor now will simply orchestrate
[00:31] the work between these different workers. Then, we have a research specialist that will take the question from the user and then use a retriever tool to perform some research on a PDF file. The results from the research specialist will then be sent to an email drafting worker, which will then draft an email, and an email draft will then be passed over to an email sender agent, which will then use a custom tool, which we will create in this video,
[01:01] which will allow the agent to actually send an email. Let's go ahead and test this by opening the chat. Let's expand this, and let's ask something like, "What was Tesla's revenue in 2023 and how does it compare to the year before that?" Let's send this. Now, let's have a look at what happened. First, the supervisor sent this message to the research specialist, and we can see that the research specialist did indeed use our vector store to fetch some information, and it then produced this report. The research results were then sent to the
[01:32] email drafter, who wrote all of this HTML code, and the HTML is simply for styling the email. And lastly, the email draft was sent to the email sender, and the email sender used this send email custom tool to send the actual email. And if I go to this email address, we do see that email in our inbox, and this now contains all of the research results with the correct styling. So I do think that by the end of this video, you will agree that adding a vector store and custom tools
[02:04] to your multi-agent flows can definitely take your flows to the next level. And as an added bonus, I'm going to show you one of the easiest ways to create these worker prompts. So let's get started. Let's create a new agent flow by navigating to the agent flows menu, and then let's click on add new. Let's click on save to give our team a name, and let's call it my research team, and let's save this. So in order to create a multi-agent flow, we need to add a supervisor
[02:34] and workers to the canvas. So under add nodes, go to the multi-agent section, and add a supervisor node to the canvas. And it's also add our workers. So let's add one of these worker nodes. And I actually prefer to put these worker nodes underneath the supervisor node, as that hierarchy just seems to make sense to me. We can then simply copy the worker node by hovering over the node and clicking on duplicate. Let's do that three times. Then let's attach the supervisor node to
[03:05] each of these workers by grabbing the output of the supervisor node and attaching it to the supervisor input node on each of these workers, like so. Next, let's give a name to each of our workers. My first worker needs to be the research specialist, so I'll simply call mine research specialist. It's also clear this worker prompt. We will get back to this in a second. Let's also give a name to the second worker, and let's call this email drafter. It's also clear its prompt,
[03:35] and it's also give a name to the final worker, which will be our email sender, or PA, or secret theory, or whatever you'd like to call it. It's also clear its prompt as well. Now before we get to these prompts, let's also assign an AI model to the supervisor node. So let's click on add nodes, let's go to chat models, and this is really up to you. But for simplicity's sake, I'll simply go with the chat open AI model, and let's attach it to our supervisor node. Then let's change a few
[04:07] things in this chat open AI node. First, let's select our credentials, and if you do not yet have credentials, simply click on create new. Give your credentials a name, like my open AI key. Then to get an API key, go to this website URL, so platform.openai.com slash API dash keys, and create a new account, and afterwards click on create new secret key. Give it a name, like YouTube tutorial as an example, and then
[04:40] click on create secret key. Then copy this key, paste it into flow wise, and click on add. For the model name, I'm going to change this to the newer GPT40 model, and it set the temperature to something like 0.4. Now that we have our theme structure in place, we do have to define the roles and responsibilities for each of these workers. We can enter a prompt in this box, like so, or we can also expand this input by clicking on this button, and here we can define the role
[05:11] of this worker. For example, we could say you are a research agent that is responsible for something, and here we could continue to define the role and behavior of this worker, but I do want to show you a useful little tip for automatically generating these worker prompts, and we can actually do that by using a prompt engineering theme offered by flow wise. To access that, let's go back to the dashboard, and let's click on marketplaces. Within marketplace, search
[05:42] for prompt engineering theme, then click on this prompt engineering theme, then click on use template, and then click on save to give your prompt engineering theme a name. Let's call this prompt engineering theme. Let's save this, and all we have to do here is select our flow wise credentials, and then save this flow again. Now don't worry too much about what's going on here, but something that you can pay attention to is this message in this little note, and
[06:12] this simply says that all you have to do is describe the app which you would like to create. So let's do this. Let's click on chat. I'm going to expand this, and let's describe the app that we would like to create. First, it's a good idea to specify the amount of agents that you need in your team. Then describe the role and responsibilities for each of your agents. For instance, the first agent is responsible for performing research on a knowledge base based on the user's
[06:43] request. Then we can also specify any tools which this agent will have access to, and we will give this research agent access to a tool called read docs. It is this read docs tool, which will be responsible for fetching the data from the vector store. You can call this whatever you want. Then the second agent will take the results from the research agent and then write an email draft containing both the user's initial question and the results from the research agent. It's also refined this
[07:13] by saying ensure that the email contains any HTML elements for styling the email. And lastly, the third agent is responsible for sending the email using a tool called send email. Again, you can call this whatever you want, but just make a note of the name of the tool. The email should always be sent to whichever email address. Now let's go ahead and send this, and this prompt engineering team will go back and forth to generate the system prompts for each of your workers. So let's have a
[07:45] look at the results. This gives us the name and the system prompt for each of our workers. So we've got our research specialist, our email content creator, and our email sender. I'm actually going to copy this text and simply store it in a notepad. Now let's go back to our agent flow and it's simply copied those values over. So for the research agent, I'll simply copy and paste that text. Let's do the same for the email drafter. And in fact, I actually like the name that they came up with of email
[08:15] content creator. And it's also copied across the system prompt for our email sender. Great. Now our team needs access to these tools. And for this, we need two tools. So you might recall that the research specialist needs access to a tool called read docs. We will use this tool to fetch information from our custom knowledge base. And the second tool will be a custom tool, which the email sender will use to send our emails. So let's start by adding our
[08:46] vector store for the research specialist. For this demo, I will be using the Steslaw financial statement, but you can use anything that you want. The point is we are going to upsell data into a vector store and then give our research specialist access to that data. Let's start by adding a new tool to the canvas and more specifically the retriever tool, which will allow our agents to fetch information from a vector store. Let's call this retriever tool read docs. Then let's
[09:16] also add a short description, like use this tool for fetching documents related to Tesla. Let's now attach this tool to our research specialist. Great. Now let's add our vector store by scrolling all the way down. It's going to vector stores and it's simply add this in memory vector store. But of course, you could also use chroma, pinecone or whatever you want. Now let's connect our vector store to the retriever tool. And let's also add a few more things to the vector store itself. First, we
[09:46] need to add this embeddings function. So let's go to add notes again, embeddings, and let's add the open AI embeddings node. And let's connect our embeddings node to the embeddings input on the vector store node. Then on the embeddings node, it's simply select our open AI credentials. We can leave the model name on this default value. Now for the document loader, we want to upload PDF documents. So let's go to document loaders and let's add PDF file
[10:17] loader. And let's attach this file loader to the document input on the vector store. On the file loader, we can also select the PDF document. And for the usage, let's say one document per page. This is also really up to you. If you want, you could select one document per file and then add a text splitter to chunk the data. But I'm simply going to leave this on one document per page. Our research specialist agent will now be able to fetch this information from the vector store. But of course, it's very important
[10:48] to first populate the vector store with this data. So let's click on Absurd Vector Database, then let's click on Absurd. And this will now grab the data from the PDF document and upload those documents into the vector store. Great. Now next, we need to create a custom tool, which will allow our email sender to actually send the email. But let's actually go ahead and test this tool to see if the research specialist is able to fetch information from the vector database. Let's click on chat. And let's ask what was Tesla's revenue in 2023. And
[11:21] we can see that the research specialist is now running. And very important is we can also see that the read docs tool was indeed used. And we can also see the content that was returned from the vector database. Great. And just another pro tip when working with these flows. You might notice that sometimes the conversation will end early. So we can see that the research specialist was indeed called, but the supervisor then decided to terminate this flow. So it never actually called the email content creator or the email
[11:53] sender, which is not correct. There are a few ways to improve this behavior. And I will show you a few tips. First, you can change the individual worker prompts by ensuring that it has some sort of instruction to pass information onto the next worker. If that doesn't work, you can take things up one level by changing the system prompt on the supervisor itself, where you can instruct it to pass information between the different nodes. For instance, start with a researcher agent, then pass the results
[12:24] to the email content creator, and then finally pass the email draft to the email sender. You can take this way further still by asking the supervisor to pass the messages back and forth until some sort of threshold or condition is met. It's simply saved as prompt. Let's try again. So let's clear the chat and let's run this again. So the research specialist is running. We can now see that the email content creator is indeed being called. And finally, the email sender is being called as well. But this note won't
[12:56] really do much as we haven't assigned a custom tool yet. Now let's create a custom tool, which will allow our agent to send emails. But first, if you are enjoying this video, then please hit the like button and subscribe to my channel for more content on agent flows and flow wise. Now let's have a look at how we can create this custom tool for sending emails. First, let's start by adding a custom tool to our canvas. Let's click on add nodes, then let's open up tools and let's add the custom tool node to
[13:27] the canvas. These custom tool nodes can be extremely powerful as it allows you to write JavaScript code, which can perform pretty much any logic that you want, like the ability to send emails. This can be a little bit technical if you are not a developer, but we will try to make this as simple as possible by using a platform called make.com. Before we go to make, let's first grab our custom tool and let's attach it to our email sender node. Great. Now to create a
[13:57] new tool, click on this drop down and click on create new. Give your tool a name like send underscore email. This name needs to be lowercase and you should use an underscore instead of any spaces. Then for the tool description, enter something like use this tool for sending emails. Then for the input schema, click on add item and let's give this property a name like message. Let's change the type to string and let's enter a description
[14:27] like the email body. Let's also check the required field. Of course, you could add the email address or the subject line to this as well, but for this demo, let's simply keep this simple. But don't worry if you're not familiar with writing JavaScript, as it's not necessary for this video. You can simply copy the code snippet from the description of this video and replace one or two variables. So after pasting in the code snippet from the description, you should see something like this. At the moment, the URL is simply an empty string and we will
[14:58] replace it with a make.com URL in a second. But all this code is doing is it is taking our email message and passing it to some API endpoint. Now let's move on to creating our email sending logic in make.com. In the description of the video, you will find this affiliate link to make.com. I'm not sponsored by them, but by using that link, you will be supporting my channel, which will be greatly appreciated. From this link, create your account and it is free to use. After signing into make, click on
[15:30] create a new scenario. If you're not familiar with make.com, it's a fantastic tool for creating powerful processes without having to write any code. Let's start by giving our scenario a different name. I'll call mine email sender tool. Let's start by adding a new app and in the search, enter webhooks and within webhooks add the custom webhook. What this webhook note will do is generate a URL endpoint, which we can call from Flow-wise. Let's add a new
[16:01] hook. Let's call it something like Flow-wise email sender and let's click on save. This will now give you this URL endpoint, which you can copy or you can simply click on copy address to clipboard and do not close this pop-up, but instead go back to Flow-wise and paste in that URL in between these single quotes. We are now done with this tool, so let's click on add and ensure that send email is selected. Let's save our flow and
[16:31] let's open the chat. I'm actually going to expand this. Let's also go ahead and clear the chat and let's ask that same question again. Now while this is running, do ensure that mac.com is still listening for that call and this time we can see that the email sender agent used our send email tool for sending the email and if we go back to mac.com, we can see that the structure was successfully determined. Great, let's click on okay and let's explain what just
[17:02] happened. So effectively, we are now able to call this endpoint and pass along the email draft. Now this hasn't sent the email yet. What we can do now is add another node to this and in the search, let's search for Gmail and let's click on send an email. Now we do need to set up our connection to Gmail which can be a little bit tricky, but I will walk you through this or if you simply wanted to skip this step, you could simply remove the Gmail node and simply attach a webhook response node
[17:35] like this and in the body, we can pass these curly braces followed by a response message called message and in here, we can say something like email sent successfully. So this will simply stop this call which means that Flow-wise will be able to call the same point and instantly receive a message back saying that the email was sent successfully. But of course, we actually want to send a real email. So in between these nodes, I'm going to add a module and specifically a Gmail module
[18:08] and within Gmail, let's click on send an email. Great. So what I would like to do is create a new connection to Gmail. So let's click on add, let's give this connection a name like Flow-wise email, then let's click on show advanced settings and here we need to enter a client ID and a client secret. This might be the only part that could be a little bit tricky, but it's honestly not that bad. To start off with, go to the Google Cloud Platform and specifically log into
[18:40] the console. From here, you need to select a project or create a new one by clicking on this drop down and then select one of your existing projects or create a new project. I'll actually call this Flow-wise agents demo and let's click on create. Then from the drop down, I'll actually wait until this project is created and I'll then select that project. Now from the menu, let's go to APIs and services, then let's go to the library and let's search for Gmail API. Let's click on
[19:13] Gmail API and let's enable it. Then let's go to credentials and let's click on create credentials, then OAuth client, then let's configure the consent screen. Let's change this to external and let's click on create. Let's give our app a name like Flow-wise research team. Let's select our support email, then let's scroll all the way down to add domain and here enter make.com and
[19:44] integromat.com. Then let's also enter this email address and let's click on save and continue. Then under scopes, we can simply scroll down and click on save and continue. For the test users, let's also just save and continue and lastly, let's click on go to dashboard. From here, I'm actually going to publish this app and from this pop-up, let's click on confirm and now let's go back to credentials again. Again, let's click on create credentials. OAuth client ID. Let's
[20:16] select the application type as web application. We can give it a name. I'll just leave it like this and then let's click on create. Now we finally have access to the client ID and the client secret. Let's copy the client ID and back in make, let's paste in the client ID and let's also copy the secret like so. Now let's click on sign in with Google and you will receive this error message which is completely fine as we still need to set up the redirect URL.
[20:47] So you can see the details for that URL by clicking on error details and here let's simply copy this redirect URI. So it's all the way to this restricted word. Let's go back to our Google Cloud platform. I'm actually going to close this pop-up then next to web client. Let's click on edit then look for this section called authorized redirect URIs. Then click on add URI and simply paste in the link that you just copied and save this. Now back in make we should be able to try
[21:18] this again. We can actually just cancel out of this then let's open Gmail again. Let's add that connection. I'll just give it a name again like Flowize email. So let's enter our client ID and secret again and if you've lost them like I did simply go back to the Google Cloud platform, click on edit next to the web client and copy the client ID like so and let's also grab our client secret like so. Let's try to sign in again and this time let's select our email account.
[21:49] Let's click on advanced. Let's click on go to integromat.com. Let's click on continue. Let's enable this checkbox. Continue and done. And now that we finally have the connection to Gmail set up we can make some more changes to this node like let's add a recipient and for the recipient I simply want all my emails to go to leonfansaldev at gmail.com. Then let's enter a subject like research results and for the email body
[22:19] we'll simply grab the message from the webbook and add it to the content of our email. That is all we have to do. Let's click on OK. Let's save this and let's click on run once. Mac is now listening for a call from Flow wise. So let's go back to Flow wise. Let's then clear this chat and let's give this a spin. So let me ask the same question again but this time I'm expecting to receive an email in my Gmail account. So the email sender is busy running and the email sender
[22:51] called our send email tool. So I can already see that I've received a new email in my Gmail account and this contains our research results. And if we go back to make we can see that each of these nodes were successfully executed. Now all we have to do is enable this make flow to listen all the time and now each and every time we run our agent flow we will receive emails to our inbox. I hope you found this video useful. If you would like to watch more content on agent flows then check out
[23:21] this other video where we cover the basics and two different scenarios for using agent flows. I'll see you in the next one. Bye bye.