Free YouTube Transcribe

Video transcript

n8n AI Agent Tutorial | Building Multi Agent Workflows

Leon van Zyl · 11,047 words · 51 min read

Want to search this transcript, jump the video from any line, or download it as TXT, SRT, or VTT?

Open in the transcript tool

Full transcript

Intro

0:00<b>Welcome to this beginner course on</b>

0:02<b>building AI agents with</b>

0:03<b>N8N. In this tutorial, I will</b>

0:06<b>assume that you're new to N8N or perhaps</b>

0:08<b>this is your very first AI</b>

0:10<b>agent. So we will go through</b>

0:11<b>the entire process step by step. From</b>

0:14<b>setting up N8N to building</b>

0:16<b>our very first workflow and</b>

0:18<b>building a supervisor agent that has</b>

0:21<b>access to tools like web</b>

0:23<b>search and it will also be able</b>

0:25<b>to delegate tasks between different</b>

0:27<b>worker agents as well. And our agent will</b>

0:30<b>also have access to a</b>

0:31<b>custom knowledge base which we can</b>

0:34<b>maintain. And each of these worker agents</b>

0:36<b>will be able to execute</b>

0:38<b>multiple actions. Like the email agent</b>

0:40<b>will be able to send emails,</b>

0:42<b>read emails and even reply to</b>

0:45<b>emails. The calendar agent will be able</b>

0:47<b>to create new calendar events and</b>

0:49<b>retrieve our current</b>

0:50<b>calendar entries. Our contact agent will</b>

0:53<b>retrieve contact details like email</b>

0:56<b>addresses from Google</b>

0:58<b>contacts. It will also be able to create</b>

1:00<b>new contacts and update</b>

1:02<b>existing contacts. Then a</b>

1:04<b>content creator agent will be responsible</b>

1:06<b>for writing things like</b>

1:08<b>research papers, blog posts,</b>

1:11<b>social media posts, etc. If you are</b>

1:13<b>familiar with using N8N and building AI</b>

1:16<b>agents, you will still</b>

1:18<b>find value in this video as well as we</b>

1:20<b>will look at best practices for</b>

1:22<b>implementing these agents.</b>

1:24<b>For this tutorial, I do recommend</b>

1:26<b>following along in your own N8N instance.</b>

1:29<b>You will also find time</b>

1:30<b>codes to the different sections in the</b>

1:33<b>description of this video. And in the</b>

1:35<b>description, you will</b>

1:36<b>also find a link where you can download</b>

1:38<b>all of these workflows</b>

1:39<b>absolutely free. So what exactly</b>

1:42<b>is N8N? Well simply put, it's a workflow</b>

1:45<b>automation tool. It's</b>

1:47<b>similar to platforms like</b>

1:48<b>Make and Zapier, but with more often</b>

1:51<b>emphasis on developers. Now</b>

1:53<b>if you're not a developer,</b>

1:54<b>this is still the perfect tool for you.</b>

1:56<b>It simply means that it is very simple</b>

1:59<b>for developers to add</b>

2:00<b>custom functionality to these workflows.</b>

2:03<b>But if you're a</b>

2:04<b>non-developer, this is a super simple</b>

2:06<b>tool to use. N8N is also open source,</b>

2:10<b>which means you can download and sell</b>

2:12<b>photos to platform if</b>

2:13<b>you want. Or if you don't want to deal</b>

2:15<b>with the infrastructure</b>

2:16<b>yourself, you can definitely sign</b>

2:18<b>up for the paid service as well. And in</b>

2:20<b>this video, we will have a</b>

2:21<b>look at running it locally</b>

2:22<b>on our own machines. And I'll also show</b>

2:25<b>you how to sign up for the cloud service.</b>

2:27<b>Let's also briefly discuss workflows and</b>

2:29<b>the different notes you</b>

2:30<b>will see throughout this</b>

2:32<b>video. Workflows like this might seem</b>

2:34<b>overwhelming, but it all breaks down to</b>

2:36<b>three different types of</b>

2:38<b>nodes. These include trigger nodes,</b>

2:41<b>processing nodes, and finally action</b>

2:44<b>nodes. Now let's have</b>

2:45<b>a look at these nodes in a bit more</b>

2:47<b>detail. Triggers are, well, anything that</b>

2:50<b>triggers the workflow.</b>

2:52<b>These could be things like forms, file</b>

2:55<b>system changes. For</b>

2:56<b>example, a file might be created</b>

2:58<b>on the file system, or our workflows</b>

3:00<b>could also run on a schedule. Our</b>

3:02<b>workflows could also be</b>

3:03<b>exposed as webhooks or API endpoints, or</b>

3:07<b>changes in external</b>

3:08<b>applications could trigger these</b>

3:10<b>workflows as well. As an example, a</b>

3:12<b>database change, or if we</b>

3:14<b>receive an email. In terms of</b>

3:16<b>building AI agents, our trigger could be</b>

3:19<b>a simple chat message.</b>

3:21<b>Processing nodes can be used to work</b>

3:23<b>with the data within the workflow. These</b>

3:25<b>could include things like</b>

3:26<b>sort, filter, if then conditions,</b>

3:30<b>transforming data, enriching data, AI</b>

3:33<b>agents, summarizing text,</b>

3:36<b>transcribing audio, and much,</b>

3:38<b>much more. And finally, we have actions.</b>

3:42<b>Actions are typically things</b>

3:43<b>that have an effect on external</b>

3:45<b>systems. So actions could be something</b>

3:47<b>like sending an email, posting</b>

3:49<b>on social media, creating and</b>

3:51<b>saving files, creating tickets, making</b>

3:54<b>API calls, updating databases, retrieving</b>

3:58<b>data from calendars,</b>

4:00<b>generating AI images, voice, or video.</b>

4:03<b>Let's have a look at the super simple</b>

4:04<b>workflow example. We could</b>

4:06<b>have a trigger like when we receive an</b>

4:09<b>email, this workflow should</b>

4:10<b>be triggered. Then using the</b>

4:12<b>contents of that email, we might want to</b>

4:15<b>then process the contents</b>

4:16<b>of that email. For example,</b>

4:18<b>we could summarize the text or we could</b>

4:21<b>extract certain</b>

4:22<b>information, perhaps lead information</b>

4:24<b>from that email. We could then perform an</b>

4:26<b>action like taking that</b>

4:28<b>lead information and installing</b>

4:30<b>it in an external system, like maybe a</b>

4:33<b>CRM system or a database. And</b>

4:36<b>we could have another action</b>

4:37<b>that replies to that initial email. Let's</b>

4:40<b>have a look at another example that</b>

4:42<b>includes an AI agent.</b>

4:44<b>We could trigger the workflow when we</b>

4:45<b>receive a chat message.</b>

4:47<b>That chat message will then be</b>

4:49<b>passed to our AI agent. The agent has</b>

4:51<b>access to a few actions. It could respond</b>

4:54<b>to our chat message,</b>

4:56<b>but it could also decide to call tools.</b>

4:59<b>And each of these tools are</b>

5:00<b>actions as well. For example,</b>

5:03<b>it could send an email or it could</b>

5:05<b>perform a Google search. So</b>

5:07<b>fundamentally, this is how</b>

5:08<b>N8n works. Just keep in mind, you would</b>

5:11<b>always have triggers, you</b>

5:12<b>would then process the data</b>

5:14<b>and perform some action. Now enough about</b>

Setting up n8n

5:17<b>the theory, let's now</b>

5:18<b>jump into N8n. You can access</b>

5:21<b>N8n by clicking on the card on the screen</b>

5:23<b>right now or using the link</b>

5:25<b>in the description of this</b>

5:26<b>video. That link will tell N8n that you</b>

5:29<b>sent me and that will</b>

5:30<b>also greatly help my channel.</b>

5:32<b>As I mentioned earlier, N8n is open</b>

5:35<b>source and you can self-host it if you</b>

5:38<b>want. That means you</b>

5:39<b>can install N8n on your local machine for</b>

5:42<b>absolutely free. And that is</b>

5:44<b>what we'll use in this video.</b>

5:46<b>You could deploy it yourself to a VPN,</b>

5:48<b>which is usually a very affordable</b>

5:50<b>option. But if you don't</b>

5:52<b>want to deal with infrastructure and you</b>

5:54<b>don't want to run it</b>

5:54<b>locally, you can definitely go for</b>

5:56<b>their paid cloud service. You can see the</b>

5:58<b>pricing on their pricing</b>

6:00<b>page over a year. So if you</b>

6:01<b>simply wanted to follow along, you could</b>

6:04<b>simply click on get</b>

6:05<b>started and then sign up for this</b>

6:07<b>14-day trial period. And that will take</b>

6:09<b>you to the N8n dashboard. For everyone</b>

6:12<b>else who wants to run</b>

6:13<b>it locally for free, I'm going to show</b>

6:15<b>you that process right now. The only</b>

n8n local setup

6:17<b>prerequisite is that</b>

6:19<b>you need to have node.js installed. So go</b>

6:21<b>to node.js.org and</b>

6:23<b>download and install node.js for</b>

6:26<b>your operating system. Then open up your</b>

6:28<b>command prompt or terminal</b>

6:29<b>and enter npx n8n start. If</b>

6:34<b>it's your first time running N8n, you</b>

6:36<b>will be asked whether you want to install</b>

6:38<b>N8n. So simply press</b>

6:40<b>Y and enter. After installation</b>

6:42<b>completes, you will get this URL, which</b>

6:45<b>you can copy. And when</b>

6:46<b>you open it in the browser, you will be</b>

6:48<b>asked to create an account. And</b>

6:50<b>afterwards you will see</b>

6:52<b>this dashboard. So whether you're running</b>

6:54<b>N8n locally or in the</b>

6:56<b>cloud, you're now ready to move</b>

6:57<b>on to the next step. From the dashboard,</b>

n8n dashboard overview

7:00<b>we can view our workflows, any</b>

7:03<b>credentials that we've set</b>

7:04<b>up, as well as past executions. On the</b>

7:07<b>left, we can also access the N8n</b>

7:10<b>marketplace by clicking</b>

7:12<b>on templates. And from here, you can view</b>

7:14<b>and download thousands</b>

7:16<b>of pre-created templates</b>

7:18<b>for pretty much any use case. Scrolling</b>

7:21<b>down to the bottom, we</b>

7:22<b>can also find our settings.</b>

7:25<b>And if you're anything like me, you'd</b>

7:27<b>want to go to personal, scroll down to</b>

7:29<b>the bottom and change</b>

7:30<b>your theme to dark mode and save.</b>

7:33<b>Awesome. Now let's go back to our</b>

7:35<b>dashboard. And I'm guessing</b>

Building first AI Agent

7:37<b>you're eager to build your very first AI</b>

7:39<b>agent. So let's get into</b>

