WEBVTT

00:00.200 --> 00:01.240
And week three.

00:01.280 --> 00:02.680
Day four is a go.

00:02.720 --> 00:03.880
Let's get started.

00:03.920 --> 00:08.000
So last time we did a stock picker and we just have a little tiny bit more to put into that.

00:08.000 --> 00:10.560
And then we're going to move on with our next project.

00:10.600 --> 00:12.320
A developer agent.

00:12.600 --> 00:14.640
But first another repetition.

00:14.640 --> 00:17.960
I hate to repeat these things, but sometimes it's good to drum it in.

00:18.240 --> 00:20.760
Building a crew project involves five things.

00:20.800 --> 00:23.120
First of all, crew I create crew.

00:23.560 --> 00:28.440
The name of the project to set up your crew, build those directories and those files.

00:28.480 --> 00:33.760
Number two, you find the YAML files for your agents and tasks, and you fill them in to define your

00:33.760 --> 00:35.040
agents and tasks.

00:35.280 --> 00:40.400
Number three, you go to the crew.py module, which is where you actually create the instances.

00:40.400 --> 00:44.960
And you use decorators to identify the agents and tasks that you'll be using.

00:45.000 --> 00:47.320
And then you create your crew itself.

00:47.360 --> 00:53.240
And this is where you can have structured outputs to make sure that the outputs conform to a schema.

00:53.240 --> 00:58.960
And you can use tools, both tools like Serpa, that crew provides for us that run remotely, and then

00:58.960 --> 01:03.060
custom tools that we build locally, like the thing that sends a push notification.

01:03.340 --> 01:10.020
And then number four, you update Main.py to set any inputs so that we can pass something in, configure

01:10.020 --> 01:12.140
the fields that are templated with the curlies.

01:12.500 --> 01:15.100
And finally we run with crew.

01:15.140 --> 01:18.220
I run and off goes our project.

01:18.740 --> 01:22.420
So I now want to cover a feature of crew called memory.

01:22.420 --> 01:28.060
And this is a feature that is a bit more prescriptive, a bit more opinionated in the crew framework.

01:28.100 --> 01:34.140
Memory, of course, is talking about how you provide information, contextual information to Llms each

01:34.140 --> 01:39.180
time you call them, and you can implement that yourself just by storing variables and then passing

01:39.180 --> 01:43.660
them in when you do things like creating tasks so you can do it the sort of manual way.

01:43.820 --> 01:49.180
But the crew framework also comes with some building blocks that lets you use their constructs around

01:49.180 --> 01:52.140
memory out of the box, and that comes with pros and cons.

01:52.180 --> 01:57.020
The pro is that you get up and running quickly, and you can use a lot of the thinking that they put

01:57.020 --> 01:57.820
behind this.

01:58.020 --> 02:03.610
The con is that there's there's a learning curve, and it obscures some of the detail of how prompts

02:03.650 --> 02:05.250
actually work behind the scenes.

02:05.250 --> 02:10.730
So as as with many times when you're adopting a framework like this, it's something to be aware of

02:10.810 --> 02:13.050
the benefits and the trade offs of doing so.

02:13.410 --> 02:18.130
But let's say that we are going to embrace cruise way of handling memory and talk about what it actually

02:18.130 --> 02:18.610
does.

02:18.850 --> 02:24.330
Well, it has five different types of memory, five different frameworks that you can include.

02:24.530 --> 02:26.850
And one of them is called short term memory.

02:26.850 --> 02:34.570
And this is just about storing recent interactions using a vector database in in a in a rag way.

02:34.570 --> 02:37.210
If you're familiar with retrieval augmented generation.

02:37.210 --> 02:40.650
And you don't need to be for this course because we're just going to put the code in there and see it

02:40.650 --> 02:41.130
run.

02:41.130 --> 02:43.250
But if you do no, then this will make more sense.

02:43.250 --> 02:49.850
So this will allow agents to access recent relevant information when they are currently executing.

02:50.450 --> 02:56.330
And then a different concept called long term memory is when more important information is stored in

02:56.330 --> 03:03.010
a SQL database for longer term recall to build up knowledge over over a longer period of time.

