WEBVTT

00:00.680 --> 00:07.080
In this video, we are going to take a look at how to add long term memory for our WhatsApp agents using

00:07.080 --> 00:07.760
Supabase.

00:08.320 --> 00:15.120
In one of my previous tutorials, I talked about how to build a WhatsApp agent that can take audio,

00:15.160 --> 00:16.920
images and text.

00:17.720 --> 00:24.280
But the problem is it has no memory because every time a user starts a new conversation, the chatbot

00:24.280 --> 00:31.160
forgets everything such as name of the user, the topics you've discussed, important details they mentioned,

00:31.360 --> 00:33.480
basically anything from your previous chats.

00:33.640 --> 00:36.280
So in this video I'm going to show you how to fix that.

00:36.600 --> 00:43.440
We are going to add long term memory to our WhatsApp AI agent so they can actually remember important

00:43.440 --> 00:50.120
details like usernames, preferences, past conversations and use that information to provide personalized

00:50.120 --> 00:52.600
responses across multiple chats.

00:52.960 --> 01:00.680
Now, why can't we just use short memory or something like RAC is because short memory in tools like

01:00.680 --> 01:02.840
N810 receives every session.

01:03.400 --> 01:07.600
That means the AI agent will forget as soon as the workflow ends.

01:07.960 --> 01:10.520
Or let's say you want to make a change in the workflow.

01:10.880 --> 01:13.600
Then the short term memory will also reset.

01:13.880 --> 01:19.840
Now, like on the other hand, is pulling info from documents or knowledge bases, but not for tracking

01:19.960 --> 01:22.360
personalized or user specific data.

01:22.680 --> 01:26.120
Like to remember the user name, preferences and so on.

01:26.440 --> 01:31.480
When it comes to storing this data long term, you have a few options.

01:31.800 --> 01:37.960
In general, Airtable is great, but for simple visual databases like this one.

01:38.200 --> 01:46.600
But it has API limitations, and LMS sometimes struggle to retrieve data from structured tables using

01:46.600 --> 01:47.600
semantic search.

01:48.680 --> 01:56.360
On the other hand, MongoDB is excellent for flexible JSON data, but we choose Supabase, which is

01:56.400 --> 02:03.680
a SQL database that offers a structure, first queries, and easy integration with tools like atom.

02:04.080 --> 02:05.920
So we're going to use Supabase instead.

02:06.800 --> 02:13.440
And by the end of this video, your agents will be able to remember important details from previous

02:13.440 --> 02:14.480
conversations.

02:15.600 --> 02:18.960
So now let's jump into it and create our workflow from scratch.

02:19.840 --> 02:22.400
First thing first we need to add our chicken node.

02:22.840 --> 02:24.680
So let's search for WhatsApp trigger.

02:28.640 --> 02:31.800
We want this workflow to be activated on message.

02:33.320 --> 02:34.720
Now let's set up credentials.

02:37.080 --> 02:38.400
So create credential.

02:40.200 --> 02:44.680
If your WhatsApp account is already connected to N810 feel free to skip this step.

02:44.720 --> 02:45.960
Otherwise, stick with me.

02:46.320 --> 02:49.760
I will guide you through setting up your credentials step by step.

02:50.600 --> 02:56.400
I will also show you a nice trick to extend your access token to 60 days.

02:56.560 --> 03:03.120
So even if your WhatsApp app is not live yet, and your business phone number is not officially verified.

03:03.720 --> 03:09.280
To make your app live, you won't have to regenerate the token every few hours as usual.

03:10.040 --> 03:16.480
In order to connect our AI agents to WhatsApp, we need to set up a meta application first.

03:17.080 --> 03:23.840
So let's head over to developers facebook.com and log in to your account.

03:24.520 --> 03:29.800
Once you are logged in, you will see my apps at the top.

03:30.600 --> 03:31.520
Click on that.

03:38.680 --> 03:40.360
And then hit create app.

03:40.400 --> 03:41.720
On the page that opens up.

03:46.120 --> 03:48.640
Now we need to give our application a name.

03:49.160 --> 03:50.560
I will call mine.

03:56.320 --> 04:01.280
WhatsApp integration tutorial.

04:03.960 --> 04:09.160
But you can name it whatever you like and also add your email.

04:17.720 --> 04:20.080
In the contact field and click continue.

04:20.760 --> 04:21.560
Click next.

04:26.600 --> 04:30.320
Okay, certain terms like WhatsApp are not allowed so I'm going to change it.

04:34.720 --> 04:35.680
And click next.

04:36.400 --> 04:37.280
Okay great.

04:37.840 --> 04:40.640
Next you will see different use case options.

04:40.760 --> 04:43.840
So you want to select other from this list.

04:44.320 --> 04:45.480
So just scroll down.

04:49.400 --> 04:52.800
Select other and hit next.

04:55.520 --> 05:04.360
Now on the following screen shows business since that's what we need for WhatsApp integration and confirm.

05:06.880 --> 05:10.520
Go ahead and click create App to finish this step.

05:11.240 --> 05:11.960
Perfect.

05:12.000 --> 05:14.480
Now you will see a list of available products.

05:15.560 --> 05:20.080
Look for WhatsApp in this list and click setup next to it.

05:25.760 --> 05:30.760
And here is where you might need to create a business portfolio if you don't have one already.

05:30.840 --> 05:35.800
So if the system asks for for this, don't worry, it's very simple to set up.

05:36.120 --> 05:40.800
Just open a new tab and go to business.facebook.com.

05:41.360 --> 05:46.400
Sign in with the same account, then look for the drop down menu on the left side.