7:41<b>this. Let's click on start from</b>

7:43<b>scratch or create workflow. We can rename</b>

7:46<b>a workflow by clicking on</b>

7:47<b>the name on the top left</b>

7:49<b>corner. Let's call this my first agent.</b>

7:52<b>Looking at the canvas, we</b>

7:54<b>can zoom out and in, and we can</b>

7:56<b>also click on this button to center all</b>

7:59<b>the notes in the center of</b>

8:00<b>the screen. You can move the</b>

8:02<b>canvas around by holding space bar and</b>

8:04<b>dragging the left mouse</b>

8:06<b>button. On the trackpad, you do</b>

8:08<b>have to press down two fingers and then</b>

8:10<b>move it left or right, up</b>

8:13<b>or down. On the top menu,</b>

8:15<b>we can switch between editor and past</b>

8:18<b>executions. We haven't executed this flow</b>

8:21<b>yet, so we don't see</b>

8:22<b>any past executions yet. Let's go back to</b>

8:25<b>our editor. We can also</b>

8:26<b>change our flow from inactive</b>

8:28<b>to active, which will put it into</b>

8:30<b>production mode. More on</b>

8:32<b>that later. If you are on the</b>

8:34<b>paid plan, you can share your workflow</b>

8:36<b>with team members. We can also access</b>

8:39<b>this workflow settings</b>

8:40<b>by clicking on these three dots. And from</b>

8:42<b>here, we can duplicate</b>

8:44<b>this workflow, download it,</b>

8:46<b>or import an existing workflow. What I do</b>

8:49<b>recommend is clicking on</b>

8:50<b>settings and from here,</b>

8:52<b>set your time zone. I'll set mine to my</b>

8:55<b>local time zone in</b>

8:56<b>Johannesburg. Let's save these</b>

8:58<b>settings. And now we can add our very</b>

9:01<b>first trigger node. When</b>

9:02<b>we click on add first step,</b>

9:04<b>we can see all the different triggers</b>

9:06<b>that are available. We can</b>

9:07<b>trigger a workflow manually,</b>

9:09<b>which is ideal for testing. Or on</b>

9:11<b>AppEvent, we can see all these</b>

9:14<b>integrations with third-party</b>

9:16<b>platforms. For example, we could search</b>

9:18<b>for something like Gmail,</b>

9:20<b>and within this Gmail node,</b>

9:22<b>we have this on message received trigger.</b>

9:25<b>This means that when we receive an email,</b>

9:27<b>that will trigger this workflow. We can</b>

9:29<b>also run workflows on a</b>

9:31<b>schedule, which means we could set</b>

9:33<b>the intervals to days, minutes, hours,</b>

9:36<b>seconds, weeks, etc. So we could decide</b>

9:39<b>to run this workflow</b>

9:41<b>on a regular schedule. We can also expose</b>

9:43<b>this workflow as an API</b>

9:45<b>endpoint using the webhook</b>

9:47<b>call. We can also create a custom form</b>

9:50<b>where we can specify</b>

9:51<b>individual fields. And when a user</b>

9:53<b>submits that form, it will trigger this</b>

9:56<b>workflow as well. Workflows</b>

9:57<b>can also be triggered by other</b>

9:59<b>workflows, which we will do in this</b>

10:01<b>tutorial. And of course, we can also</b>

10:03<b>trigger our workflow when</b>

10:05<b>we receive a chat message. And since we</b>

10:07<b>are focusing on AI agents in this</b>

10:10<b>tutorial, I'll select this</b>

10:11<b>on chat message node. This node doesn't</b>

10:14<b>give us too many options. We can</b>

10:16<b>basically decide to make</b>

10:17<b>it public, which will give us this URL,</b>

10:20<b>which we can use to access</b>

10:21<b>this chat flow using a chat</b>

10:23<b>interface from outside of N8N. I'm simply</b>

10:26<b>going to disable this</b>

10:28<b>toggle for now. Let's go back to</b>

10:29<b>the canvas. And now we get this open chat</b>

10:32<b>button. After clicking this</b>

10:34<b>button, we now have this chat</b>

10:36<b>interface. They send a message like,</b>

10:38<b>"Hello." We get this pop up</b>

10:40<b>saying this workflow executed</b>

10:42<b>successfully. And we can see our chat</b>

10:44<b>message all the way on the</b>

10:45<b>right over here. But we didn't</b>

10:47<b>receive any response. That is because we</b>

10:50<b>haven't attached an AI agent</b>

10:52<b>yet. Now we can decide to add</b>

10:54<b>processing or action nodes to this</b>

10:56<b>workflow by clicking on this</b>

10:58<b>add button. Now we have a whole</b>

11:00<b>bunch of different options. Under data</b>

11:02<b>transformation, we have</b>

11:04<b>values like edit field,</b>

11:06<b>which allows us to manipulate values. We</b>

11:09<b>can filter on data. We can limit the</b>

11:12<b>amount of entries. We can</b>

11:13<b>split the entries out or aggregate</b>

11:15<b>different results, et</b>

11:17<b>cetera. Also under flow, we can do</b>

11:19<b>things like if statements, filter, merge.</b>

11:23<b>We can loop over items and</b>

11:25<b>more. What we're interested</b>

11:26<b>in is this advanced AI menu. And within</b>

11:30<b>here, we have access to all</b>

11:31<b>sorts of AI related nodes.</b>

11:34<b>Let's add the AI agent node. Whenever we</b>

11:37<b>add nodes, whether these are</b>

11:39<b>processing or action nodes,</b>

11:41<b>we can see the input from the node before</b>

11:44<b>it, as well as the</b>

11:45<b>output generated by this node</b>

11:47<b>on the right hand side. This means we can</b>

11:50<b>see the input from the chat</b>

11:52<b>interface on the left over</b>

11:54<b>here. And we can change this view from a</b>

11:56<b>schema view, a table view,</b>

11:58<b>and a JSON view. Let's go</b>

12:00<b>back to schema. We can see the chat</b>

12:02<b>window provided a session ID, which is a</b>

12:05<b>unique identifier for</b>

12:06<b>this conversation. We also have an action</b>

12:09<b>called send message, and</b>

12:10<b>of course our chat message.</b>

12:12<b>Within this agent node, we can set all</b>

12:15<b>sorts of parameters. We can</b>

12:16<b>select the type of agent from</b>

12:18<b>this dropdown, and here we have access to</b>

12:21<b>tool agents,</b>

12:22<b>conversational agents, and many others.</b>

12:25<b>For 99.9% of all use cases, the tool</b>

12:29<b>agent is sufficient. For</b>

12:31<b>the source prompt node,</b>

12:32<b>the default behavior is to try and grab</b>

12:35<b>the user's message from the</b>

12:36<b>chat trigger node. Therefore,</b>

12:38<b>we don't have to manually specify the</b>

12:41<b>prompt. Of course, if we wanted to, we</b>

12:43<b>could change this to</b>

12:44<b>define below, and now we can simply type</b>

12:47<b>a message like hello or how are you</b>

12:50<b>doing? Now, obviously,</b>

12:51<b>you don't want to hard code those values.</b>

12:53<b>We want to grab them from</b>

12:54<b>the chat window or from another</b>

12:57<b>node in the flow. So what we could do is</b>

12:59<b>grab this chat input</b>

13:01<b>property on the left and drag and</b>

13:03<b>drop it into the stix field. And now we</b>

13:06<b>are passing the value from the chat</b>

13:07<b>window in to your AI</b>

13:10<b>agent. But as you can see, the value is</b>

13:12<b>coming from JSON.chat</b>

13:14<b>input, which is identical to this</b>

13:16<b>very first option, which also looks for</b>

13:19<b>JSON.chat input. So let's leave it on</b>

13:22<b>this option for now.</b>

13:23<b>Under options, we can click on add</b>

13:25<b>option. And let's add a</b>

13:27<b>system message. It's a common</b>

13:29<b>practice with AI agents to set a system</b>

13:32<b>message. Here we can define</b>

13:34<b>the role, the rules, and any</b>

13:37<b>other information that should affect the</b>

13:39<b>agent's behavior. To make</b>

13:40<b>this window a bit larger,</b>

13:42<b>let's switch over to expression and let's</b>

13:44<b>click on this button to</b>

13:45<b>expand this view. Let's change</b>

13:48<b>this. I'm going to remove this default</b>

13:50<b>text and I'm going to add</b>

13:51<b>this hashtag, which in Markdown</b>

13:53<b>is simply a heading with the text role.</b>

13:57<b>Here we can give our agent</b>

13:58<b>the name and set its behavior.</b>

14:00<b>Let's say you are an AI agent called Max.</b>

14:04<b>We could also set</b>

14:05<b>additional stuff like additional</b>

14:08<b>information. And in here, let's add</b>

14:11<b>something like you are talking to Leon.</b>

14:13<b>This will tell our agent</b>

14:14<b>who they're talking to. What I also like</b>

14:16<b>to do is to tell our agent what the</b>

14:18<b>current date and time</b>

14:20<b>is. So if we ask you the question like</b>

14:22<b>what is the current date and time, it</b>

14:24<b>will have that answer.</b>

14:26<b>So we can simply do that by saying the</b>

14:28<b>current date and time is,</b>

14:31<b>and now we have to dynamically</b>

14:33<b>populate the date and time. So how do we</b>

14:35<b>do that? We get this little</b>

14:36<b>tip saying we can use these</b>

14:38<b>double curly braces to inject some</b>

14:40<b>JavaScript. But don't worry, we won't be</b>

14:42<b>writing any JavaScript</b>

14:43<b>during this tutorial. This is the only</b>

14:45<b>time where we will inject a dynamic</b>

14:48<b>value. So simply enter</b>

14:50<b>double curly braces, then dollar sign,</b>

14:53<b>and here we get a list of suggested</b>

14:55<b>values. Let's select</b>

14:57<b>the now value. On the right hand side, we</b>

15:00<b>see a preview of what</b>

15:01<b>that value would look like.</b>

15:03<b>And this is injecting a JavaScript object</b>

15:06<b>into this text. We can</b>

15:07<b>make this look slightly better</b>

15:09<b>by adding dot and to string. So I'll just</b>

15:13<b>select this second option.</b>

15:15<b>And now we're injecting the</b>

15:16<b>date and the time and the time zone into</b>

15:19<b>this prompt. We will come</b>

15:20<b>back to the system prompt</b>

15:21<b>a few times during this tutorial. But for</b>

15:24<b>now, this is good enough.</b>

15:25<b>Let's close this pop up.</b>

15:27<b>And let's go back to the canvas. Now our</b>

15:30<b>AI agent has this red</b>

15:31<b>outline. That is because we're</b>

15:33<b>missing certain inputs. And we can see</b>

15:35<b>this chat model is a required</b>

