in this video we will create a custom tool that makes use of an external node package you will learn a few important core skills for building flowwise tools first we will set our flywise for development you will then learn how to install external node dependencies and lastly you will learn how to create a custom tool that will make use of these external dependencies in order to keep this video light and fun we will create a custom tool that will make use of the Pokemon note package for fetching information about Pokemon in our chat window we
will ask the chatbot to either fetch a random Pokemon or get the name of a Pokemon based on its ID the agent will then determine the correct tool to use and return the result in order to follow along you will need the following you will need the latest LTS version of node installed you also need to install git for your operating system and you will need a code editor like vs code and some experience with node and JavaScript will be beneficial let's get started first we need to set up flywise for development by downloading the
flowwise repo go over to this flowwise repo page then click on code then copy this URL next create a new folder for where the flowwise file should be downloaded then open up the terminal or command prompt in Windows we could do that by going to the address bar and then typing CMD and in order to download this repo enter get clone and then paste in that URL and press enter and this will download flowwise to your operating system next we can CD into this downloaded folder and let's open this folder in a code Editor to
open this folder with vs code we can simply type code and period and that folder will be opened up in vs code alternatively you could just open up vs code click on file open folder and then select the flowwise folder now we need to install the flowwise dependencies we can do that by opening up the integrated terminal and then in the terminal simply type yarn install this will take a minute to complete but this will install the project dependencies for flowwise after the installation is complete we need to build this project we can do that
by running yarn bold and pressing enter once bold is complete we now have a development version of flowwise and since we now have access to all the source code of flywise we can modify it to our hearts contain we can test that flowwise is working by running yarn start and if we go to localhost 3000 we can see flowwise running successfully the first thing I'm going to do is to go over to credentials and add my openai API Key by clicking on ADD credential I'll select open AI API I'll just give it a name like
open AI API key and I'll paste in my API key if you are unfamiliar with using flow wise then I highly recommend checking out the first few videos in this series next let's go and create our chat flow so I'll go to chat flows add new I'll give it a name like Pokemon chat flow then because we'll be using tools or go to agents or then grab the openai function agent and add that to the canvas then let's add our chat model so under nodes I'll go to chat models and I'll add the chat open
AI node and let's connect this llm to the agent also let's select its credentials so under connect credentials I'll select openai API key let's also add memory so under nodes go to memory and let's add the buffer memory node to the canvas I'll just zoom out for a second and then let's go ahead and connect this memory node to the agent let's add our Custom Tool so I'll just move this out a bit then under nodes let's go to tools and then under Tools let's grab the Custom Tool node and add that to the canvas
right let's go ahead and create our Custom Tool first I'll save this chat flow then under select tools let's click on create new in this video we'll create two tools we'll create a tool to fetch a random Pokemon name and the second tool that will get the ID for a specific Pokemon let's first create the random tool just give the tool a name like get random Pokemon and please take note that we need to use a specific naming convention for these if you are new to creating tools then please have a look at a video
where I show the basics of creating tools for flow wise in the tool description I'll say use this tool when asked to retrieve a random Pokemon this is important for the agent to determine when to use this tool since this tool does not like any input we will simply leave the output schema empty we will add a property for the tool where we get the ID of a Pokemon for the this tool will leave this blank then for the JavaScript code I'll simply return a string value of EV we will change this code after we've
installed the Pokemon Library let's save this tool let's also go ahead and save this chat flow in the chat let's do the following first let's see if the bot is working by typing hello and we do get a response back let's now say give me a random Pokemon name and to get a response saying sure the random Pokemon name is Evie now let's cover it and install this Pokemon package in our project in order to install external node libraries we need to do the following I'm going to stop the flowwise project and clear the terminal
just to keep things clean first I need to explain that external libraries need to be added to the components folder in the flowwise project so first we need to navigate to the packages folder and and then we need to navigate to the components folder now we can add any external node library that we want we can do that by typing yarn add and in our example the package is called Pokemon after adding the package we now need to install and rebuild the flowwise project to do that is go back to the root directory by typing
CD period period then again CD period period and now we are back in the root directory we can now run yarn install and then we need to rebuild flow wise by running yarn bold now there's only one small step left we need to add the external node packages to the environment variables so let's close the components folder and then open up the server folder then find the file called Dot env.example and then create a copy of that file in the same folder then go ahead and rename name this file to dot EnV we can now
use this environment variable file to do a couple of very cool things the first is we can set debug to on by uncommenting this line then in order to include our node dependency we need to uncomment this line the one that says tool function external dependency and then add our dependency to this list I'm actually going to remove these two examples and replace that with Pokemon and let's go ahead and save this file and that is it our flowwise tools will now have access to these node libraries let's go ahead and start flowwise by running
yarn start then in flow wise let's go back to the dashboard then let's go back to the tools and let's click on get random Pokemon and let's go ahead and add our logic we can have a look at how this package works by going to npmjs.com and if we scroll down we can see see some example code here so in order to include this package in our guide we need to require this package then we have access to the following functions we can return an array of all Pokemon by calling the dot all method or
we can get a random Pokemon by calling the random method we can get the ID of a specific Pokemon by calling the get ID method it is the random method and the get ID method that we'll be using so let's start by including the Pokemon package so back in flow wise at the top of this code let's include the Pokemon package then let's call the random method like so and let's assign this value to a variable called random Pokemon and then let's return this variable instead of this hard-coded string value like so now let's save
this tool let's go back to our chat flow and let's test this out in the chat window I'm just going to clear this chat history so in the chat that window let's ask please give me a random Pokemon name and we do get a response back from the chatbot if we go back to our code editor I'm just going to expand this terminal a bit and what we want to ensure is that the value was indeed fetched from the tool and not from the data that the model was trained on so scrolling up we can
see this line here for the agent action and the tool that was used was the get random Pokemon tool so this confirms that our tool was used to get a random Pokemon name so let's go ahead and create that second tool let's go to tools then click on create let's give it a name like get Pokemon ID by name in the description use this tool when also get an ID of a Pokemon in the output schema We'll add a new property and we'll call it Pokemon name for the type we'll select string in the description
we'll enter something like name of Pokemon and post set required to true in the JavaScript code we'll copy this include again and this time we'll copy this get ID function and let's assign this to a variable as well by entering const Pokemon ID equals Pokemon dot get ID and then we'll return Pokemon ID obviously we don't want to hard code this value but we want to use the value that was passed in from the properties to do that we'll copy the property value then let's replace this string value like so and in order to tell
flow wise that this is a reference to the property value we can simply add a dollar sign at the start of this value that should be it let's go ahead and add this tool then let's go back to the chat flow and let's add another Custom Tool to this canvas let's go to nodes then tools and let's grab the Custom Tool node let's select the tool that we just created and let's is connect this node to our agent and let's save this in the chat I'm just going to clear the chat history so first let's
ask the following what is the ID of Pokemon Eevee and we get a response saying it's one three three if we look at the terminal we can scroll up we can see that the agent did select the correct tool and the Pokemon name property was populated with EV let's try asking for a random Pokemon Again by asking please return a random Pokemon name and let's have a look at our console if I scroll up we can see that the agent did indeed select the correct tool if you need assistance with automating business processes using tools
like flowwise then please get in touch with my AI automation agency called cognitive if you like this video please consider subscribing to my channel and I'll see you in the next one bye bye