05:48.200 --> 05:52.680
Click on that, then click on Create a Business Portfolio.

05:52.720 --> 05:53.400
From there.

05:56.560 --> 06:01.760
It will ask you for basic information like your portfolio, name and contact details.

06:02.160 --> 06:05.040
So fill that out and create your portfolio.

06:08.320 --> 06:12.440
Then come back to our app setup and select that portfolio from the drop down.

06:15.320 --> 06:16.560
And click continue.

06:18.320 --> 06:21.280
And now you should see WhatsApp appear in the left sidebar.

06:22.160 --> 06:23.560
So click on that.

06:26.120 --> 06:27.880
Click on API setup.

06:32.200 --> 06:35.640
And we'll be coming back to this section several times.

06:36.200 --> 06:39.960
The first thing we need to do is add our phone number for testing.

06:40.720 --> 06:46.600
So under this to drop down click on Manage Phone Number list.

06:48.800 --> 06:50.200
And then add phone number.

06:52.320 --> 06:58.280
And follows the simple verification process to add your number, you will get a code.

06:58.760 --> 06:59.600
Alright, great.

07:04.480 --> 07:07.560
Once that's done, select your number from the drop down.

07:12.600 --> 07:16.560
Next we need to generate the access token.

07:17.160 --> 07:18.360
So click on this button.

07:18.600 --> 07:21.760
It might ask you to log in again so just reconnect.

07:22.040 --> 07:24.960
This gives you credentials.

07:24.960 --> 07:26.960
We need to you need to connect.

07:27.160 --> 07:28.440
And they tend to add up.

07:30.000 --> 07:30.480
Great.

07:30.520 --> 07:32.800
Now let's test if everything is working.

07:33.160 --> 07:39.280
So scroll down on this page until you see Set Message and click on this button.

07:39.680 --> 07:42.880
And you should receive a text message on your WhatsApp.

07:44.600 --> 07:49.000
If you got that message perfect, our WhatsApp connection is ready and we can move.

07:49.560 --> 07:51.920
We can move on to building our workflow.

07:52.160 --> 07:56.080
Now there is something important to mention about this access token.

07:57.640 --> 08:02.240
Right now we are working with a temporary token that expires every few hours.

08:03.360 --> 08:10.000
So we need to refresh this token while we are building the agents and automations in N810.

08:10.880 --> 08:13.680
And this is totally fine for testing and development.

08:14.280 --> 08:19.680
But if you want to use this in production, you will need a permanent access token.

08:20.320 --> 08:25.800
And the reason we have this temporary tokens is because we are currently in development mode.

08:26.200 --> 08:27.200
As you can see here.

08:29.360 --> 08:35.280
For live application you would want to upgrade to a permanent solution.

08:35.880 --> 08:40.440
So to get a permanent token you need to verify your business with meta.

08:41.760 --> 08:47.640
I won't go through the full verification process in this tutorial since it involves business documentation,

08:48.120 --> 08:50.240
but this is also a very simple process.

08:53.080 --> 08:57.440
You'll need to go to your business portfolio and complete business verification.

09:00.120 --> 09:03.080
So if you look at your business settings right here.

09:08.040 --> 09:09.040
You'll find.

09:11.240 --> 09:12.600
Under business info.

09:15.360 --> 09:17.040
Business verification status.

09:19.240 --> 09:21.200
Just simply click on View Details.

09:27.760 --> 09:33.000
And this takes you through Metta's verification process where you'll need to provide business information

09:33.000 --> 09:34.080
and documentation.

09:34.320 --> 09:36.400
So just simply click on Start Verification.

09:37.120 --> 09:43.040
And once Mita approves your business verification, you can then generate permanent API credentials

09:43.040 --> 09:44.280
that won't expire.

09:44.600 --> 09:47.640
However, there are two workarounds.

09:47.640 --> 09:52.640
If you don't have a business phone number or a verified business to make your it up fully active.

09:52.920 --> 09:57.600
So the first one is to extend the validity of your access token to 60 days.

09:57.760 --> 10:05.760
So instead of constantly refreshing your access token to connect WhatsApp to N810, you can go to the

10:05.760 --> 10:08.200
Facebook Developer Tools.

10:08.400 --> 10:13.200
So click on the tools tab at the top and use Access Token Debugger.

10:14.080 --> 10:16.760
But first let's copy our access token.

10:18.600 --> 10:20.080
Go to API setup.

10:23.480 --> 10:24.760
Now let's copy the token.

10:26.480 --> 10:31.680
And now we can go to the Tools Access token debugger.

10:37.120 --> 10:38.880
Paste your access token right here.

10:44.200 --> 10:45.040
Press debug.

10:49.120 --> 10:51.840
And here at the bottom Extend access token.

10:52.920 --> 10:56.880
Now, as you can see, this token will expire two months from today.

10:57.880 --> 11:01.520
So this way you get 60 days before you need to refresh it again.

11:02.760 --> 11:05.880
So it's way more convenient than doing it every few hours.

11:06.960 --> 11:10.480
Now the second option is to actually make your app active.

11:10.920 --> 11:14.560
So switching from development mode to live mode.

11:15.160 --> 11:19.680
So when you hover over on it, you will see that in development mode, your app can only request data

11:19.680 --> 11:21.200
from users with an approval.

11:21.320 --> 11:27.560
To request end user data, your app must have advanced access permissions and be set to live mode.

11:27.880 --> 11:33.200
You can also use different Facebook accounts, add it as a test user, and use it that way, as I already

11:33.200 --> 11:33.800
showed you.

11:34.560 --> 11:36.400
But I'm going to show you a different way.

11:37.480 --> 11:39.160
So let's try to switch it to live.