15:37<b>input. The chat model is the</b>

15:40<b>large language model, which is</b>

15:41<b>effectively the brain behind this agent</b>

15:43<b>is click on Add. And here</b>

15:45<b>we can see a list of all the large</b>

15:47<b>language providers offered</b>

15:48<b>by in it in now I am going to</b>

15:50<b>mention that almost all of these nodes</b>

15:53<b>are paid services. And we</b>

15:55<b>will be using open AI during the</b>

15:57<b>course of this video. And there's a very</b>

15:59<b>good reason for that. AI</b>

Important Note on LLMs for Agents

16:01<b>agents require powerful models</b>

16:04<b>in order to work effectively and trying</b>

16:06<b>to run a powerful model on</b>

16:08<b>their own machine using a</b>

16:09<b>llama is not practical. If you want a</b>

16:12<b>free service, then I do recommend using</b>

16:15<b>Grog. But this does offer</b>

16:17<b>certain shortcomings as well as the</b>

16:19<b>models offered by Grog are not as</b>

16:21<b>powerful as the models we need</b>

16:23<b>to get this agent to work effectively.</b>

16:25<b>But if you really want to</b>

16:26<b>follow along for free and with a</b>

16:29<b>caveat that you might run into</b>

16:30<b>frustrating issues with the agent is not</b>

16:33<b>doing what you're expecting</b>

16:34<b>it to do. Afterwards, we will set up open</b>

16:37<b>AI instead. So let's add</b>

Groq Setup

16:39<b>the Grog node. And now we</b>

16:41<b>need to create our credentials. So on the</b>

16:44<b>credentials, click on Create New</b>

16:46<b>Credential. And now we have</b>

16:47<b>to enter an API key, go to grok.com. And</b>

16:51<b>under developers, click on</b>

16:53<b>Free API key, then click on</b>

16:56<b>Create API key, and give it a name like</b>

17:00<b>n8n masterclass, copy</b>

17:02<b>the key and add it to n8n.</b>

17:05<b>Click on Save. And if everything was set</b>

17:07<b>up correctly, you should</b>

17:08<b>get this green message.</b>

17:10<b>It's close to pop up. And now we can</b>

17:12<b>select from the different</b>

17:13<b>models at the time of recording,</b>

17:16<b>the best open source model to use for</b>

17:18<b>agents would be llama 3.3 and the 70</b>

17:21<b>billion parameter model.</b>

17:23<b>So simply select that model, go back to</b>

17:25<b>the canvas. And now this</b>

17:26<b>error will be resolved.</b>

17:28<b>We can chat to this model by clicking on</b>

17:30<b>open chat. And let's say,</b>

17:32<b>hello. So this will run the agent.</b>

17:35<b>And afterwards, we do get our response</b>

OpenAI API Key

17:37<b>back. Now I will not be</b>

17:39<b>using Grog for this tutorial,</b>

17:41<b>as there are limitations down the line.</b>

17:43<b>So I'm going to delete this</b>

17:44<b>node, then on the chat model,</b>

17:47<b>I'm going to add open AI, then on the</b>

17:49<b>credentials, let's create a new</b>

17:51<b>credential. And now we have to</b>

17:52<b>provide an API key to get the key, go to</b>

17:56<b>platform.openai.com slash</b>

17:58<b>API keys, you will find a link</b>

18:01<b>in the description of this video to</b>

18:03<b>create a key, they go on create new</b>

18:05<b>secret key, give it a name</b>

18:07<b>like n8n masterclass. And let's create</b>

18:10<b>this key is copy the key and</b>

18:13<b>add it to n8n. We don't have</b>

18:15<b>to change any of these other fields, they</b>

18:17<b>simply save the connection was</b>

18:18<b>successful. So we can</b>

18:20<b>close this pop up. And now we can select</b>

18:22<b>our AI model. I'm going to</b>

18:24<b>select GPT 40 mini. This is</b>

18:26<b>a super affordable and intelligent model.</b>

18:30<b>I do want to remind you</b>

18:31<b>that open AI is a paid service,</b>

18:33<b>which means you do have to load some</b>

18:35<b>credit onto your account. And</b>

18:37<b>trust me, a few dollars goes a</b>

18:39<b>long way on this platform to load credit,</b>

18:42<b>click on your profile, click</b>

18:43<b>on billing, and then click on</b>

18:46<b>add to credit balance. And here you can</b>

18:48<b>add as little as $5. And</b>

18:51<b>trust me, that's going to last</b>

18:53<b>you a long time. And in my opinion, it's</b>

18:56<b>absolutely worth it. As I</b>

18:58<b>personally hate dealing with the</b>

18:59<b>frustration of working with models that</b>

19:02<b>don't do what I expect him to</b>

19:04<b>do. So back in n8n, let's go</b>

19:06<b>back to the canvas. And let's see if this</b>

19:08<b>is working. Let's open</b>

19:10<b>chat. And let's start a new</b>

19:11<b>conversation by clicking on this refresh</b>

19:13<b>button. Yeah, we'll just</b>

19:15<b>reset this conversation. And</b>

19:17<b>let's say hi there. And we get our</b>

19:19<b>response back. This chat window also</b>

19:22<b>provides other valuable</b>

19:23<b>information as well. On the right hand</b>

19:26<b>side, we can see that the</b>

19:27<b>agent that was called and within</b>

19:29<b>this agent node, the open AI chat model</b>

19:32<b>node was called. And we can see the</b>

19:34<b>response took about 900</b>

19:36<b>milliseconds, along with the date and</b>

19:38<b>time that this was run, and</b>

19:40<b>the amount of tokens that were</b>

19:42<b>used. We can also see the full input. And</b>

19:45<b>this includes our system</b>

19:46<b>message along with the human</b>

19:48<b>message that we just passed over here.</b>

19:51<b>And we also see the agent's</b>

Conversation History Memory

19:53<b>output. Our agent is working,</b>

19:55<b>but it is lacking some basic</b>

19:56<b>functionality. First, let me show you</b>

19:58<b>this silly issue. Let's say,</b>

20:01<b>my dog's name is Ruby. Our agent says,</b>

20:04<b>oh, what a lovely name. How</b>

20:05<b>old is Ruby? And what breed is</b>

20:07<b>she? But watch what happens when I ask</b>

20:09<b>it, what is my dog's name?</b>

20:12<b>And now it's saying it doesn't</b>

20:13<b>have access to that information. So our</b>

20:15<b>agent is clearly suffering</b>

20:16<b>from some kind of memory loss.</b>

20:18<b>Now, why is this? Although we can see the</b>

20:21<b>conversation history in this chat window,</b>

20:24<b>each message that we send to the agent is</b>

20:26<b>technically a separate invocation. So the</b>

20:29<b>agent has no view of the previous</b>

20:31<b>conversations. And we can see that on the</b>

20:34<b>right hand side as well,</b>

20:35<b>the input simply contains a system</b>

20:37<b>message. And then our latest</b>

20:39<b>message is got no view of the</b>

20:42<b>conversation history. So how can we add</b>

20:45<b>that history or the</b>

20:46<b>previous messages in our chat,</b>

20:48<b>we can do that by adding memory. So let's</b>

20:51<b>click on memory. And let's</b>

20:52<b>select this window buffer</b>

20:54<b>memory node. This node will be used to</b>

20:56<b>store our previous messages.</b>

20:58<b>And here we can also specify</b>

20:59<b>the amount of previous messages that</b>

21:02<b>should be stored and</b>

21:03<b>retrieved. Let's say we want to pull</b>

21:04<b>in the 20 last messages. Let's go back to</b>

21:07<b>the canvas and watch</b>

21:09<b>what happens when we chat to</b>

21:10<b>this agent. Now I'm going to reset this</b>

21:12<b>chat. And let's say my dog's name is</b>

21:15<b>Ruby. And in the chat</b>

21:17<b>window, we can already see a different</b>

21:19<b>behavior. First, our agent</b>

21:21<b>reaches out to the buffer memory</b>

21:23<b>node to retrieve our conversation</b>

21:25<b>history, it then sends our message to</b>

21:27<b>open AI. And finally,</b>

21:29<b>it stores the new messages in our memory</b>

21:32<b>database. Let's ask it now, what is my</b>

21:35<b>dog's name? And this</b>

21:36<b>time our agent did remember my dog's</b>

21:38<b>name. And on the right hand side, if we</b>

21:41<b>go to our chat model,</b>

21:42<b>we can see the system message, then we</b>

21:45<b>can see the</b>

21:46<b>conversation history. And finally,</b>

21:49<b>we can see the new message that we sent.</b>

Adding Web Search

21:52<b>Our agent is coming along</b>

21:53<b>nicely, but we can greatly</b>

21:55<b>improve it even still. AI agents have the</b>

21:58<b>capability to call</b>

21:59<b>tools. Tools allow it to</b>

22:01<b>interact with the environment around it.</b>

22:04<b>Let me show you an</b>

22:05<b>example of this. Let's ask it,</b>

22:07<b>what is the latest news on grok3? And our</b>

22:10<b>agent is telling us that</b>

22:11<b>its last update was October</b>

22:13<b>2023. So it actually doesn't know what</b>

22:16<b>grok3 is. This simply means the cutoff</b>

22:19<b>date for the training</b>

22:20<b>data of the specific model was October</b>

22:22<b>2023. So our agent doesn't</b>

22:25<b>have access to real time data.</b>

22:27<b>How can we fix that? Well, thankfully,</b>

22:29<b>that's easy. We can assign</b>

22:31<b>a tool within tools, we can</b>

22:32<b>call other workflows, we can access</b>

22:35<b>vector stores, and under other tools,</b>

22:38<b>there's plenty of different</b>

22:39<b>integrations. For example, on this</b>

22:42<b>screen, I can already see a calculator.</b>

22:45<b>And since these models</b>

22:45<b>are generally very bad at doing math,</b>

22:47<b>I'll actually add the calculator tool in</b>

22:50<b>the meantime, like so,</b>

22:51<b>right. But we also want to give our agent</b>

22:53<b>the ability to go online</b>

22:55<b>and perform a web search.</b>

22:58<b>That way it can retrieve up to date</b>

23:00<b>information. The tool that we</b>

23:02<b>can use for that is called Serp</b>

23:04<b>API, the Google search tool. So let's add</b>

23:07<b>this to the canvas. Now we</b>

23:08<b>also have to connect credentials</b>

23:10<b>to this tool. So let's select create new</b>

23:12<b>credential. And of course, we</b>

23:14<b>have to add an API key. To get</b>

23:16<b>your free API key, simply go to</b>

23:18<b>serpapi.com and register for</b>

23:21<b>an account. After signing in,</b>

23:24<b>copy your API key and add it to N8N.</b>

23:27<b>Hopefully you're starting to</b>

23:28<b>see a bit of a pattern here.</b>