03:03.610 --> 03:08.510
And then there's something called entity memory that's very similar to short term memory, actually.

03:08.550 --> 03:15.310
It's it's basically when there's things about people, places and concepts, then those can also be

03:15.310 --> 03:22.430
stored in a Rag database for vector based similarity search and to be included in the context.

03:22.830 --> 03:26.110
And then there's crew describes this as another kind of memory.

03:26.110 --> 03:27.230
But I think it's a bit misleading.

03:27.230 --> 03:33.990
I think what they call contextual memory is just a sort of umbrella term for the short term, long term

03:33.990 --> 03:42.070
and entity memory that can all together be queried and passed in as context when prompting an LM and

03:42.070 --> 03:43.910
crew abstracts all this away from you.

03:43.910 --> 03:48.190
So it's just going to be a few lines of code to have all of these types of memories running.

03:48.390 --> 03:50.430
But in doing so, as I say, big benefit.

03:50.470 --> 03:53.070
A lot of work happens behind the scenes.

03:53.070 --> 03:57.030
And perhaps also there the trade off is that you've got less visibility into it.

03:57.030 --> 04:01.270
So if things don't go the way you want, then it's a bit harder to debug and figure out what's going

04:01.270 --> 04:01.630
on.

04:01.910 --> 04:08.500
And then there is another kind of memory called user memory, which is to store user specific information.

04:08.500 --> 04:14.940
And actually, at least as of now in Crewe, this is a concept that they support and have some frameworks

04:14.940 --> 04:21.300
around, but it's mostly left up to you to be querying user memory and then inserting it into the prompt

04:21.300 --> 04:22.900
or providing it at the right time.

04:22.900 --> 04:28.020
So user memory is a bit of an odd one out here, and I suspect that they're looking to build more into

04:28.020 --> 04:28.940
that in time.

04:29.260 --> 04:33.180
And for now, for the code that we're about to look at, we're just going to really look at contextual

04:33.180 --> 04:33.540
memory.

04:33.540 --> 04:40.300
So short term long term and entity memory and seeing how we can incorporate that into our stock picker

04:40.300 --> 04:40.980
solution.

04:41.420 --> 04:44.540
And so we're back in the stock picker project in cursor.

04:44.540 --> 04:47.260
And we are looking at the crew.py module.

04:47.580 --> 04:53.100
And I'm going to start by putting in some new imports in here, which are interesting ones from crime

04:53.100 --> 04:53.460
memory.

04:53.460 --> 04:58.500
We're going to import long term memory short term memory and entity memory.

04:58.500 --> 05:00.180
The three types we'll be working with.

05:00.220 --> 05:03.660
And I do believe you can also have user memory in there too.

05:03.700 --> 05:06.220
But then you have to manually manage it yourself.

05:06.800 --> 05:13.320
And then from my memory storage rag storage, we're importing a class called Rag storage for vector

05:13.320 --> 05:14.880
based retrieval.

05:15.160 --> 05:24.120
And with that we're also going to import from long term memory SQLite storage, long term memory SQLite

05:24.160 --> 05:26.720
storage object like that a class.

05:26.920 --> 05:27.400
All right.

05:27.400 --> 05:30.640
So that's a few things that we're now going to put to good use.

05:30.640 --> 05:37.080
We're now going to go to the crew function the function that creates the crew within this this module.

05:37.080 --> 05:39.320
And you can see where we made our manager.

05:39.320 --> 05:41.320
And we've got a few more things to make.

05:41.360 --> 05:48.120
As as cursor is trying to prompt us, they're trying to ignore cursors, insisting let's do it ourselves.

05:48.320 --> 05:48.720
All right.

05:48.720 --> 05:55.960
So we are going to to want to be creating a short term memory a long term memory and an entity memory.

05:55.960 --> 05:58.280
And we're going to do them one by one.

05:58.280 --> 06:04.440
So let's start by saying that the short term memory, which is the one that we'll begin with, short

06:04.480 --> 06:08.780
term memory, trying not to press a tab or it's going to fill it all in for me.

06:08.780 --> 06:10.820
But I'm going to I'm going to do it right here.

06:10.860 --> 06:14.940
Short term memory is going to be something which has rag storage.