11:40.240 --> 11:46.480
As you can see, you must provide a valid privacy policy URL in order to make your app live.

11:46.720 --> 11:50.160
Go to Basic Settings and make sure it is valid.

11:51.680 --> 11:52.960
So here is what you can do.

11:53.320 --> 12:00.880
You can go to ChatGPT and generate a basic privacy policy and also terms of service.

12:01.240 --> 12:04.720
So two separate documents then go to Google Drive.

12:06.520 --> 12:07.840
Create a new document.

12:13.040 --> 12:15.480
Paste the basic privacy policy here.

12:18.080 --> 12:18.400
Then.

12:30.000 --> 12:30.640
Save.

12:33.000 --> 12:37.160
Now change the access to anyone with the link.

12:37.840 --> 12:38.920
Then copy the link.

12:42.760 --> 12:44.280
Go back to your meta account.

12:48.440 --> 12:49.850
Go to Basic settings.

12:57.290 --> 12:59.850
And paste the Privacy Policy URL right here.

13:02.130 --> 13:04.770
And do exactly the same thing with Terms of service.

13:06.170 --> 13:08.330
So ask ChatGPT to generate it for you.

13:08.610 --> 13:11.050
Pass it to a new document in Google Drive.

13:11.610 --> 13:13.690
Then grab the link and paste it right here.

13:14.770 --> 13:22.730
Then save changes and after that you'll be able to change the app mode from development to life.

13:23.210 --> 13:29.170
So to wrap up this way, even without a verified business, you can still run WhatsApp agents.

13:29.850 --> 13:32.170
And next we need to set up our credentials.

13:34.450 --> 13:37.810
So click on the dropdown Create new credential.

13:38.410 --> 13:41.650
And now as you can see we need to provide client ID and client secret.

13:45.250 --> 13:48.970
So we need to grab our app details from meta Stromata for the connection.

13:49.610 --> 13:52.450
So let me go back to our meta dashboard.

14:01.410 --> 14:03.050
Now under settings.

14:04.810 --> 14:05.850
Click on basic.

14:17.650 --> 14:21.730
So here I can copy the app ID and I will pass this into the client ID field.

14:23.330 --> 14:26.210
I'm going to simply copy it.

14:29.850 --> 14:31.090
And paste it right here.

14:36.450 --> 14:38.170
And the same for App Secret.

14:43.690 --> 14:45.050
So I need to click show.

14:46.970 --> 14:50.010
Then copy that and paste it to the client secret field.

14:52.170 --> 14:57.970
It might ask you to login to your Facebook account again, so just simply reconnect.

14:58.970 --> 15:00.210
Copy up secret.

15:02.450 --> 15:07.050
Go back to LinkedIn and paste it into this field.

15:08.730 --> 15:09.530
Hit save.

15:14.770 --> 15:15.370
Perfect.

15:15.370 --> 15:22.650
I can see the connection successful message, which means our workflow can now receive WhatsApp messages.

15:23.730 --> 15:27.010
So I will close the credential window and test our setup.

15:31.970 --> 15:37.850
So let me click Execute Workflow to start monitoring for incoming messages.

15:38.610 --> 15:39.930
Now I'll switch to.

15:41.570 --> 15:50.250
Now I will switch over to WhatsApp and send a simple message like Let's send a simple message on WhatsApp.

15:51.370 --> 15:51.890
Hello.

15:53.170 --> 15:54.010
And hit save.

15:57.450 --> 15:57.850
All right.

15:57.850 --> 15:58.090
Great.

15:58.130 --> 15:59.250
Now we got some data.

16:01.690 --> 16:02.970
Now let's pin this data.

16:05.690 --> 16:07.010
All right, this data is pinned.

16:08.290 --> 16:10.010
Now let's add our agent.

16:10.770 --> 16:12.130
So click on add node.

16:13.530 --> 16:16.250
Select AI agent.

16:18.330 --> 16:22.730
Now we want to change the source for prompt to define below.

16:24.850 --> 16:28.730
Now for the prompt we want to use the actual message we just sent.

16:29.890 --> 16:35.890
So from the text object let's wrap body and drop it here.

16:36.770 --> 16:37.090
Alright.

16:37.090 --> 16:37.690
Perfect.

16:38.850 --> 16:39.730
Now let's move on.

16:44.250 --> 16:45.650
Now let's add our chat model.

16:48.210 --> 16:53.570
I'm going to use GPT four because it's cheaper and sufficient for this use case.

16:57.530 --> 16:58.650
So let's search for GPT four.

17:01.730 --> 17:02.610
All right great.

17:03.090 --> 17:05.090
Make sure you OpenAI account is connected.

17:11.290 --> 17:12.850
Now let's execute the workflow again.

17:14.930 --> 17:17.890
Now our agent prepared response for us.

17:18.570 --> 17:19.570
So we have output.

17:19.570 --> 17:22.010
We can use the response.

17:22.930 --> 17:25.250
Now we are going to add another WhatsApp node.

17:25.250 --> 17:30.490
But this time to send agents reply back to the user.

17:32.650 --> 17:34.050
So search for WhatsApp.

17:39.570 --> 17:42.890
We want to send message to select that.

17:44.850 --> 17:45.210
All right.

17:45.210 --> 17:45.690
Great.

17:47.450 --> 17:48.530
Now let's expand.

17:48.890 --> 17:50.010
What's a node?

17:51.690 --> 17:53.410
So for the resource we have a message.

17:54.650 --> 17:56.010
We want to send a message.

17:56.850 --> 17:59.850
And now we need to provide the recipient's phone number.

18:02.010 --> 18:04.490
We can find the number in context.