23:30<b>Integrating with external systems is</b>

23:32<b>really simple. Now let's go back to the</b>

23:34<b>canvas. And let's just</b>

23:36<b>move these tools around. So this looks</b>

23:38<b>nice and neat. We now have a</b>

23:39<b>calculator tool and a Serp API</b>

23:42<b>tool. You can rename nodes by right</b>

23:45<b>clicking a node and clicking</b>

23:46<b>rename. I'll just call this</b>

23:48<b>Google search and let's click on rename.</b>

23:51<b>You can also rename a node</b>

23:53<b>by double clicking on it and</b>

23:55<b>clicking on the name over here. Right now</b>

23:57<b>let's test this out. Let's</b>

23:59<b>go to the chat window. I'm</b>

24:01<b>actually going to copy my question, start</b>

24:03<b>a new conversation and</b>

24:05<b>let's ask it what is the latest</b>

24:07<b>news on Croc 3. We can see the search</b>

24:10<b>tool was called and in the</b>

24:12<b>response we can see that Croc 3</b>

24:14<b>is available to members of X who have</b>

24:17<b>this subscription plan</b>

24:19<b>and users who subscribe</b>

24:20<b>directly to Croc's platform. So we could</b>

24:23<b>ask other questions like</b>

24:24<b>what the current weather is etc.</b>

24:27<b>And our agent will now be able to use our</b>

24:29<b>web search tool to</b>

24:30<b>retrieve up to date information.</b>

Create Supervisor and Email Agent

24:32<b>Now let's step things up by adding the</b>

24:34<b>ability for our agent to read and send</b>

24:37<b>emails. Now we could</b>

24:39<b>simply click on add tools and within</b>

24:41<b>tools we could search for Gmail and</b>

24:44<b>within the Gmail node</b>

24:45<b>we have different operations. Like we've</b>

24:48<b>got the ability to send</b>

24:49<b>emails, we could reply to emails,</b>

24:51<b>we could mark emails as read, we could</b>

24:54<b>search emails etc. So this</b>

24:57<b>means we could add one node</b>

25:00<b>for sending an email like so and then we</b>

25:04<b>could search for Gmail</b>

25:05<b>again and under operation we</b>

25:08<b>could click on get many and then add it</b>

25:11<b>to this and we could add</b>

25:12<b>additional nodes that will now</b>

25:14<b>tag emails, read specific emails etc. But</b>

25:18<b>during the course of this</b>

25:20<b>video we will also be interacting</b>

25:22<b>with calendars and fetching contact</b>

25:25<b>information. So you can imagine we will</b>

25:27<b>have quite a few tools</b>

25:29<b>that we are adding to this agent and a</b>

25:31<b>general rule of thumb is to</b>

25:33<b>keep the amount of tools to</b>

25:35<b>10 tools or less. Otherwise you'll start</b>

25:38<b>to confuse the agent. So</b>

25:40<b>a better approach is to</b>

25:41<b>create specialized worker agents that</b>

25:44<b>each have a very specific function. So</b>

25:47<b>what we'll do now is</b>

25:48<b>we will create an email agent that will</b>

25:50<b>be responsible for doing</b>

25:52<b>anything email related and</b>

25:54<b>then this agent will simply call that</b>

25:56<b>agent as a tool. So effectively this</b>

25:59<b>agent becomes a kind of</b>

26:01<b>a supervisor that will delegate tasks</b>

26:04<b>between different agent</b>

26:05<b>nodes. In fact while we're here</b>

26:07<b>let's already set that up. I'm going to</b>

26:10<b>rename this agent to</b>

26:12<b>supervisor and I'm also going to</b>

26:14<b>rename it on the top left to supervisor</b>

26:17<b>agent and I like adding</b>

26:19<b>these little emojis just to</b>

26:21<b>indicate that this workflow is an agent.</b>

26:24<b>So let's save this workflow, let's go</b>

26:26<b>back to home and let's</b>

26:28<b>create a new workflow and let's call this</b>

26:31<b>one email agent. Let's save this and</b>

26:34<b>let's add a trigger.</b>

26:36<b>Now this agent will be triggered by</b>

26:38<b>another workflow. So the</b>

26:40<b>type of trigger that we want to</b>

26:42<b>add is this when executed by another</b>

26:45<b>workflow. Under input data</b>

26:47<b>mode we can change this from</b>

26:50<b>accept all data. This simply means we</b>

26:53<b>will grab whatever data is</b>

26:54<b>being passed from our supervisor</b>

26:56<b>and work with that data. Then let's click</b>

26:59<b>on set mock data. This will</b>

27:02<b>simply allow us to manually</b>

27:04<b>specify data so that we can test this. So</b>

27:07<b>we don't have to run the supervisor</b>

27:08<b>workflow every time we</b>

27:09<b>just want to test this workflow in</b>

27:12<b>isolation. So I'll just</b>

27:13<b>actually remove line four and let's</b>

27:16<b>rename this property from name to query</b>

27:19<b>and this must be called</b>

27:21<b>query and for the value let's say</b>

27:24<b>send an email to leon.fundsale at</b>

27:27<b>gmail.com asking for a</b>

27:29<b>status update. Let's save this,</b>

27:31<b>let's go back to the canvas and let's</b>

27:33<b>click on add and let's add</b>

27:35<b>our AI agent. Let's change the</b>

27:38<b>source for the prompt to the find below</b>

27:40<b>and let's add the query</b>

27:42<b>property into the prompt. Let's go</b>

27:45<b>back to the canvas and let's add our chat</b>

27:47<b>model and of course we will</b>

27:49<b>be using open AI and we can</b>

27:51<b>leave it on gpt 4.0 mini and again I like</b>

27:54<b>to go to settings let's</b>

27:56<b>change the time zone to</b>

27:58<b>joe anisberg let's save this. For these</b>

28:01<b>worker agents we don't</b>

28:03<b>have to assign memory as these</b>

28:04<b>agents are kind of performing a once-off</b>

28:07<b>task. They don't have to remember the</b>

28:09<b>conversation history</b>

28:10<b>so they will receive an instruction from</b>

28:12<b>the supervisor execute</b>

28:14<b>on that instruction and</b>

28:15<b>provide some response. We do however want</b>

28:18<b>to assign a tool so</b>

28:20<b>under the list of tools let's</b>

28:21<b>search for gmail and here we do have to</b>

28:24<b>assign credentials. Let's</b>

28:26<b>create a new credential and</b>

28:27<b>for these google nodes we do have to</b>

28:29<b>provide the client id and a client</b>

Google Cloud OAuth Setup

28:32<b>secret. So to get the</b>

28:33<b>client secret and key go to</b>

28:35<b>cloud.google.com and click on console.</b>

28:39<b>Then let's create a new project</b>

28:41<b>by clicking on this drop down. Let's</b>

28:43<b>click on new project and</b>

28:45<b>I'm going to rename this to</b>

28:46<b>nitin masterclass and let's create this</b>

28:50<b>project. Once this is done click on</b>

28:52<b>select project or you</b>

28:53<b>could simply click on this drop down and</b>

28:55<b>select your project from</b>

28:56<b>there. Now we have to enable</b>

28:58<b>access to the gmail api so let's click on</b>

29:01<b>this navigation menu</b>

29:02<b>click on apis and services</b>

29:05<b>then click on library and search for</b>

29:08<b>gmail open up the gmail api</b>

29:11<b>and enable access to the gmail</b>

29:14<b>api. Now we have to set up our oauth</b>

29:17<b>consent screen thankfully this is</b>

29:19<b>something we only have to do</b>

29:20<b>once. Click on oauth consent screen click</b>

29:24<b>on get started. Now let's</b>

29:26<b>give our app a name. I'm</b>

29:27<b>simply going to call this nitin</b>

29:30<b>masterclass let's select a support email</b>

29:33<b>and let's click on next.</b>

29:35<b>For the audience select external click on</b>

29:38<b>next enter contact</b>

29:39<b>information so I'll enter my email</b>

29:42<b>address next under finish just click on</b>

29:44<b>agree and continue then</b>

29:46<b>create. Now click on audience and</b>

29:50<b>click on publish app and confirm then</b>

29:53<b>back in the menu let's go back</b>

29:55<b>to api and services and let's</b>

29:58<b>click on credentials. Now we can finally</b>

30:01<b>create our oauth credentials by clicking</b>

30:03<b>on create credentials</b>

30:05<b>oauth client id for the application type</b>

30:08<b>select web interface for</b>

30:10<b>the name just enter nitin</b>

30:13<b>and under authorized redirect uris click</b>

30:16<b>on add uri and back in</b>

30:18<b>nitin we can simply copy this</b>

30:20<b>oauth redirect url and paste it into this</b>

30:24<b>field and let's click on</b>

30:25<b>create. The good news is we only</b>

30:28<b>had to do this process once we will reuse</b>

30:30<b>this client id and secret</b>

30:32<b>throughout the course of</b>

30:34<b>this video so simply copy your client id</b>

30:36<b>and add it to nitin and</b>

30:38<b>let's do the same thing for the</b>

30:40<b>client secret and let's add that to nitin</b>

30:42<b>as well then click on sign</b>

30:44<b>in with google select your</b>

30:46<b>email address if you see this screen</b>

30:48<b>simply click on advanced and click on go</b>

30:51<b>to nitin masterclass</b>

30:52<b>there is a process that you can follow to</b>

30:54<b>verify these apps but for</b>

30:56<b>the tutorial's sake that's</b>

30:58<b>completely unnecessary let's click on</b>

31:00<b>continue to nitin</b>

31:01<b>masterclass let's select all of these</b>

31:03<b>permissions and continue and our</b>

31:06<b>connection was successful let's close</b>

31:08<b>this pop-up and now we can</b>

31:09<b>finally continue with this note first i'm</b>

31:12<b>going to rename this note</b>

31:13<b>to send and for the operation</b>

31:16<b>we'll select send now for the two email</b>

31:19<b>address and the subject we want our ai</b>

31:22<b>agent to intelligently</b>

31:23<b>populate these fields on our behalf for</b>

31:26<b>example the user would say</b>

31:27<b>something like send an email</b>

31:29<b>to this email address asking for an</b>

31:31<b>update but we want our agent to</b>

31:33<b>intelligently extract the</b>

31:35<b>email address and then populate it into</b>

31:38<b>the two field and generate</b>

31:40<b>a subject line and an email</b>

31:42<b>body based on this context so in order to</b>

31:45<b>tell nitin that the agent</b>

31:47<b>should populate these fields</b>

31:48<b>you can simply click on this button</b>

31:51<b>titled let the model define this</b>

31:53<b>parameter i'll do it for</b>

31:54<b>the two field for the subject field and</b>

31:57<b>for the message field we</b>

31:59<b>can also click on options and</b>

