WEBVTT

00:00.240 --> 00:02.880
And now for something completely different.

00:03.080 --> 00:10.200
We are going to work on making an agent that knows how to code, how to write Python code, how to write

00:10.240 --> 00:14.360
software, and a little bit more than that, it's not only going to know how to write software, but

00:14.400 --> 00:16.000
how to run it as well.

00:16.400 --> 00:25.120
So this is challenging and complex, but it's possible to have an agent in Crewe in the Crewe environment,

00:25.120 --> 00:26.320
which has this ability.

00:26.360 --> 00:32.480
Not only is it able to to take a problem that you set it, it can write code to solve that problem.

00:32.720 --> 00:36.560
It can then execute that code in a Docker container.

00:36.560 --> 00:41.000
It doesn't need to, but it's good to have it run it in a Docker container, which means that it is

00:41.040 --> 00:46.120
a sort of sandboxed, ring fenced environment that doesn't have access to do damage to your computer

00:46.120 --> 00:52.280
because it's in this protected world, and then it can run the code, it can execute it in that container

00:52.280 --> 00:57.120
and look at the results and interpret those results to take on some more action.

00:57.120 --> 01:01.790
So as I say this, this is this is a really advanced Task.

01:01.830 --> 01:06.150
This is something that's taking us to the next level, and it's going to be hard and complex.

01:06.670 --> 01:09.390
Except it's not going to be hard or complex.

01:10.510 --> 01:16.390
You probably saw that coming, but it is going to be as simple as when we create an agent, we're going

01:16.470 --> 01:18.910
to say allow code execution equals true.

01:19.390 --> 01:20.390
And that's going to be it.

01:20.390 --> 01:22.470
And then it's going to be able to execute code.

01:22.590 --> 01:27.310
And if you say code execution mode equals safe, then if you have Docker installed on your system and

01:27.310 --> 01:31.950
I will show you how to install Docker, if you don't, it will run it in a Docker container.

01:32.190 --> 01:34.470
And it seems almost so good.

01:34.510 --> 01:36.030
It's uh, it's crazy.

01:36.030 --> 01:40.670
I had to like close down docker to make sure that that it that it failed when I, when, when uh, when

01:40.670 --> 01:43.910
it was closed because I almost couldn't believe it was happening.

01:43.950 --> 01:45.590
It's that simple.

01:45.590 --> 01:51.990
And this is where frameworks like crew really stand out because they make things like this so very easy

01:51.990 --> 01:52.510
to do.

01:52.910 --> 01:56.910
It's worth mentioning that these this kind of system is sometimes called a Coda agent.

01:56.950 --> 01:58.870
It's various other names for it, you hear.

01:58.870 --> 02:03.610
And it's worth knowing that when people talk about Coda agents, they're not just talking about agents

02:03.610 --> 02:05.250
that can deliver code.

02:05.290 --> 02:11.010
Agents that are able to generate Python, but also this ability to generate Python and then run that

02:11.010 --> 02:17.970
Python as steps towards solving a greater problem so that this is more a means to an end than just saying

02:18.130 --> 02:20.330
it is something which which writes code.

02:20.370 --> 02:23.610
Now, confusingly, our project for this week we are going to build something that writes code.

02:23.650 --> 02:27.290
But but the fact that that it can run it too is kind of cool.

02:27.610 --> 02:29.610
So that is the introduction.

02:29.610 --> 02:32.250
And with that let's go and actually build something like this.

02:32.290 --> 02:33.890
Let's build something that can write it.

02:33.930 --> 02:36.170
We'll make something that can write code and can run it.

02:36.170 --> 02:37.130
Let's do that.

02:37.170 --> 02:38.010
See you in a sec.

02:38.450 --> 02:38.890
Okay.

02:38.890 --> 02:40.370
Welcome back to cursor.

02:40.410 --> 02:42.970
Welcome back to the crew folder.

02:43.210 --> 02:49.250
And I'm going to open up a new terminal and go into that third folder.

02:49.250 --> 02:50.810
And you know how to create a crew project.

02:50.810 --> 02:53.210
So well now that you have it committed to memory.

02:53.330 --> 02:59.770
But you know that it's crew I, which I can't spell crew, I create crew.

03:00.210 --> 03:07.080
And then the name of the project, which we will call coda, and it's going to build the directories,

03:07.080 --> 03:08.520
it's going to do the scaffolding.

03:08.520 --> 03:13.520
All we have to say that we want OpenAI and we want GPT for our mini, and we don't need a key.

03:14.000 --> 03:19.280
And Kabam, we have all of the folder structure.

03:19.320 --> 03:20.040
Great.

03:20.400 --> 03:20.960
Okay.

03:21.000 --> 03:28.120
So as always, the first thing we do is we go into the config and we start by defining our agents.

03:28.440 --> 03:30.160
So what agents are we going to have.

03:30.160 --> 03:32.080
We're only going to have one this time.

03:32.080 --> 03:34.240
It's going to be a very simple agent.

03:34.240 --> 03:37.280
Let me just remove this so we can see what we're doing.

03:37.520 --> 03:44.560
Let's delete the the scaffolding and put in our coda agent.

03:44.800 --> 03:49.080
So we're going to say you are a Python developer.

03:49.080 --> 03:54.240
That's the role you write Python code to achieve this assignment.

03:54.240 --> 04:00.320
And then we pass in the assignment that is the input that will be set in the run method.

04:00.880 --> 04:03.000
First you plan how the code will work.

04:03.260 --> 04:07.460
Then you write the code, then you run it and check the output.

04:08.140 --> 04:08.940
Backstory.