18:05.610 --> 18:08.890
So let's grab it and drop it into this field.

18:10.530 --> 18:10.850
All right.

18:10.850 --> 18:11.490
Perfect.

18:13.490 --> 18:17.530
Now what we want to do we want to provide a text body.

18:18.450 --> 18:20.370
So this is output from agent.

18:23.850 --> 18:24.250
All right.

18:24.250 --> 18:24.850
Perfect.

18:25.850 --> 18:32.330
Now we need to provide different type of credentials to connect our WhatsApp account to an A-10.

18:32.690 --> 18:37.530
Pay attention that credentials are different from the WhatsApp node.

18:39.130 --> 18:40.690
Let's add new credentials.

18:41.330 --> 18:42.570
Create new credential.

18:45.490 --> 18:46.610
And call it.

18:46.650 --> 18:47.690
Call this node.

18:48.970 --> 18:49.930
WhatsApp.

18:53.210 --> 18:54.010
Reply.

18:57.850 --> 19:05.370
Now we need two pieces of information here the access token and the business account ID.

19:05.810 --> 19:11.010
So let me switch back to our dashboard and go to the WhatsApp API configuration.

19:15.930 --> 19:20.930
So in the sidebar click on WhatsApp API setup.

19:35.850 --> 19:40.770
And as you can remember here we can generate access token generate access token.

19:41.490 --> 19:47.530
Now meta might ask you to log in to your Facebook account again.

19:47.730 --> 19:49.210
So just simply reconnect.

19:52.370 --> 19:53.650
Copy the access token.

19:56.210 --> 20:04.130
Go back to N810 and paste it right here for the Business Account ID.

20:05.050 --> 20:07.690
You can find that right here on the same page.

20:10.850 --> 20:14.610
As you can see WhatsApp business account ID, simply copy it.

20:17.050 --> 20:18.970
And paste it into this field.

20:22.090 --> 20:23.010
And hit save.

20:25.570 --> 20:26.290
Perfect.

20:27.050 --> 20:32.210
So if everything is configured correctly, we should see a green connection status.

20:33.930 --> 20:39.450
But if you get an error here, it's likely because the access token expired.

20:39.610 --> 20:43.010
So just regenerate it in meta and update n810.

20:44.330 --> 20:44.690
All right.

20:44.730 --> 20:44.930
Great.

20:44.970 --> 20:48.610
Now we are ready to give our agent long term memory.

20:48.810 --> 20:51.370
So let's create our Supabase database.

20:52.490 --> 20:55.770
So now let's jump into Supabase and create our database.

20:57.090 --> 20:59.730
First thing I'm going to do is head over to Supabase.

20:59.730 --> 21:00.250
Com.

21:01.410 --> 21:02.410
So sign up now.

21:05.290 --> 21:06.810
Provide email and password.

21:08.210 --> 21:11.330
If you don't have an account yet just sign up for a free one.

21:11.610 --> 21:13.210
It takes like 30s.

21:14.250 --> 21:17.250
Once you are in, we need to create a new organization.

21:17.770 --> 21:19.090
You don't need to have a company.

21:20.170 --> 21:24.850
I already have one organization, but I'm going to show you how to create one from scratch.

21:24.850 --> 21:26.770
So click on New organization.

21:29.690 --> 21:30.690
Now give it a name.

21:33.730 --> 21:34.650
Whatever we like.

21:36.690 --> 21:38.850
Type leave as is personal.

21:39.650 --> 21:40.970
And we are using free plan.

21:42.210 --> 21:45.210
Confirm by clicking on this create button.

21:47.530 --> 21:47.810
Cool.

21:47.810 --> 21:52.450
So now that we got our organization setup, we need to create an actual project.

21:53.610 --> 21:55.210
So click on New Project.

21:56.130 --> 21:58.450
We're going to need to pick a name for the project.

21:59.730 --> 22:05.330
So I'm going to say tutorials maybe WhatsApp.

22:17.850 --> 22:18.490
Specific.

22:18.930 --> 22:20.490
Now we need to set password.

22:21.090 --> 22:22.490
And please make a note of this password.

22:22.490 --> 22:23.450
This is really important.

22:24.010 --> 22:29.810
You can leave the region as default because this is the closest one to you for the best performance.

22:30.250 --> 22:32.210
Then click on Create New Project.

22:32.490 --> 22:34.530
So it will take a minute to spin up.

22:35.010 --> 22:36.410
You can see project status here.

22:36.450 --> 22:36.930
Alright, great.

22:36.970 --> 22:37.970
Now we have green light.

22:38.010 --> 22:38.770
We can move on.

22:38.810 --> 22:40.010
So our project is ready.

22:40.050 --> 22:43.770
Now we need to create a place to store our memories for our AI agent.

22:43.770 --> 22:46.730
So click on databases from the sidebar.

22:50.290 --> 22:51.730
Then hit Create New table.

22:56.810 --> 23:00.130
And right now it's empty because we don't have any table yet.

23:01.090 --> 23:03.170
So first let's give it a name.

23:03.450 --> 23:04.650
Let's say chat memory.

23:11.810 --> 23:15.730
Now when you scroll down you will see columns.

23:16.090 --> 23:20.410
Now here is where we set up what data we are actually going to store.

23:21.010 --> 23:22.610
And now we can add new columns.

23:24.130 --> 23:24.930
So first.

23:27.410 --> 23:28.450
Let's add column.

23:32.170 --> 23:33.170
Called message.

23:36.770 --> 23:38.610
And set the type to text.

23:42.330 --> 23:45.170
The next one will be recipient.

23:51.290 --> 23:52.410
Which is also text.