32:00<b>let's select a paint nitin attribution</b>

32:03<b>and disable this this will simply remove</b>

32:07<b>the text at the bottom</b>

32:08<b>of the email which says something like</b>

32:10<b>email sent using nitin let's go back to</b>

32:13<b>the canvas and let's</b>

32:14<b>test this out by running this workflow so</b>

32:16<b>our agent is running it's</b>

32:18<b>calling the send tool and</b>

32:19<b>looking at my email i received this email</b>

32:22<b>requesting a status update</b>

32:23<b>with this text that was generated</b>

32:25<b>by our ai agent so i'm actually going to</b>

32:28<b>reply to this email to say</b>

32:29<b>we're slightly behind schedule</b>

32:31<b>but it should be done by wednesday it's</b>

32:33<b>sent this and if i refresh</b>

32:35<b>this inbox and this is now the</b>

32:37<b>inbox that our agent is linked to we can</b>

32:40<b>see that response from the</b>

32:42<b>other leon the other email</b>

32:43<b>address so i'm not going to open this</b>

32:46<b>mail as i actually want to add the</b>

32:47<b>ability for our agent</b>

32:49<b>to read emails on our behalf so what we</b>

32:51<b>can do is click on tool let's</b>

32:53<b>go to gmail select the gmail</b>

32:55<b>tool and under operation let's select get</b>

32:59<b>many we don't want to</b>

33:00<b>return all of the emails so let's</b>

33:03<b>just say we want the last five emails and</b>

33:06<b>under filters let's select</b>

33:08<b>red status and let's select</b>

33:11<b>unread emails only i'm also going to</b>

33:13<b>rename this note to unread and let's</b>

33:17<b>rename this well let's</b>

33:18<b>go back to this trigger node and let's</b>

33:20<b>edit this value to something like what</b>

33:23<b>are my current unread</b>

33:24<b>emails let's save this let's go back to</b>

33:27<b>the canvas and let's run this</b>

33:29<b>workflow we can now see that</b>

33:30<b>the unread note was called and if we open</b>

33:33<b>up our agent node we can see</b>

33:35<b>on the right hand side that</b>

33:36<b>it says you currently have one unread</b>

33:39<b>email here are the details the</b>

33:41<b>email was sent from leon with</b>

33:43<b>the subject line of request for status</b>

33:45<b>update along with we're</b>

33:47<b>slightly behind schedule and</b>

33:49<b>we should be done by wednesday great so</b>

33:51<b>our agent is now able to retrieve our</b>

33:53<b>emails we can also get</b>

33:55<b>our agent to reply to emails and i think</b>

33:58<b>that will be the final</b>

33:59<b>function that we add to this email</b>

34:01<b>agent so again let's go to gmail let's</b>

34:04<b>add a gmail tool under</b>

34:06<b>operation let's select reply</b>

34:09<b>and for the message id we'll simply let</b>

34:11<b>the agent populate this and we'll also</b>

34:14<b>let the agent generate</b>

34:15<b>the message let's also rename this to</b>

34:19<b>reply and let's go back to</b>

34:21<b>the canvas and let's test this</b>

34:23<b>out i'm going to change this trigger node</b>

34:26<b>so for this message let's</b>

34:28<b>say reply to leon asking him to</b>

34:33<b>complete the work by tuesday like so it</b>

34:37<b>saved us let's go back to the</b>

34:38<b>canvas and it's execute this</b>

34:40<b>workflow so we can see it's searching the</b>

34:42<b>unread emails and now it's</b>

34:44<b>replying to the email and if</b>

34:46<b>i pull up my emails again we can see that</b>

34:49<b>response from my dev account</b>

34:50<b>saying thank you for the update</b>

34:52<b>but could you please complete the work by</b>

34:54<b>tuesday great we can</b>

34:56<b>actually now rename this agent to</b>

34:58<b>let's just call this email agent not that</b>

35:01<b>it matters but i like</b>

35:02<b>to keep things organized</b>

35:03<b>we can now save this and now we need to</b>

35:06<b>add this agent as a tool to our</b>

35:08<b>supervisor agent let's go</b>

35:10<b>back to the dashboard let's click on</b>

35:12<b>supervisor and on the</b>

35:14<b>supervisor let's click on add tools</b>

35:17<b>and let's select call nnn workflow tool</b>

35:20<b>let's give our tool a name</b>

35:21<b>like email agent and in the</b>

35:24<b>description we need to tell our</b>

35:26<b>supervisor agent when to use this tool so</b>

35:29<b>our description could be</b>

35:31<b>use this tool for any email related</b>

35:33<b>actions then from the list of workflows</b>

35:36<b>let's select our email</b>

35:38<b>agent and lastly i am going to rename</b>

35:41<b>this to email like so let's</b>

35:44<b>go back to the canvas let's</b>

35:46<b>put it next to the rest of these tools</b>

35:48<b>let's save this workflow and let's test</b>

35:50<b>it let's say send an</b>

35:52<b>email to my email address inviting leon</b>

35:55<b>to my birthday party next</b>

35:57<b>saturday let's send this and</b>

36:00<b>we can see our agent is running and it is</b>

36:02<b>calling our email worker</b>

36:04<b>which completed and in the chat</b>

36:06<b>response it says the invitation to your</b>

36:08<b>birthday party has been</b>

36:10<b>successfully sent to leon if you</b>

36:12<b>need anything else feel free to ask now</b>

36:14<b>there's a problem looking at</b>

36:16<b>my emails i didn't receive this</b>

36:18<b>email and this was intentional i want to</b>

36:21<b>show you how to troubleshoot</b>

36:22<b>workflows in nnn we can see</b>

36:25<b>the email node was indeed called and on</b>

36:27<b>the left hand side we can</b>

36:29<b>see the query that was passed</b>

36:30<b>into that node along with the output on</b>

36:33<b>the right hand side we can also view the</b>

36:36<b>data that was passed</b>

36:37<b>to this email workflow by going back to</b>

36:40<b>the dashboard let's click</b>

36:42<b>on email agent and let's</b>

36:44<b>click on executions here we can view all</b>

36:47<b>the past executions for this</b>

36:48<b>workflow and if we look at the</b>

36:50<b>last one we can see exactly what was</b>

36:53<b>passed into this flow we can see the</b>

36:55<b>query has this structure</b>

36:57<b>which contains the subject line along</b>

36:59<b>with the body of the email</b>

37:01<b>etc but this doesn't include</b>

37:04<b>the email address at all so it seemed</b>

37:06<b>like our supervisor</b>

37:08<b>attempted to write the email itself</b>

37:11<b>and totally forgot to include the email</b>

37:13<b>address which is not what</b>

37:14<b>we want in fact if we open up</b>

37:16<b>this send node we can see this email was</b>

37:19<b>sent to leon at example.com</b>

37:21<b>so this agent unfortunately had</b>

37:24<b>no idea what the supervisor wanted it to</b>

37:26<b>do so it just kind of made</b>

37:28<b>up its own email address now</b>

Improving Supervisor System Prompt

37:30<b>what we need to change here is the</b>

37:32<b>supervisor node should only be</b>

37:35<b>responsible for delegating</b>

37:36<b>tasks between the workers it should not</b>

37:39<b>try and write emails or</b>

37:41<b>content or anything itself its</b>

37:43<b>function is simply to orchestrate the</b>

37:45<b>tasks between the different agents so</b>

37:47<b>let's fix that ASAP let's</b>

37:49<b>go back to the supervisor let's open the</b>

37:52<b>supervisor node let's go to</b>

37:54<b>the system message and let's</b>

37:55<b>improve the system message so let's add</b>

37:58<b>your job is to orchestrate</b>

38:00<b>activities between different</b>

38:02<b>agents and then formulate a friendly</b>

38:04<b>response back to the user</b>

38:06<b>and just to really hit home</b>

38:08<b>let's also add you should never write</b>

38:10<b>emails create content</b>

38:12<b>create summaries yourself your</b>

38:14<b>job is to call agents and tools in the</b>

38:16<b>correct sequence and</b>

38:18<b>finally think carefully about the</b>

38:20<b>sequence of events some tools might</b>

38:23<b>require you to first call</b>

38:24<b>another tool in order to pass it to</b>

38:26<b>correct information now this should</b>

38:28<b>greatly improve this</b>

38:30<b>behavior let's go back to the canvas</b>

38:32<b>and let's try this again they sent</b>

38:34<b>exactly the same message so i will just</b>

38:36<b>say send an email to</b>

38:38<b>leon.fonsal at gmail.com inviting leon to</b>

38:41<b>my birthday party next</b>

38:43<b>saturday let's send this</b>

38:44<b>we can see our agent is calling the email</b>

38:47<b>worker node and finally it</b>

38:49<b>says the invitation has been</b>

38:50<b>sent and again although it said it sent</b>

38:54<b>the email i still didn't</b>

38:55<b>receive it this agent still sent</b>

38:57<b>the email to leon at test.com again this</b>

39:02<b>was intentional and i bet</b>

39:04<b>you've been experiencing</b>

39:05<b>the same issues when using the grok</b>

39:07<b>models and that is because</b>

39:09<b>these agents need a lot of</b>

39:11<b>intelligence in order to function</b>

39:13<b>correctly so for the model i'm going to</b>

39:16<b>switch it from mini to gpt4</b>

39:19<b>0 and if you do have access to 0.3 mini i</b>

39:22<b>highly recommend using that</b>

39:23<b>as well but now look at the</b>

39:25<b>difference when we save this it's going</b>

39:27<b>to open chat let's send</b>

39:29<b>that exact same message again</b>

39:31<b>like so so of course it's going to call</b>

39:33<b>the email tool but it's not</b>

39:35<b>saying it sent the invitation</b>

39:37<b>and looking at my emails i did indeed</b>

39:40<b>receive the invitation this time so</b>

39:43<b>hopefully you can see what</b>

39:44<b>a difference these more intelligent</b>

39:45<b>models can make because we</b>

39:47<b>probably could use 0 4 mini or</b>

39:50<b>maybe one of the llama 3.3 models but you</b>

39:53<b>would have to prompt the</b>

39:54<b>crap out of this thing in the</b>

39:55<b>system prompt to get a decent result but</b>

39:58<b>do take note you can still</b>

40:00<b>use a cheaper model for some</b>

40:02<b>of these specific workers this email</b>

40:05<b>agent does not require an</b>

40:07<b>advanced model and the open source</b>

40:09<b>models or something like 4.0 mini is</b>

40:12<b>perfect for this use case next we're</b>

Contacts Agent

40:14<b>going to add a contacts</b>

40:16<b>agent to this workflow because passing</b>

40:18<b>the entire email address</b>

40:19<b>into the sprint is not practical</b>

40:22<b>we basically just want to say something</b>

40:23<b>like sending email to john</b>