04:08.980 --> 04:12.180
A seasoned Python developer with a knack for writing clean, efficient code.

04:12.220 --> 04:14.700
And we can use GPT four or mini.

04:14.740 --> 04:18.380
Yes, you can do it either way, but we'll do what cursor suggests.

04:18.420 --> 04:22.660
Change it to have the provider and the name of the model which looks a bit better.

04:23.580 --> 04:26.020
Okay, so there we go.

04:26.060 --> 04:26.940
That's pretty simple.

04:26.940 --> 04:29.700
That was our single agent.

04:29.980 --> 04:32.900
And we're going to have one single task.

04:33.300 --> 04:34.580
Let's put it in here.

04:35.020 --> 04:38.460
It is right Python code to achieve this assignment.

04:38.500 --> 04:40.220
A text file that includes the code.

04:40.300 --> 04:45.900
So so the output we want from it is a text file that includes the code and the output of the code.

04:45.900 --> 04:48.060
We want it to put both in the output.

04:48.260 --> 04:52.820
So I've called it code and output text as the output.

04:53.140 --> 04:54.820
So that is what we want it to do.

04:54.860 --> 04:59.820
So because I really want to make the point that it's going to write code, run it, get the output and

04:59.820 --> 05:03.540
it's going to think all of this through and then respond with all of that.

05:03.540 --> 05:08.330
We don't just want it to give us the output because we want to double check what it's doing is right.

05:08.850 --> 05:11.890
Okay, now we know we have to go to the crew module.

05:11.890 --> 05:13.010
Let's do that next.

05:13.530 --> 05:13.970
Okay.

05:13.970 --> 05:19.010
Here we are in the crew module that I've just gone through and deleted the templating stuff that's in

05:19.010 --> 05:20.290
there by default.

05:20.530 --> 05:24.050
And so we're just leaving our config relationships here.

05:24.130 --> 05:26.210
And I'm just going to put a little comment here.

05:26.650 --> 05:27.970
Make that a comment as well.

05:28.010 --> 05:28.450
Whoops.

05:28.810 --> 05:34.850
So this is a link to how you can install Docker if you don't already have it installed.

05:34.850 --> 05:40.370
And this is just literally and this is the Docker desktop web page for you.

05:40.570 --> 05:45.890
And as it does claim, it is a one click install for Mac or Windows or Linux.

05:45.890 --> 05:47.810
And it should be as simple as that.

05:47.970 --> 05:52.130
Many of you, I suspect from an engineering background, already know and love Docker.

05:52.170 --> 05:54.530
If you don't, then welcome to it.

05:54.530 --> 06:00.570
This should be as simple as installing it and then it's installed and you can then leave it be, but

06:00.570 --> 06:06.080
you will need to have it installed for this to work properly in a Docker setting.

06:06.320 --> 06:06.920
Okay.

06:07.120 --> 06:09.000
So now we are going to create our agent.

06:09.000 --> 06:12.840
We start with an agent decorator to make sure it goes in the right place.

06:13.040 --> 06:15.120
And we are going to create a coder.

06:15.320 --> 06:20.520
I'm going to ignore the fact that cursor is already probably several steps ahead of me, rendering my

06:20.520 --> 06:26.280
job here useless, but we'll keep going anyway, I'm going to return an agent.

06:26.280 --> 06:27.760
This is the usual fare.

06:28.120 --> 06:29.520
So what is our agent going to do?

06:29.520 --> 06:31.760
Well, the I will press tab there.

06:31.800 --> 06:36.320
The config is going to be the uh config that we set in the YAML file.

06:36.680 --> 06:39.440
But then we'll have verbose being true as usual.

06:40.160 --> 06:41.400
Now what else do we want.

06:41.480 --> 06:48.120
We now want this super complex, super hard step of making sure that this agent has the power to run

06:48.160 --> 06:53.720
to, to, to execute code, which is as simple as allow code.

06:54.160 --> 06:54.440
Oops.

06:54.480 --> 06:57.000
Allow code execution equals true.

06:57.040 --> 06:57.920
There it is.

06:58.160 --> 06:59.680
Now it can execute code.

07:00.000 --> 07:11.420
There's this step of saying code execution Execution mode is safe, and now that ensures that it runs

07:11.420 --> 07:16.940
it within a Docker container so that it's not just running the code on your platform.

07:17.380 --> 07:19.580
Now we can say Max execution time.

07:19.580 --> 07:21.140
This is a good one to have in there.

07:21.140 --> 07:23.380
And we're going to say 30 30s.

07:23.420 --> 07:25.260
This is going to be a simple task.

07:25.620 --> 07:29.500
And max retry limit.

07:29.620 --> 07:31.700
It's funny that cursor prompted me wrong there.

07:31.740 --> 07:33.380
Let's give it five retries.

07:33.420 --> 07:36.380
It can have up to five times of trying this.

07:36.700 --> 07:39.460
And that is our coder agent.

07:39.700 --> 07:41.580
So now we have a task.

07:42.100 --> 07:46.180
And the task is going to be a coding task.

07:46.460 --> 07:52.620
And I rather suspect that, uh, we, uh, can just use what cursor does, but we can take out expected

07:52.620 --> 07:56.860
output because we already defined the expected output in the task itself.

07:56.860 --> 07:58.060
So it's not needed again.

07:58.180 --> 07:58.540
All right.

07:58.540 --> 07:59.060
So there we go.

07:59.100 --> 08:01.980
We have our agent and our task defined.

08:02.060 --> 08:06.220
Now we just have to do the crew function method just below.