23:55.170 --> 23:56.090
And the last one.

23:56.290 --> 23:56.970
Sender.

24:01.810 --> 24:02.450
Text.

24:03.090 --> 24:03.410
All right.

24:03.450 --> 24:03.930
Perfect.

24:03.930 --> 24:07.770
So you have message because we want to store the actual message content.

24:07.810 --> 24:09.130
You have recipient column.

24:10.330 --> 24:12.890
This is gonna store who is receiving the messages.

24:13.330 --> 24:14.770
And finally the sender.

24:15.890 --> 24:18.810
So this tells us who sent each message.

24:18.930 --> 24:22.890
So basically the phone number of whoever is chatting with our agent.

24:23.170 --> 24:28.130
We already got Createdat which tracks when each message was sent.

24:28.290 --> 24:30.930
And that comes automatically, but I cool.

24:30.930 --> 24:31.970
That all looks good.

24:31.970 --> 24:32.890
Now hit save.

24:36.130 --> 24:37.890
And supervises created our table.

24:37.970 --> 24:40.650
now adding five columns to chart memory.

24:41.250 --> 24:42.250
So to our table.

24:45.650 --> 24:46.730
Let's wait a moment.

24:47.370 --> 24:47.970
And there we go.

24:47.970 --> 24:50.330
On the left hand side we can see our table.

24:50.890 --> 24:53.410
So we've got our chart memory table ready to go.

24:54.050 --> 24:59.250
Now that our database is set up let's connect it to our editing workflow.

24:59.610 --> 25:01.570
So let's go back to our editing dashboard.

25:05.890 --> 25:06.170
Here.

25:06.170 --> 25:08.210
So back in our editing workflow.

25:08.570 --> 25:11.970
Now we need to add Supabase as a tool.

25:12.170 --> 25:14.730
So our agent can actually save memories.

25:14.850 --> 25:16.490
So click on this Add Node button.

25:17.650 --> 25:19.490
And let's search for Supabase.

25:22.730 --> 25:28.610
And we want to use Supabase tool to add, get, delete and update data in a table.

25:30.290 --> 25:31.130
Let's select that.

25:33.130 --> 25:36.570
Now we want to leave the description as is as a resource.

25:36.570 --> 25:45.170
We have a row and we want to as an operation, we want to create because we are adding new records to

25:45.210 --> 25:46.290
our database.

25:46.290 --> 25:49.050
So now we got to set up the credentials.

25:49.530 --> 25:51.850
So let's add credential.

25:54.490 --> 25:56.010
Click on create Credential.

25:57.610 --> 26:02.730
And we need two things here the host URL and the service role secret.

26:03.050 --> 26:06.810
So to grab this go back to your Superbase project.

26:13.370 --> 26:14.810
Go to Project Settings.

26:16.850 --> 26:19.930
Then click on data API under configuration.

26:23.170 --> 26:24.250
Copy this URL.

26:24.490 --> 26:26.170
This is the URL of your project.

26:30.050 --> 26:33.690
Go back 2010 and paste it right here.

26:35.090 --> 26:41.570
Now you need to provide service for secret, so look for API keys in settings.

26:44.090 --> 26:44.970
By the way there is.

26:45.130 --> 26:46.570
They recently moved this section.

26:47.450 --> 26:48.610
So let's open it.

26:49.730 --> 26:55.050
Now let's reveal our service roll secret and let's copy it.

26:56.450 --> 26:57.690
Head back to N810.

27:02.170 --> 27:04.690
And paste it in the service secret field.

27:06.730 --> 27:07.450
It's safe.

27:09.370 --> 27:09.730
All right.

27:09.730 --> 27:10.170
Great.

27:10.730 --> 27:12.250
Now close that pop up.

27:15.410 --> 27:17.090
Now in your super base node.

27:19.330 --> 27:21.210
You will see table name or ID.

27:23.090 --> 27:25.650
So let's select the table we just created.

27:26.290 --> 27:27.210
So check memory.

27:28.250 --> 27:37.010
It should appear right now under data to send we need to map our fields.

27:37.010 --> 27:40.330
But first let's get some test data to work with.

27:40.890 --> 27:42.290
So save your workflow.

27:45.930 --> 27:47.050
And let's test it out.

27:48.250 --> 27:52.370
So I'm gonna send a text message something like.

27:52.850 --> 27:58.090
First I'm gonna execute workflow and send the message.

28:03.250 --> 28:04.330
My name is Damien.

28:13.610 --> 28:15.610
Great to see if it triggers.

28:15.970 --> 28:17.210
Let's see a response.

28:30.250 --> 28:31.290
Nice to meet you, Damien.

28:31.290 --> 28:32.490
How can I assist you today?

28:34.010 --> 28:40.650
And now if I click on the super base node, I can see that we've got the data from the inputs that we

28:40.650 --> 28:41.370
can save.

28:42.490 --> 28:44.890
So now we need to add some fields.

28:45.170 --> 28:47.410
So first let's add message.

28:48.330 --> 28:52.130
So let's select message which is string.

28:54.650 --> 28:59.010
And for the field value let's expand WhatsApp sugar node.

28:59.770 --> 29:00.890
And this is our body.

29:04.650 --> 29:05.250
All right great.

29:05.290 --> 29:08.810
Now let's add another field called sender.

29:14.730 --> 29:15.330
All right.

29:16.130 --> 29:21.490
And that's going to be the from field which is the phone number of whoever sent the message.

29:22.650 --> 29:26.970
So you can find it here within the messages object.

29:29.090 --> 29:29.610
Grab it.

29:29.610 --> 29:30.850
Drop it into this field.