06:15.340 --> 06:22.460
We we come up with a provider which is OpenAI, and a model, an embedding model to generate vectors

06:22.460 --> 06:23.420
from text.

06:23.420 --> 06:24.620
And we'll be using this one.

06:24.620 --> 06:27.860
And you can substitute in whatever models you would like here.

06:27.860 --> 06:29.220
It's going to be short term.

06:29.220 --> 06:35.380
And we give it a path to where we'd like it to create that memory, that vector store as memory.

06:35.620 --> 06:41.540
And it will use chroma as it happens, something which people who've taken my, uh, alarm engineering

06:41.540 --> 06:42.540
course know very well.

06:42.540 --> 06:43.460
I love chroma.

06:43.700 --> 06:47.180
All right, so that's the short term memory.

06:47.340 --> 06:50.660
Let's also create some long term memory.

06:50.660 --> 06:51.620
So here it is.

06:51.620 --> 06:57.260
The long term memory is going to be just simply creating an instance of this of this class long term

06:57.260 --> 06:58.820
memory SQLite storage.

06:58.820 --> 07:01.020
And we'll give that also a place to go.

07:01.060 --> 07:04.660
We'll make a database file also in the same directory.

07:04.980 --> 07:07.140
So that's the long term memory object.

07:07.500 --> 07:13.850
And now finally, thirdly, we're going to create a, uh, entity memory object.

07:13.850 --> 07:15.810
So entity memory.

07:16.290 --> 07:17.250
And there it is.

07:17.450 --> 07:19.450
So oh I see.

07:19.490 --> 07:19.730
Hang on.

07:19.770 --> 07:20.570
We've got two of them.

07:20.570 --> 07:21.530
Let's do that.

07:21.930 --> 07:22.810
Looks like that's good.

07:22.850 --> 07:25.250
So entity memory is going to be an entity memory object.

07:25.250 --> 07:28.930
It's also going to be a rag storage object.

07:28.930 --> 07:33.770
We give the provider and the embeddings model and we put it in the memory folder.

07:33.970 --> 07:40.370
So here we have our three types our short term memory our long term memory and our entity memory.

07:40.530 --> 07:44.530
And now we get to the place where we create our crew.

07:44.850 --> 07:47.210
And now it's going to be very challenging.

07:47.250 --> 07:48.570
It's not going to be challenging at all.

07:48.610 --> 07:51.170
We're going to say memory equals true.

07:51.890 --> 07:54.810
And we are going to then just do exactly that.

07:54.850 --> 07:57.490
So crew was a little bit off base with the memory equals part.

07:57.490 --> 07:58.690
But it's got the rest of it right.

07:58.690 --> 08:00.330
That's all you need to do.

08:00.490 --> 08:04.970
You set the long term memory the short term memory and the entity memory.

08:04.970 --> 08:07.010
And we are almost done with memory.

08:07.010 --> 08:08.610
Just just as simple as that.

08:09.170 --> 08:14.510
And I said almost because there is just one or rather two very small extra changes we need to make.

08:14.550 --> 08:21.910
We need to go back up in the module to where we created these agents the trading company, the financial

08:21.910 --> 08:23.430
researcher and the stock picker.

08:23.550 --> 08:25.310
And we need to give them memory.

08:25.350 --> 08:29.830
Now what we want is for the trading company finder to have memory.

08:29.830 --> 08:32.190
And we just do it by saying memory equals true.

08:32.510 --> 08:36.390
We don't actually want the researcher to have memory because we want it to go and do research every

08:36.430 --> 08:36.950
time.

08:37.110 --> 08:41.830
But we do want the stock picker to have memory, because we don't want it to recommend the same thing

08:41.870 --> 08:42.550
more than once.

08:42.550 --> 08:48.470
And I don't know if you remember, but in the prompts, in the YAML files, I said a couple of times,

08:48.790 --> 08:52.590
uh, don't, don't recommend the same stock twice and things like that.

08:52.590 --> 08:56.190
And, and surface new companies for the for the trading company finder.

08:56.190 --> 09:01.070
And that would normally be the final change you need to make is go back and make sure that your instructions