40:25<b>inviting him to my birthday</b>

40:27<b>party next saturday and our agent should</b>

40:29<b>somehow retrieve the email</b>

40:31<b>address that be stored against</b>

40:33<b>john from some sort of database and then</b>

40:36<b>send the email to that</b>

40:37<b>address now let's create this</b>

40:39<b>contacts agent let's go back to home</b>

40:42<b>let's create a workflow and let's rename</b>

40:45<b>this to contacts agent</b>

40:47<b>for the trigger i'm sure you've guessed</b>

40:49<b>it we will add this when executed by</b>

40:52<b>another workflow trigger</b>

40:53<b>we'll set the input data mode to accept</b>

40:56<b>all data we can pull some mock</b>

40:58<b>data in by clicking this link</b>

41:00<b>then let's delete all of this and i'll</b>

41:03<b>just add back like so let's</b>

41:06<b>rename this property to query</b>

41:08<b>and for the text let's say retrieve</b>

41:11<b>john's email address let's save this</b>

41:14<b>let's go back to canvas</b>

41:16<b>let's click on add advanced ai ai agent</b>

41:20<b>of course let's change the source to the</b>

41:22<b>find below and let's</b>

41:24<b>add the query to this text let's go back</b>

41:27<b>to the canvas let's add a</b>

41:29<b>chat model we'll go to open</b>

41:30<b>ai chat model we can use gpt for omini in</b>

41:34<b>this case as we don't</b>

41:35<b>need an intelligent model and</b>

41:36<b>now under tools let's search for google</b>

41:39<b>contacts tool here we have</b>

41:41<b>to set up credentials again</b>

41:43<b>so let's click on create new credential</b>

41:45<b>and we have to specify a</b>

41:47<b>client id and secret so all we</b>

41:50<b>have to do is go back to google cloud</b>

41:52<b>platform and copy these</b>

41:54<b>exact same values so i'll copy</b>

41:56<b>the id let's also copy the secret like so</b>

42:00<b>and of course if you</b>

42:01<b>already close this pop-up all you</b>

42:03<b>have to do is go back to credentials</b>

42:04<b>click on this oauth 2.0 client</b>

42:07<b>id and you can get your client</b>

42:09<b>id and the secret on this screen now</b>

42:11<b>before we click on this sign</b>

42:13<b>in with google button we do</b>

42:15<b>have to first allow access to this api so</b>

42:18<b>back in google cloud let's</b>

42:20<b>go to menu let's go to apis</b>

42:22<b>and services app library then let's</b>

42:25<b>search for contacts api you</b>

42:28<b>will notice though that the</b>

42:29<b>contacts api has actually been deprecated</b>

42:32<b>so instead we need to</b>

42:34<b>use this google people api</b>

42:36<b>instead let's simply enable this api then</b>

42:40<b>let's go back to n8n let's</b>

42:41<b>click on sign in with google</b>

42:43<b>let's select our email account i'll just</b>

42:46<b>simply tell this to</b>

42:47<b>continue let's click on continue</b>

42:49<b>again and that should be it let's close</b>

42:52<b>this pop-up and let's close</b>

42:54<b>this screen as well and for the</b>

42:56<b>operation let's simply select get many</b>

42:59<b>we'll simply limit this to</b>

43:01<b>i don't know five results</b>

43:03<b>for the fields let's grab the email</b>

43:06<b>addresses and the names of these contacts</b>

43:10<b>it's an able use query</b>

43:12<b>and for the query it's simply let the ai</b>

43:16<b>decide and that should be it</b>

43:17<b>let's go back to the canvas</b>

43:19<b>and one thing we didn't do was actually</b>

43:22<b>set up our google contacts</b>

43:23<b>account thankfully this is</b>

43:25<b>super easy go to contacts.google.com and</b>

43:29<b>sign into your google</b>

43:30<b>account initially we won't have any</b>

43:32<b>contacts so let's create one i'll simply</b>

43:35<b>call this person john and for</b>

43:37<b>the last time i'll just call</b>

43:39<b>him demo and let's add an email address</b>

43:41<b>i'm actually just going</b>

43:43<b>to use my personal email</b>

43:44<b>address again and let's save this right</b>

43:47<b>so now in our contacts we do</b>

43:49<b>have one contact called john</b>

43:51<b>so in our workflow if we send a message</b>

43:54<b>retrieve john's email</b>

43:56<b>address we should get an email back</b>

43:58<b>so let's run this it's searching our</b>

44:01<b>contacts and if we look at the</b>

44:02<b>output we can see that john's</b>

44:04<b>email is well my email address cool i am</b>

44:08<b>going to rename this node</b>

44:10<b>to search and let's also add</b>

44:14<b>another google contacts node so google</b>

44:17<b>contacts let's change the</b>

44:19<b>operation to create and for the</b>

44:21<b>family name let's simply let the ai</b>

44:24<b>decide the same with the</b>

44:25<b>given name then for the additional</b>

44:27<b>fields let's add emails and other emails</b>

44:31<b>let's click on add email</b>

44:33<b>and for the type we'll just</b>

44:34<b>select home and for the value of the</b>

44:36<b>email address we'll let the ai agent</b>

44:39<b>populate this field let's</b>

44:40<b>also rename this node to create let's go</b>

44:44<b>back to the canvas and</b>

44:45<b>let's change this trigger node's</b>

44:47<b>input to to create a contact so let's say</b>

44:51<b>add a new contact for mary</b>

44:55<b>lamb with the email address</b>

44:59<b>mary at test dot com let's save this go</b>

45:04<b>back to the canvas and</b>

45:05<b>let's test this workflow we can</b>

45:07<b>see the create node is executing and we</b>

45:10<b>got something back let's</b>

45:11<b>have a look at the response</b>

45:12<b>the contact for mary has been</b>

45:14<b>successfully created and</b>

45:16<b>going back to google contacts</b>

45:18<b>let's refresh this and we now have mary</b>

45:20<b>in our database with her</b>

45:22<b>email address we can also change</b>

45:24<b>contacts so again let's change our dummy</b>

45:27<b>data in the trigger node</b>

45:29<b>to update mary lamb's email</b>

45:33<b>address to mary dot lamb at test dot com</b>

45:38<b>let's save this and</b>

45:40<b>under tools let's search for</b>

45:43<b>google contacts under operation let's</b>

45:46<b>change this to update and for</b>

45:48<b>the contact id we'll let the</b>

45:50<b>agent populate this and for the fields</b>

45:52<b>let's let the agent decide as</b>

45:54<b>well now we have to also tell</b>

45:56<b>it which fields are allowed to be updated</b>

45:58<b>so let's click on add field</b>

45:59<b>let's select emails and under</b>

46:02<b>add email let's select home and for the</b>

46:05<b>value let's let the agent</b>

46:07<b>decide great let's go back</b>

46:08<b>to the canvas oh let's also rename this</b>

46:11<b>to update like so and let's</b>

46:14<b>actually test this workflow so</b>

46:16<b>it's searching for mary's details and we</b>

46:18<b>can see the update node</b>

46:19<b>actually failed saying the field</b>

46:21<b>dot join is not a function all right so i</b>

46:25<b>think this field selection</b>

46:26<b>is not going to work if the</b>

46:28<b>model tries to decide so instead let's go</b>

46:30<b>back to fixed and then in</b>

46:32<b>this list let's select email</b>

46:34<b>addresses and let's select names as well</b>

46:37<b>i think only selecting</b>

46:39<b>emails will work but let's give</b>

46:41<b>this a spin let's test this workflow so</b>

46:43<b>it's searching for mary</b>

46:44<b>now it's updating mary which</b>

46:46<b>was successful this time and the agent</b>

46:49<b>says mary lamb's email</b>

46:50<b>address has been updated and going</b>

46:52<b>back to our contacts it's showing mary at</b>

46:55<b>test at the moment and if</b>

46:56<b>we refresh this this now</b>

46:58<b>changed to mary.lam at test.com and of</b>

47:01<b>course this also changed</b>

47:02<b>the name so this is not ideal</b>

47:04<b>it's just fixed this again by changing</b>

47:06<b>this to mary and lamb let's</b>

47:09<b>save this let's go back to</b>

47:11<b>our contacts and i think the reason that</b>

47:13<b>happened is in this update</b>

47:15<b>node under update fields let's</b>

47:17<b>also add the family name and we'll let</b>

47:20<b>the agent decide and let's also add the</b>

47:23<b>given name and let's</b>

47:25<b>let the agent decide this as well so</b>

47:27<b>hopefully this will resolve</b>

47:29<b>this issue i'm just going to</b>

47:30<b>rename this back to mary lamb let's</b>

47:34<b>change the email to mary at</b>

47:35<b>test.com let's save this and</b>

47:38<b>let's give this agent a spin it's</b>

47:39<b>updating mary and if we refresh this this</b>

47:43<b>is now working correctly</b>

47:44<b>i could have cut this part out in editing</b>

47:46<b>but i do want to show you</b>

47:47<b>the process of troubleshooting</b>

47:50<b>and fiddling with these nodes until</b>

47:51<b>things work now that we have</b>

47:53<b>our contacts agent we can assign</b>

47:55<b>it to our supervisor so let's go to</b>

47:57<b>supervisor let's click on add</b>

47:59<b>tools let's call initn workflow</b>

48:02<b>tool and let's call this contacts agent</b>

48:05<b>for the description let's</b>

48:06<b>say use this tool for all</b>

48:09<b>contacts related actions then from the</b>

48:12<b>list of workflows let's</b>

48:13<b>select contacts agent cool and</b>

48:16<b>i'm also going to rename this to contacts</b>

48:19<b>now as a little aside you</b>

48:21<b>might see other tutorials</b>

48:22<b>injecting the list of tools into the</b>

48:25<b>system prompt but quite</b>

48:27<b>honestly it's quite redundant</b>

48:29<b>what initn will do is look at all the</b>

48:31<b>tools assigned to the agent</b>

48:32<b>and then dynamically inject</b>

48:34<b>the list of tools into the system prompt</b>

48:37<b>itself so there's no need</b>

48:38<b>for you to do that all you have</b>

48:40<b>to do is ensure that the description of</b>

48:42<b>each tool is accurate now</b>

48:44<b>let's try this out this time let's</b>

48:46<b>say send an email to john inviting him to</b>

48:49<b>my birthday party next</b>

48:51<b>saturday now watch what happens</b>

48:53<b>so let's send this message first it's</b>

48:55<b>going to our list of contacts to retrieve</b>

48:58<b>john's email address</b>

48:59<b>then it's sending the email as well and</b>

49:03<b>indeed i did receive that</b>

49:04<b>email addressed to john you</b>

49:07<b>might notice that the google search tool</b>

49:08<b>gets called from time to</b>

49:09<b>time as well and this is</b>