29:31.850 --> 29:33.930
And the last one we want to add.

29:36.010 --> 29:36.770
One more field.

29:36.770 --> 29:38.850
So this will be a recipient.

29:41.290 --> 29:46.130
And that's going to be your test number or or whoever's receiving the message.

29:46.410 --> 29:50.970
You can find it uh in contacts WhatsApp ID.

29:54.290 --> 29:54.650
Alright.

29:54.650 --> 29:55.090
Great.

29:56.970 --> 30:02.170
So now we've got message sender and recipient or mapped correctly.

30:02.770 --> 30:03.050
Alright.

30:03.050 --> 30:03.730
Perfecto.

30:06.930 --> 30:10.970
Now as you can see we've got a tool created for saving messages.

30:11.250 --> 30:12.290
Let's rename it.

30:15.730 --> 30:20.370
To save message to make it clear.

30:23.890 --> 30:30.930
But the problem is we need to tell our agent when to actually save stuff to memory.

30:31.570 --> 30:37.050
Now let's add option and let's use System Message to put our prompt.

30:38.850 --> 30:40.650
Now let's switch over to expression mode.

30:41.330 --> 30:42.370
Let's expand it.

30:44.050 --> 30:48.530
We are gonna add a system message here so we can write our instructions.

30:50.610 --> 30:52.890
So I'm going to paste the prompt I prepared.

30:52.890 --> 30:55.450
So what we've got here we've got role.

30:55.650 --> 30:57.410
You are the assistant.

30:57.450 --> 30:59.970
We are currently chatting with a user on WhatsApp.

31:01.170 --> 31:07.770
We also have rules when the user sends a message check if they shared any important information that

31:07.770 --> 31:09.770
should be saved in memory for later.

31:10.210 --> 31:13.650
If yes, use the save memory tool to save it.

31:14.170 --> 31:18.650
Do not tell the user that you are saving anything, just keep the conversation going.

31:18.690 --> 31:19.370
As usual.

31:19.610 --> 31:25.330
We also have tools, so use this tool to store any important facts shared by the user.

31:25.930 --> 31:29.810
Summarize the information clearly and pass it to this tool.

31:31.290 --> 31:33.610
Now this sentence is optional.

31:35.330 --> 31:39.490
If you want your agent to tell users it's saving info.

31:39.530 --> 31:40.650
You can change that.

31:42.330 --> 31:47.050
Now we'll look at memories in a sec, but we also have important section.

31:47.050 --> 31:49.210
So use this stored info when replying.

31:49.770 --> 31:53.090
If something is already saved, don't ask for it.

31:53.090 --> 31:56.050
Again, keep your responses natural and friendly.

31:57.410 --> 31:58.690
So this is important.

31:58.890 --> 32:05.250
We only want to store new facts, so if something is already in memory, we don't want it to keep us

32:05.290 --> 32:07.370
asking the same questions over and over.

32:08.530 --> 32:10.250
And now here is a cool trick.

32:10.570 --> 32:13.050
So let's go to our super base node.

32:16.890 --> 32:24.690
Since we are letting the AI decide what's important to save, we can also let it summarize the info

32:24.730 --> 32:27.610
instead of just saving the raw message.

32:27.970 --> 32:36.730
So in the super base node In the message field, we can let the model define this parameter.

32:37.610 --> 32:38.610
So click on that.

32:39.250 --> 32:48.210
So this lets the LM automatically generate what to save instead of just outputting the exact user message.

32:49.650 --> 32:51.650
So choose define automatically by the model.

32:53.010 --> 32:59.450
And now the AI will extract and summarize the important information before saving it.

33:00.530 --> 33:01.050
Alright great.

33:01.090 --> 33:02.210
Now let's test this out.

33:03.810 --> 33:05.090
So let's save the workflow.

33:08.290 --> 33:16.370
Now, before we give it a test and check if our Supabase save message node is working, let's disconnect

33:16.370 --> 33:17.290
these two nodes.

33:18.210 --> 33:19.890
So I'm going to remove the connection.

33:21.370 --> 33:27.370
And I'm going to send a simple message on WhatsApp because I didn't pin the data.

33:27.370 --> 33:30.130
So I don't have any data in the flow in this node.

33:31.970 --> 33:33.130
So execute workflow.

33:39.330 --> 33:39.850
Hello.

33:41.730 --> 33:42.410
Send.

33:45.890 --> 33:47.330
Now let's open this node.

33:51.130 --> 33:56.530
I wanted to send the message again because I need to pass the message to our agent.

33:57.170 --> 33:58.610
So now I'm going to.

34:02.530 --> 34:03.650
Connect these two nodes.

34:09.650 --> 34:11.130
Let's open our agent.

34:13.090 --> 34:19.970
Now we need to prepare the reference the WhatsApp trigger node because this agent doesn't receive the

34:19.970 --> 34:21.170
message directly.

34:22.650 --> 34:25.010
So let's remove this JSON prompt.

34:26.730 --> 34:30.810
And now within the messages object from the text object.

34:31.610 --> 34:36.850
Let's grab Body field and drop it here into the prompt field.

34:38.210 --> 34:38.970
Alright, great.

34:39.370 --> 34:41.010
Now let's give it a test.

34:41.010 --> 34:42.130
So save workflow.

34:45.610 --> 34:46.610
Execute workflow.

34:48.290 --> 34:49.810
And now let's send another message.

34:49.810 --> 34:53.410
But this time let's say something like.

34:55.650 --> 34:56.730
My name is Damien.

35:03.370 --> 35:07.770
And before I send the message, just to remind you.

35:11.890 --> 35:16.690
In our chat memory table, there is no information about my my name.