09:01.070 --> 09:05.750
and your YAML files are very clearly making sure that it will take advantage of memory.

09:05.750 --> 09:11.580
Because remember, whilst memory, these abstractions are trying to make memory seem quite magical and

09:11.580 --> 09:12.780
taken care of for you.

09:12.780 --> 09:19.660
At the end of the day, memory just means more stuff shoved into the prompt, more relevant context

09:19.700 --> 09:24.220
put into the prompt so that when you call an LLM it has knowledge.

09:24.260 --> 09:30.220
It's in the input is included information about prior conversations or about prior information that

09:30.220 --> 09:31.020
it retrieved.

09:31.340 --> 09:34.660
So with that we have set up set up the memory.

09:34.820 --> 09:39.860
And we are now going to bring up our terminal and then run this.

09:40.220 --> 09:43.900
And so as usual I go into already in the stock picker.

09:43.900 --> 09:47.540
So all I have to do is type a query I run and we'll be good to go.

09:47.740 --> 09:49.060
Let's see what happens.

09:49.260 --> 09:55.420
So just right off the bat, we expect it to be able to take advantage of memory without needing anything

09:55.420 --> 09:55.820
more.

09:55.980 --> 09:59.540
What we should see is it should create a memory directory in here.

09:59.540 --> 10:02.260
And it just has there is a memory directory.

10:02.460 --> 10:04.020
Stuff is going on.

10:04.060 --> 10:10.340
My computer is hard at work and I can see already within memory there is a Croma database that's being

10:10.340 --> 10:10.980
created.

10:10.980 --> 10:12.960
There is a long term memory.

10:12.960 --> 10:18.480
If I expand this, there is indeed a database that's been a SQLite database that's been created there.

10:18.480 --> 10:26.440
And so things are happening and we can see that, that, uh, various companies are being surfaced by

10:26.440 --> 10:33.320
the market watcher and more is going on and we will, uh, let this thing run.

10:33.360 --> 10:37.640
My computer's hard at work, and I will see you when we have a conclusion.

10:38.080 --> 10:39.640
And that definitely took a bit longer.

10:39.640 --> 10:43.040
It was going around around the houses a little bit, but it completed it.

10:43.040 --> 10:44.760
Recommended Microsoft this time.

10:44.880 --> 10:46.680
Remember, don't use this for real decisions.

10:46.680 --> 10:51.080
But it was, uh, entertaining to see it at work and bouncing around between the different agents.

10:51.200 --> 10:56.280
And whilst we don't have as much visibility into what's happening in terms of its use of memory and

10:56.280 --> 11:02.320
what context got provided, we can see that it's certainly built and populated different data stores

11:02.360 --> 11:09.320
and both the short term memory, the long term memory and the entity memory in the Rag chroma data store

11:09.320 --> 11:10.480
that's been created there.

11:10.520 --> 11:15.550
And the main point I want to get across is that, of course you can see the benefits of what this brings

11:15.550 --> 11:15.750
us.

11:15.750 --> 11:23.590
It was so easy to set up quite a complex situation, multiple types of memory with both vector similarity

11:23.590 --> 11:25.710
queries and SQL queries too.

11:25.750 --> 11:27.430
And we didn't need to know anything about it.

11:27.470 --> 11:29.830
We simply created the objects.

11:29.830 --> 11:33.950
The short term long term entity memory objects passed them in.

11:34.070 --> 11:40.190
And then we told our agents we turned memory on by saying memory equals true for the agents that we

11:40.190 --> 11:41.910
wanted to remember things.

11:42.350 --> 11:45.510
And that is a wrap on the stock picker project.

11:45.550 --> 11:49.350
We saw a lot of different aspects of Q AI with this project.

11:49.390 --> 11:52.150
We reminder, we saw structured outputs.

11:52.310 --> 11:55.870
We saw our own homegrown tool as well as Serpa.

11:56.190 --> 12:01.750
We also used the not the sequential but the hierarchical process.

12:01.950 --> 12:09.750
And now we have added in the memory feature all, all the three main types of memory in there as well.

12:09.790 --> 12:14.390
And that is a nice tour of a lot of the functionality in crew.