49:11<b>simply the agent retrieving the date for</b>

49:13<b>next saturday so the</b>

49:14<b>google search thing can be quite</b>

49:16<b>random but the agents usually got some</b>

49:18<b>reason for it now that we have the</b>

Creating a Calendar Agent

49:20<b>ability to send emails</b>

49:21<b>and easily access contacts let's also set</b>

49:25<b>up a calendar agent so</b>

49:26<b>when we invite john to our</b>

49:28<b>birthday the agent will also create an</b>

49:30<b>entry in our calendar let's</b>

49:32<b>go back to our dashboard let's</b>

49:34<b>create our workflow obviously let's give</b>

49:37<b>it a name like calendar</b>

49:38<b>agent and for the trigger let's</b>

49:41<b>select when executed by another workflow</b>

49:43<b>then let's select acceptable</b>

49:45<b>data let's pull in mock data</b>

49:48<b>let's remove all of this let's remove</b>

49:50<b>this and of course we need to change this</b>

49:52<b>to query and for the</b>

49:54<b>text let's say create a calendar entry</b>

49:57<b>for one march at 3 p.m</b>

49:59<b>titled birthday party let's save</b>

50:01<b>this let's go back to the canvas and</b>

50:04<b>generally speaking whenever</b>

50:05<b>we're dealing with dates and</b>

50:06<b>times i highly recommend going to</b>

50:09<b>settings then for the time zone let's</b>

50:12<b>select our local time zone</b>

50:13<b>so that will be Joanna's book for me</b>

50:15<b>let's save this and of course</b>

50:17<b>let's add our ai agent let's</b>

50:19<b>change the source to the query property</b>

50:22<b>over here let's go back</b>

50:23<b>to our canvas let's add our</b>

50:25<b>chat model which will be the openai chat</b>

50:28<b>model and we'll simply use</b>

50:30<b>gpt 4.0 mini let's add our first</b>

50:33<b>calendar tool let's search for google</b>

50:35<b>calendar tool then let's set up our</b>

50:37<b>credentials and as per usual</b>

50:40<b>we need the client id and secret so back</b>

50:43<b>to google cloud platform let's click on</b>

50:45<b>library let's search</b>

50:46<b>for calendar let's select google calendar</b>

50:49<b>api and let's enable access</b>

50:51<b>to this api let's go back to</b>

50:53<b>our credentials let's click on the oauth</b>

50:56<b>credentials i'll copy the</b>

50:57<b>client id and add it to n8n let's</b>

51:00<b>also add this client secret like so let's</b>

51:03<b>click on sign in with</b>

51:04<b>google let's select our google</b>

51:06<b>account on this screen let's simply go to</b>

51:08<b>n8n let's provide</b>

51:10<b>permissions to all of these let's</b>

51:12<b>continue and that's it the connection to</b>

51:15<b>google calendar was</b>

51:16<b>successful so for the operation we</b>

51:18<b>do want to create a calendar event i'm</b>

51:21<b>actually going to rename</b>

51:22<b>this note to create as well then</b>

51:25<b>in the calendar list i'm going to select</b>

51:27<b>my email account and for the</b>

51:29<b>start date and time i'm going</b>

51:30<b>to let the agent decide this and i'll do</b>

51:33<b>the same for the end date and time then</b>

51:35<b>under add additional</b>

51:36<b>fields scroll down to summary and we'll</b>

51:40<b>let the ai agent select this as well</b>

51:42<b>summary is simply the</b>

51:43<b>title of the invite let's go back to the</b>

51:46<b>canvas and looking at my</b>

51:48<b>calendar i don't have any invites</b>

51:50<b>for the first of march so in n8n let's</b>

51:54<b>run this workflow this is</b>

51:55<b>creating the event and looking</b>

51:57<b>at the response we can see that i've</b>

51:59<b>created the calendar entry for birthday</b>

52:01<b>party on the first of</b>

52:03<b>march at 3 pm but it used a year 2024 and</b>

52:07<b>that's because the allo m</b>

52:08<b>things we stole in 2024 so to</b>

52:11<b>fix that we can simply open up the agent</b>

52:13<b>then let's add a system</b>

52:15<b>message and we'll switch over</b>

52:18<b>to expression let's expand this and what</b>

52:21<b>we want to do now is simply tell the</b>

52:23<b>agent what the current</b>

52:24<b>date and time is like we did with the</b>

52:26<b>supervisor so let's say the</b>

52:28<b>current date and time is double</b>

52:31<b>curly braces dollar sign we'll use now</b>

52:36<b>dot to string that one so</b>

52:39<b>this one i'll tell the agent</b>

52:40<b>what the current date and time is and i</b>

52:42<b>will greatly fix the issues</b>

52:44<b>with creating these events</b>

52:46<b>let's run this again so it's creating our</b>

52:48<b>event we can see it</b>

52:50<b>created the entry for march 5th</b>

52:52<b>2025 and going to our calendar we can</b>

52:55<b>indeed see that entry</b>

52:56<b>wonderful now let's also give our</b>

52:58<b>agent the ability to check our calendar</b>

53:01<b>entries for us so let's</b>

53:02<b>add tools let's go to google</b>

53:05<b>calendar tool then under operation let's</b>

53:08<b>select get many and from</b>

53:10<b>the calendar list let's select</b>

53:12<b>our email account then for the limit i'll</b>

53:15<b>let the agent decide the</b>

53:17<b>same for the after and the same</b>

53:19<b>for the before then let's go back to the</b>

53:21<b>canvas i'm just going to</b>

53:23<b>rename this node to search and</b>

53:26<b>also let's go back to our trigger node</b>

53:29<b>and let's say what does my</b>

53:31<b>calendar look like on one march</b>

53:33<b>so let's save this let's test this</b>

53:35<b>workflow and it's calling</b>

53:37<b>the search tool and finally our</b>

53:40<b>agent is saying that on one march 2025</b>

53:42<b>you have the following</b>

53:43<b>scheduled events and it's only the</b>

53:45<b>one which is the birthday party between</b>

53:48<b>three and five fantastic</b>

53:50<b>let's go ahead and add this agent</b>

53:52<b>to our supervisor so let's go back to the</b>

53:55<b>dashboard let's go to</b>

53:56<b>supervisor let's click on</b>

53:58<b>add tools call in it in workflow tool and</b>

54:01<b>let's call this i'm also</b>

54:03<b>going to rename this node to</b>

54:05<b>calendar like so then for the description</b>

54:08<b>let's say use this tool for</b>

54:10<b>any calendar related actions</b>

54:12<b>and then from the list of workflows let's</b>

54:14<b>select the calendar agent</b>

54:16<b>and hopefully you're starting</b>

54:17<b>to see a pattern this is actually a lot</b>

54:20<b>of fun to use so now that we have a</b>

54:22<b>calendar agent set up</b>

54:24<b>we can provide some nice and complex</b>

54:26<b>scenarios like saying john an email</b>

54:29<b>asking if you wanted</b>

54:30<b>to play squash tomorrow at 2 pm also</b>

54:33<b>create an entry in my</b>

54:35<b>calendar let's just go ahead and send</b>

54:37<b>this and this is actually going to</b>

54:39<b>orchestrate quite a few activities first</b>

54:41<b>it's fetching john's</b>

54:42<b>email address then it's sending the email</b>

54:45<b>and creating the calendar</b>

54:47<b>entry first let's have a</b>

54:48<b>look at the email here i've received an</b>

54:51<b>email with the title squash</b>

54:52<b>came tomorrow and is saying hi</b>

54:54<b>john hope you're doing well i was</b>

54:56<b>wondering if you wanted to play squash</b>

54:58<b>tomorrow at 2 pm awesome</b>

55:00<b>let's also have a look at our calendar so</b>

55:03<b>let's go back to tomorrow</b>

55:04<b>and here we can see the entry</b>

55:07<b>called squash with john between two and</b>

55:09<b>three i don't know about</b>

55:11<b>you but this is phenomenal we</b>

Content Creator

55:14<b>still have two exciting tools to go next</b>

55:16<b>we're going to create a</b>

55:17<b>content creator and we can use</b>

55:19<b>this creative writer to come up with blog</b>

55:22<b>posts social media posts</b>

55:24<b>effectively we can add any type</b>

55:27<b>of creative writing over to this agent</b>

55:29<b>and after that i'll show you how to</b>

55:31<b>create a custom knowledge</b>

55:32<b>base where you can upload your own</b>

55:34<b>documents to effectively train</b>

55:37<b>your agent to answer questions</b>

55:39<b>from your own documents right let's go</b>

55:41<b>back to the dashboard and let's create</b>

55:43<b>this content creator</b>

55:45<b>agent let's rename this to content</b>

55:48<b>creator and of course for the trigger</b>

55:50<b>let's select when executed</b>

55:52<b>by another workflow from the drop down</b>

55:54<b>let's select accept all data</b>

55:56<b>let's pull in some mock data</b>

55:58<b>let's delete all of this let's delete</b>

56:00<b>this guy and let's rename</b>

56:02<b>this to query and for the value</b>

56:05<b>let's also pass in generate 10 unique</b>

56:08<b>title ideas for a</b>

56:09<b>youtube tutorial on building ai</b>

56:12<b>agents in n18 let's save this go back to</b>

56:15<b>the canvas and of</b>

56:16<b>course we'll add our ai agent</b>

56:18<b>we'll change the source to this query</b>

56:21<b>property and i am going to</b>

56:23<b>add a system message for this</b>

56:24<b>agent and this will simply be something</b>

56:26<b>like this add a role and</b>

56:28<b>let's say you are an expert</b>

56:30<b>content writer create seo-friendly posts</b>

56:33<b>articles etc based on the</b>

56:36<b>user's query and then of course</b>

56:37<b>let's also assign a large language model</b>

56:40<b>or any model that's very</b>

56:41<b>good at writing content and</b>

56:43<b>believe it or not that's actually all we</b>

56:45<b>have to do with this agent</b>

56:46<b>let's test this workflow just</b>

56:48<b>to make sure it's all working and i get</b>

56:50<b>my titles back awesome let's simply</b>

56:53<b>attach this agent to our</b>

56:54<b>supervisor so back over here let's add a</b>

56:57<b>tool let's add the call</b>

56:59<b>in a 10 workflow tool let's</b>

57:00<b>call this content creator i'm just going</b>

57:03<b>to rename this note to writer</b>

57:06<b>and for the description we can</b>

57:08<b>just say use this tool for any creative</b>

57:10<b>writing actions and from</b>

57:12<b>the list of workflows we'll</b>

57:14<b>select our content creator let's go back</b>

57:16<b>to the canvas let's move it</b>

57:18<b>next to the rest of our tools</b>

57:20<b>let's save this and of course let's give</b>

57:22<b>it a spin like write a</b>

57:24<b>detailed summary of the new</b>