35:18.370 --> 35:21.890
And now, when I send the message.

35:28.570 --> 35:36.410
I can clearly see that the message has been passed to the save message node, but we can also double

35:36.410 --> 35:40.650
check by going to executions.

35:49.370 --> 35:50.970
Let's check the last execution.

35:56.650 --> 35:58.490
Yes, as you can see on the screen.

36:00.850 --> 36:04.570
This execution should save the record to memory.

36:05.730 --> 36:08.290
So let's check our super base table.

36:12.410 --> 36:13.810
Now when I refresh the table.

36:18.370 --> 36:20.370
I can see that my name has been saved.

36:22.290 --> 36:23.250
Alright, perfect.

36:25.410 --> 36:27.380
I can see what got saved.

36:27.740 --> 36:37.940
So send the info so the recipient number and the message which is the I summarized as user's name is

36:37.980 --> 36:38.500
Damon.

36:40.060 --> 36:42.940
Plus we also have the Createdat timestamp.

36:46.740 --> 36:50.100
And now if I hop over to N810.

36:52.220 --> 36:57.340
Go back to editor and open save message node.

36:58.580 --> 37:00.060
I can see the same data.

37:00.340 --> 37:07.020
So created at timestamp message darker message recipient and sender.

37:08.220 --> 37:08.620
All right.

37:08.620 --> 37:09.220
Perfect.

37:11.460 --> 37:16.260
So now we are successfully saving important facts to our database.

37:18.340 --> 37:25.580
Now that we are saving memories to our database, we need to retrieve them and pass them to our agent

37:25.580 --> 37:28.740
so it can actually use that data.

37:28.780 --> 37:29.660
Use that info.

37:31.900 --> 37:35.740
So let's add another node between WhatsApp trigger and agent.

37:37.460 --> 37:39.260
Let's search for spark again.

37:47.420 --> 37:48.460
Select Supabase.

37:50.900 --> 37:59.500
And we want to get many rows because we want our agent to fetch memories from the chat memory table.

38:00.020 --> 38:03.140
And based on that generate response.

38:04.580 --> 38:06.380
So select get many rows.

38:09.820 --> 38:15.620
Make sure you are using the same credentials as for the safe message node.

38:17.860 --> 38:19.060
For the resource you have a row.

38:19.060 --> 38:23.860
Because we want to get rows, we want to get many rows.

38:24.100 --> 38:30.340
Here you can also change it to create delayed getrow update and so on.

38:31.980 --> 38:38.100
So in other words, because you want to read the data, not write it, we are using get operation.

38:39.220 --> 38:43.980
Now here I've got an error because I'm using a wrong credentials.

38:44.500 --> 38:46.580
So I'm going to change it to Supabase.

38:47.940 --> 38:51.340
And now I'm able to select the table I created.

38:51.340 --> 38:52.580
So chat memory.

38:53.460 --> 38:54.500
So select the table.

38:56.540 --> 38:58.820
Now you want to return all records.

39:00.180 --> 39:05.020
And now this is very important because we don't want all records from everyone.

39:05.300 --> 39:09.740
We only want memories for the specific person who is chatting.

39:10.900 --> 39:12.780
We need to add a filter condition.

39:13.980 --> 39:14.980
So add condition.

39:17.060 --> 39:18.100
For the field name.

39:18.420 --> 39:23.380
Select sender as a condition.

39:24.660 --> 39:26.740
Let's choose equals.

39:29.380 --> 39:36.100
And for the fieldvalue, let's pass in the sender's phone number from our WhatsApp note, which you

39:36.100 --> 39:38.940
can find in the contacts object.

39:40.260 --> 39:41.060
So wha.

39:44.260 --> 39:45.220
Alright, perfect.

39:46.740 --> 39:47.780
Now let's test it.

39:48.580 --> 39:49.940
So let's execute step.

39:53.140 --> 39:58.300
And now you should see on the right side that one item has been retrieved.

39:59.100 --> 40:01.780
So the message user's name is Damien.

40:02.900 --> 40:04.940
Now let's send another test message.

40:05.860 --> 40:07.580
So I'm going to save the workflow.

40:08.100 --> 40:09.300
Just moving this note.

40:19.540 --> 40:20.740
I'm going to save it.

40:24.340 --> 40:25.140
Test workflow.

40:27.060 --> 40:29.300
Let's say I like dogs.

40:32.660 --> 40:33.420
Hit send.

40:34.900 --> 40:39.060
There is the new record saying that user likes dogs.

40:43.020 --> 40:45.820
And now when I test the Get Memories tab.

40:48.900 --> 40:50.060
So let's press on it.

40:57.780 --> 40:58.780
And I edit it.

41:04.980 --> 41:06.420
We should see two items.

41:06.780 --> 41:11.500
So two records the same as in the chat memory table in Supabase.

41:11.540 --> 41:11.980
Perfect.

41:12.020 --> 41:16.900
Now we've got a user's name is Damon and user likes dogs.

41:17.620 --> 41:18.140
Cool.

41:18.580 --> 41:22.980
Now, before we pass this to our agent, I want to clean up the data.

41:22.980 --> 41:29.820
So we don't need all those database fields, just the actual messages and when they were sent.

41:30.380 --> 41:39.420
So to do this we need to add an aggregate node after SQL base get memory node.

41:39.860 --> 41:44.220
So first let's rename this node to get memory.

41:53.620 --> 41:55.460
And now let's add aggregate node.

41:58.340 --> 41:59.540
Search for aggregate.

42:02.300 --> 42:06.500
To combine a field from many items into a list in a single item.

42:09.940 --> 42:14.460
And now we want to choose all item data into a single list.

42:14.860 --> 42:20.860
And for the output field name, let's call it chat memory.

42:20.860 --> 42:20.940
40.

42:25.900 --> 42:29.140
Four include select specific fields.

42:31.220 --> 42:36.500
And type just message and Createdat.

42:40.420 --> 42:43.420
Because that are the only fields we need from our table.

42:46.500 --> 42:47.940
Message and Createdat.

42:49.580 --> 42:51.980
We don't need the data from the rest of the columns.

42:53.700 --> 42:55.140
And now when we test this step.

42:55.180 --> 42:56.180
So execute step.

43:00.020 --> 43:00.940
And edit it.

43:02.460 --> 43:06.260
You can see that now we have a nice clean data.

43:07.260 --> 43:10.300
Just the conversation memories and timestamps.

43:11.340 --> 43:13.340
Now let's go back to our agent node.

43:13.820 --> 43:18.620
Because we need to pass both the new user message and the retrieved memories.

43:20.060 --> 43:21.260
So for the prompt.

43:24.540 --> 43:25.500
Let's expand it.

43:28.580 --> 43:33.340
For the memories we are gonna pass in our conversation.

43:33.340 --> 43:35.620
Memories from the aggregate node.

43:37.220 --> 43:38.500
From the aggregate node.

43:38.740 --> 43:41.220
Let's grab chat memory and drop it here.

43:42.540 --> 43:48.660
Now on the right you can see it's returning a JSON object, but our agent needs text.

43:49.060 --> 43:59.580
So click on the chat memory field, type dot two and select JSON string.

44:04.460 --> 44:07.860
So this converts the object into text format as you can see.

44:08.860 --> 44:13.940
So now we've got the message dates and the actual message in the format.

44:14.420 --> 44:15.820
Our agent can understand.

44:17.220 --> 44:20.100
Now let's close this up and test the entire workflow.

44:22.460 --> 44:24.260
All right, let's hit save.

44:27.300 --> 44:28.860
Now I need to unpin data.

44:31.100 --> 44:34.860
So we can send a fresh data into the flow.

44:35.740 --> 44:36.740
So let's open it.

44:39.980 --> 44:43.700
And now let's save execute workflow.

44:44.900 --> 44:46.580
And I'm going to send a simple message.

44:49.340 --> 44:50.140
What's my name.

44:56.700 --> 44:57.940
Let's see the output.

44:59.420 --> 45:00.260
The name is Damien.

45:00.820 --> 45:01.860
How is it going today.

45:03.020 --> 45:04.140
So as you can see it's working.

45:04.140 --> 45:05.300
It remembers my name.

45:06.100 --> 45:11.660
Now let me turn the workflow to active to active mode so we can do more testing.

45:15.420 --> 45:15.980
Confirm.

45:19.940 --> 45:25.620
Let's ask, do I like dogs or cats?

45:32.140 --> 45:33.460
Let's see the executions.

45:39.140 --> 45:39.700
Are great.

45:41.540 --> 45:43.140
Now let's check the response.

45:48.140 --> 45:49.620
You mentioned that you like dogs.

45:49.620 --> 45:53.020
Do you have a favorite breed or any dog related stories to share?

45:55.580 --> 45:57.180
So it remembers that I like dogs.

46:00.100 --> 46:02.900
So as you can see, we've got long term memory working.

46:02.900 --> 46:08.460
It's storing info in Supabase and retrieving it to generate responses.

46:09.660 --> 46:11.140
Let's give it a final test.

46:13.820 --> 46:18.020
I'm going to ask I'm going to say I like sushi.

46:22.740 --> 46:23.100
All right.

46:23.100 --> 46:25.260
This information should be saved in our table.

46:29.540 --> 46:30.540
Use it like sushi.

46:35.020 --> 46:38.620
Let's ask, what food do I like?

46:48.180 --> 46:48.820
Like sushi.

46:48.820 --> 46:50.420
Do you have a favorite type of sushi?

46:51.460 --> 46:51.780
All right.

46:51.780 --> 46:52.420
Perfect.

46:53.540 --> 46:56.460
Now, throughout this conversation, I ask a bunch of questions.

46:57.060 --> 47:02.700
But the only really important info from our conversation was my name.

47:03.460 --> 47:06.860
And also that I like dogs and like sushi.

47:07.700 --> 47:11.660
So all these three facts are saved in our chat memory table.

47:13.620 --> 47:16.820
So the agent was able to filter out.

47:18.180 --> 47:19.820
all the random sentences.

47:19.820 --> 47:25.780
It only stored the actual important facts because that's what we told it to do in our system message.

47:25.820 --> 47:27.300
So in our prompt.

47:28.380 --> 47:28.700
Cool.

47:28.740 --> 47:36.180
Now your agent is able to save important information from conversations into memory and retrieve it

47:36.180 --> 47:41.860
along with a new user's prompts to generate personalized responses.

47:41.900 --> 47:46.940
This really changes how your WhatsApp agent works because it can remember stuff.

47:47.220 --> 47:52.940
For example, if you are building this type of solution for your own business or your client's business,

47:53.660 --> 47:56.460
it can help build a relationship with customers.

47:56.860 --> 48:02.980
It can be super useful if you are trying to build a kind of a second brain and chat with your agent

48:02.980 --> 48:03.780
through WhatsApp.

48:04.260 --> 48:06.940
Of course, you can switch to Telegram or Slack if you want.

48:07.540 --> 48:13.180
Yes, adding long term memory with Supabase makes it way more solid and production ready.

48:13.620 --> 48:16.500
I hope this was helpful and see you in the next tutorial.