57:25<b>grok3 model so what we're expecting to</b>

57:28<b>happen here is for the</b>

57:29<b>google search to be called and</b>

57:31<b>now our writer is being called as well to</b>

57:33<b>write the summary for us</b>

57:35<b>right and having a look at the</b>

57:36<b>output we can see that our writer came up</b>

57:39<b>with this beautiful article</b>

57:40<b>using its research results</b>

57:42<b>on this grok3 model so if we wanted to we</b>

57:45<b>could even instruct the</b>

57:46<b>agent to send that report via</b>

57:48<b>email as well that is how powerful this</b>

57:51<b>agent is getting now finally</b>

RAG & Knowledge Base

57:53<b>let's add a custom knowledge</b>

57:54<b>base to this agent the custom knowledge</b>

57:56<b>base will allow us to upload documents</b>

57:58<b>from our own machine</b>

58:00<b>and we can then ask the agent questions</b>

58:02<b>about those documents so</b>

58:03<b>these could be like pdf files</b>

58:05<b>it could be csv files word documents or</b>

58:08<b>anything you want so this allows our</b>

58:10<b>agent to go online to</b>

58:12<b>perform research but it can also answer</b>

58:15<b>questions from our own custom</b>

58:16<b>knowledge base almost like a</b>

58:18<b>second brain to set this all up we do</b>

58:21<b>have to create a database</b>

58:22<b>where all this custom data will</b>

58:24<b>be stored for this we will be using</b>

58:27<b>pinecone and this is free to</b>

58:29<b>use as well go to pinecone.io</b>

58:31<b>and sign up for your account then from</b>

58:34<b>this dashboard click on</b>

58:35<b>create index and give it a</b>

58:38<b>name like n8n masterclass and within</b>

58:42<b>configuration select text embedding3small</b>

58:46<b>this guy over here and</b>

58:48<b>click on create index right now we have</b>

58:51<b>our database set up and</b>

58:53<b>the next thing we want to do</b>

58:54<b>is to create an api key by going to api</b>

58:57<b>keys click on create api</b>

59:00<b>key and let's name this n8n</b>

59:03<b>masterclass and let's create this key you</b>

59:06<b>can simply copy this key</b>

59:07<b>and store it in a safe place</b>

59:09<b>but we will come back to this key in a</b>

59:11<b>few minutes first let's go back to n8n</b>

59:13<b>and let's click on add</b>

59:15<b>tool then let's select pinecone vector</b>

59:18<b>store click on create</b>

59:20<b>credential and then copy your</b>

59:22<b>api key and add it to n8n and let's save</b>

59:26<b>this great let's close</b>

59:27<b>this and for the name let's</b>

59:30<b>just simply call this knowledge base and</b>

59:32<b>i'm also going to rename this note to</b>

59:35<b>knowledge base as well</b>

59:36<b>and for the description let's enter use</b>

59:39<b>this tool when ask questions</b>

59:40<b>from our own knowledge base</b>

59:42<b>then from the list of indexes select n8n</b>

59:46<b>masterclass we can leave</b>

59:47<b>this value as 4 but this value</b>

59:50<b>simply tells the database how many</b>

59:51<b>documents it should return right let's</b>

59:54<b>then move the knowledge</b>

59:55<b>base down next to our tools and we also</b>

59:58<b>have to attach an embedding</b>

59:59<b>node so let's select openai</b>

1:00:02<b>and for the model selection we need to</b>

1:00:04<b>use the same model that we used when</b>

1:00:06<b>creating our pinecone</b>

1:00:08<b>index which was text embedding 3 small</b>

1:00:11<b>great at the moment if</b>

1:00:12<b>we ask agent any questions</b>

1:00:14<b>about our knowledge base it won't return</b>

1:00:16<b>anything as the database is currently</b>

1:00:18<b>empty we can see that</b>

1:00:20<b>by going to database let's click on our</b>

1:00:22<b>index and here we can see we</b>

1:00:24<b>don't have any records at the</b>

1:00:26<b>moment so what we'll do is we'll create a</b>

1:00:28<b>new workflow that is</b>

1:00:30<b>kind of a utilities workflow</b>

1:00:31<b>that we can use to upload documents into</b>

1:00:34<b>the database so let's</b>

1:00:35<b>give it a name i'm actually</b>

1:00:36<b>going to select this tool icon this time</b>

1:00:39<b>and let's call it update</b>

1:00:41<b>knowledge base for the trigger</b>

1:00:42<b>let's assign a form submission so we'll</b>

1:00:46<b>show a form to the user</b>

1:00:47<b>that they can use to upload</b>

1:00:48<b>documents for the title let's just call</b>

1:00:50<b>this upload documents for</b>

1:00:53<b>the field name let's call this</b>

1:00:55<b>file for the element type let's select</b>

1:00:57<b>file i'm going to disable</b>

1:01:00<b>multiple files as that does</b>

1:01:02<b>mean you have to deal with loops and</b>

1:01:03<b>things like that we'll</b>

1:01:04<b>simply keep it simple and this is</b>

1:01:06<b>indeed a required field let's go back to</b>

1:01:09<b>the canvas and let's click</b>

1:01:11<b>on test workflow and here</b>

1:01:13<b>we can see that we do indeed have a form</b>

1:01:15<b>i'm going to select the</b>

1:01:16<b>sample invoice on my machine</b>

1:01:18<b>and click on submit we can now close this</b>

1:01:21<b>pop up and if we have a look</b>

1:01:22<b>at this node we can see that</b>

1:01:24<b>the output is a binary file this simply</b>

1:01:27<b>means this is an image or a</b>

1:01:29<b>text file whatever after this</b>

1:01:31<b>let's add a new node and let's search for</b>

1:01:35<b>pinecone vector store and</b>

1:01:37<b>for the action let's select add</b>

1:01:39<b>documents to vector store from the</b>

1:01:41<b>pinecone index list let's select our</b>

1:01:44<b>database let's go back to the</b>

1:01:46<b>canvas under embeddings let's add the</b>

1:01:49<b>openai embedding node let's</b>

1:01:51<b>select text embedding3small</b>

1:01:53<b>then let's also add a document loader</b>

1:01:56<b>let's select the default data loader and</b>

1:01:59<b>instead of json let's</b>

1:02:01<b>change this to binary since this node is</b>

1:02:04<b>receiving a binary file on</b>

1:02:06<b>the left hand side we can leave</b>

1:02:08<b>all the other fields on the default</b>

1:02:09<b>values let's go back to the canvas and</b>

1:02:12<b>let's add a text splitter</b>

1:02:14<b>and i'll add the recursive character text</b>

1:02:17<b>splitter i'll change</b>

1:02:18<b>the chunk size to 2000</b>

1:02:20<b>with a chunk overlap of 200 so how this</b>

1:02:23<b>works is when we upload a</b>

1:02:25<b>document we don't want to</b>

1:02:27<b>upload a document in its entirety into</b>

1:02:29<b>the database and the</b>

1:02:31<b>reason is if the agent queried</b>

1:02:33<b>that document and let's say this was like</b>

1:02:35<b>a 20 000 character</b>

1:02:37<b>document or maybe something with</b>

1:02:39<b>thousands of pages we don't want to</b>

1:02:41<b>inject that entire document</b>

1:02:43<b>into the context or into the</b>

1:02:45<b>prompt to the agent that's going to get</b>

1:02:47<b>super expensive be very</b>

1:02:50<b>slow and most likely produce</b>

1:02:52<b>rubbish results so the solution is to</b>

1:02:55<b>take that large document and</b>

1:02:56<b>to chunk it into smaller pieces</b>

1:02:58<b>and we can determine the size of those</b>

1:03:01<b>chunks so that means when we</b>

1:03:03<b>query the database only the</b>

1:03:05<b>most relevant chunks will be returned and</b>

1:03:07<b>only those chunks will be</b>

1:03:09<b>injected into the prompt</b>

1:03:10<b>let's go back to the canvas and i think</b>

1:03:13<b>we should be able to test this let's</b>

1:03:15<b>click on test workflow</b>

1:03:16<b>i'll upload the sample invoice let's</b>

1:03:19<b>click on submit and this</b>

1:03:20<b>can be any document by the way</b>

1:03:22<b>you can take lecture notes it can be</b>

1:03:25<b>receipts pretty much</b>

1:03:26<b>anything so this execution was</b>

1:03:28<b>successful and if we go back to the</b>

1:03:30<b>database i'll refresh this page and we</b>

1:03:33<b>can see we now have two</b>

1:03:35<b>documents so my invoice was basically</b>

1:03:37<b>split into two separate documents and let</b>

1:03:39<b>it into the database</b>

1:03:41<b>now that we've got data in our database</b>

1:03:43<b>we should be able to test our agent so</b>

1:03:46<b>let's go back to this</b>

1:03:47<b>and let's ask a question relevant to that</b>

1:03:50<b>document and just to</b>

1:03:51<b>show you what that sample</b>

1:03:52<b>invoice looks like i actually just</b>

1:03:55<b>downloaded this online and</b>

1:03:56<b>this seems to be some internet</b>

1:03:58<b>invoice and if we look at the total</b>

1:04:01<b>amount it's 453 euros so</b>

1:04:04<b>let's ask our agent what was the</b>

1:04:07<b>gross amount of the invoice so looking at</b>

1:04:11<b>our workflow it</b>

1:04:12<b>correctly determined to call our</b>

1:04:14<b>knowledge base and in the response we are</b>

1:04:17<b>getting the correct value</b>

1:04:18<b>back so now your agent also has</b>

1:04:21<b>access to your second brain which is a</b>

1:04:23<b>custom knowledge base which you can</b>

1:04:25<b>upload any documentation</b>

1:04:27<b>to if you ever wanted to delete documents</b>

1:04:29<b>from this knowledge base</b>

1:04:30<b>simply go to the database</b>

1:04:32<b>and delete these entries so you can</b>

1:04:35<b>actually take this agent to the next</b>

1:04:36<b>level the next step is to</b>

1:04:38<b>integrate this agent into something like</b>

1:04:40<b>whatsapp or telegram so</b>

1:04:42<b>that you can access it from any</b>

1:04:44<b>where and did you know these agents also</b>

1:04:46<b>have multimodal support</b>

1:04:48<b>so you can have real-time</b>

1:04:49<b>voice conversations with these agents and</b>

1:04:52<b>you can also ask it to</b>

1:04:54<b>describe images for you check out</b>

1:04:56<b>how to do that in this video over here</b>

1:04:58<b>hit the like button</b>

1:04:59<b>subscribe and share this video and</b>

1:05:02<b>i'll see you in the next one bye bye</b>

This transcript was generated from the captions YouTube publishes for this video. Get the transcript of any YouTube video atfreeyoutubetranscribe.com: free, unlimited, no sign-up.