WEBVTT

00:00.360 --> 00:01.840
And now it gets juicy.

00:01.880 --> 00:07.200
Now we're going to go to Crewe and we're going to start building a bunch of different things.

00:07.800 --> 00:11.520
So the first thing is that I want us to use structured outputs.

00:11.520 --> 00:17.520
In other words, we are going to ask our different tasks to be providing information according to a

00:17.520 --> 00:23.160
particular JSON schema as a way of making sure we're getting the information that we want from these

00:23.160 --> 00:26.560
agents in a robust sort of way that is kind of on rails.

00:26.840 --> 00:32.960
And so, as you probably remember, the way to do that is to create classes that are subclasses of base

00:32.960 --> 00:36.760
model and use this as a way of describing what we want.

00:36.840 --> 00:38.080
So let me give you an example.

00:38.080 --> 00:41.120
Let's make a class that's called trending company.

00:41.480 --> 00:43.800
And so this is a subclass of base model.

00:43.800 --> 00:45.120
We give it an explanation.

00:45.120 --> 00:47.760
It's a company in the news attracting attention.

00:48.000 --> 00:51.120
And then we set up name ticker and reason.

00:51.120 --> 00:53.240
And we give them descriptions like this.

00:53.480 --> 00:58.560
And you can see this is a way of, of laying out the information that we're going to want to be gathering.

00:58.560 --> 01:04.280
And it helps guide the agents and the tasks to, to to produce information that we want.

01:04.800 --> 01:07.120
And now I'm going to make a second class.

01:07.120 --> 01:09.880
That is basically just a list of these.

01:09.880 --> 01:11.960
So it's called trading company list.

01:11.960 --> 01:17.120
And it contains a single field companies which is a list of these objects.

01:17.160 --> 01:23.680
It's a way to organize it so that one task can result in a bunch of trading companies.

01:24.800 --> 01:25.640
So far so good.

01:25.800 --> 01:29.440
We're going to do pretty much the same thing again for our research.

01:29.560 --> 01:33.720
So we're going to have a trending company research schema.

01:33.920 --> 01:34.760
Here it is.

01:34.960 --> 01:39.720
So again it's a it's a pedantic class a class that is a subclass of base model.

01:39.920 --> 01:42.000
And it's detailed research on a company.

01:42.000 --> 01:46.800
It has a name, market position, future outlook and investment potential.

01:47.160 --> 01:53.040
And by giving the fields with that name and with that description, we are going to force the agent

01:53.040 --> 01:55.560
to produce that information in its response.

01:55.600 --> 02:01.040
And so it's a really clever way of making sure that we guide the agent's behavior.

02:01.680 --> 02:09.840
And similarly we're going to add a list trending company research list, a detailed list of of all of

02:09.840 --> 02:15.250
the research on the companies, and it's a list of trending company research objects of these objects

02:15.250 --> 02:16.490
with these descriptions.

02:17.170 --> 02:23.050
And again, I find it helpful to be mindful that you use consistent, clear terminology.

02:23.210 --> 02:23.930
I used to have.

02:23.970 --> 02:28.850
I used to my first version of this, I called these newsworthy companies, and I was just introducing

02:28.850 --> 02:32.610
concepts that weren't crystal clear in terms of what I was going for.

02:32.650 --> 02:40.050
And and this has helped make it more reliable using simple and and common terms and using them consistently.

02:40.570 --> 02:44.530
Okay, now it's time to define our crew, our class stock picker.

02:44.770 --> 02:48.570
And as usual we look at the YAML files.

02:48.570 --> 02:49.290
We bring them in here.

02:49.290 --> 02:54.610
And I've deleted the rest of the gunk that it auto generates so that we can build this ourselves from

02:54.610 --> 02:55.250
scratch.

02:55.490 --> 03:03.450
And we're going to start by creating our trending company finder agent, which I'll do like this.

03:03.770 --> 03:08.610
And we need to give it of course the decorator agent like that.

03:08.610 --> 03:10.890
So this is a trending company finder.

03:11.050 --> 03:18.450
It's going to return an agent configured with the config and we're going to use a tool which will be

03:18.450 --> 03:19.930
let me tidy this up for you.

03:20.250 --> 03:20.770
There we go.

03:20.810 --> 03:26.810
It's going to use the super dev tool as before so that it can look for trending companies on the internet.

03:27.250 --> 03:28.810
That seems pretty good.

03:28.850 --> 03:30.770
All right, let's make our second agent.

03:31.210 --> 03:35.930
And this second agent is going to be our financial researcher agent.

03:36.250 --> 03:40.490
And so let's see we're going to want to again use Sirpa.

03:41.050 --> 03:50.050
So we're going to have it look at the config again for the financial researcher and the tools we.

03:50.130 --> 03:51.330
I was wondering what was going on there.

03:51.330 --> 03:58.050
I was missing the deaf deaf financial researcher like so that's going to have an agent.

03:58.690 --> 04:01.130
And there we go.

04:01.170 --> 04:02.490
Now it should work fine.

04:02.890 --> 04:03.370
All right.

04:03.370 --> 04:04.410
That seems good.

04:04.410 --> 04:10.810
And it has suggested cursor has kindly suggested that we do this, which seems good to me, except we

04:10.850 --> 04:12.610
don't really need this.

04:12.610 --> 04:19.850
We don't need to have the Sirpa dev tool in there, because the stock picker has been given all of its

04:20.020 --> 04:22.860
information, it's not going to need that at all.

04:23.340 --> 04:24.260
All right.

04:24.460 --> 04:27.860
So that is the definition of our three agents.

04:28.020 --> 04:30.260
Let's go on to defining our tasks.

04:30.900 --> 04:31.420
Okay.

04:31.460 --> 04:34.060
So it's time to define the first of our tasks.

04:34.060 --> 04:38.940
And the first task is the task to find trending companies using the trending company finder.

04:39.100 --> 04:40.100
And here it is.

04:40.300 --> 04:43.220
Find trending companies is creating a task.

04:43.540 --> 04:44.860
This is the config.

04:45.060 --> 04:48.660
And we also have this field output pedantic.

04:48.980 --> 04:56.700
And that is telling it that this task needs to output some JSON in the schema that conforms to trending

04:56.700 --> 04:57.820
company list.

04:57.820 --> 05:00.580
And that of course is this object right here.

05:00.700 --> 05:06.620
So we are constraining it to make sure that it produces something in that format, which is exactly

05:06.620 --> 05:07.420
what we want.

05:07.460 --> 05:11.180
And so this is the way that you do structured outputs in crew.

05:11.700 --> 05:15.260
And now the research trending companies task.

05:15.420 --> 05:18.420
This is going to again be hooked up to the right config.

05:18.580 --> 05:22.020
And this of course is going to create the trending company's research list.

05:22.060 --> 05:23.260
Pedantic object.

05:23.580 --> 05:24.980
So here we go.

05:25.020 --> 05:28.020
If we look back up, this is, of course, this object right here.

05:28.060 --> 05:31.260
A list of research results.

05:31.380 --> 05:38.660
So we are saying this task to research is going to be forced to produce information that conforms to

05:38.700 --> 05:39.660
that schema.

05:39.780 --> 05:42.300
And that way we know we're going to get research.

05:43.220 --> 05:47.060
Hopefully you're following along with this.

05:47.100 --> 05:50.380
If not then do look at the code and try this out for yourself.

05:50.500 --> 05:51.700
We're almost done.

05:51.700 --> 05:58.100
We're just going to add in the best company picker, which is right here, and which is going to select

05:58.100 --> 05:59.420
the best company.

05:59.620 --> 06:02.660
And that's an easy one, an easy one to end with.

06:02.700 --> 06:05.540
And now we've got left to do is actually create our crew.

06:06.180 --> 06:06.580
All right.

06:06.620 --> 06:07.660
Time to create the crew.

06:07.900 --> 06:09.220
We've made the agents.

06:09.220 --> 06:10.580
We've made the tasks.

06:10.780 --> 06:12.140
Here is the crew.

06:12.580 --> 06:16.060
You may be thinking to yourself, we only created three agents.

06:16.060 --> 06:17.420
Did we have a fourth agent?

06:17.460 --> 06:20.340
Yes, we did, but that fourth agent is a bit different.

06:20.340 --> 06:25.380
It's the manager, and we don't want that to be in the list of the of the, the general agents that

06:25.380 --> 06:27.300
are going to be working on the task at hand.

06:27.340 --> 06:30.630
We're going to want to create this separately and handle it separately.

06:30.630 --> 06:37.710
So we create our manager agent like this just as a, as a as a separate variable manager, an agent

06:37.710 --> 06:41.190
that has the config from that's called manager.

06:41.190 --> 06:44.990
And we also use this field allow delegation equals true.

06:45.230 --> 06:50.230
That is telling crew that we want it to be able to delegate to other agents.

06:50.350 --> 06:54.870
That would be the equivalent of the handoff in the OpenAI agents SDK.

06:55.550 --> 06:55.910
All right.

06:55.950 --> 07:02.670
And so now it just remains for us to actually return our crew from this function here from Def Crew.

07:02.670 --> 07:04.190
And we're going to do it like this.

07:04.670 --> 07:05.950
Return crew.

07:06.070 --> 07:08.270
The agents is self dot agents.

07:08.270 --> 07:11.270
And that is a three agents with the decorators above.

07:11.310 --> 07:13.990
Those are the agents that form this team, this crew.

07:14.190 --> 07:16.710
The tasks are the tasks that we defined.

07:16.750 --> 07:22.030
We're now saying the process is process hierarchical not process sequential.

07:22.030 --> 07:28.590
And that means that we are going to assign an LM to figure out which agent does what task.

07:28.950 --> 07:29.830
Verbose is true.

07:29.830 --> 07:32.350
And this is where we specify the agent.

07:32.350 --> 07:34.510
It's the agent we created right here.

07:34.510 --> 07:36.910
We could just just create that agent right there in the code.

07:36.910 --> 07:41.030
But it's a bit neater to do it this way and that is the end of it.

07:41.390 --> 07:43.310
Now there is actually an alternative here.

07:43.310 --> 07:46.430
You don't need to create a separate manager agent.

07:46.430 --> 07:52.670
You can actually say manager LM equals and just define an LM like GPT four or something.

07:52.750 --> 08:00.990
But um, I found it perform slightly better if I get the opportunity to describe the role of the manager.

08:00.990 --> 08:02.350
But both did work.

08:02.390 --> 08:04.270
But as you'll see, neither works perfectly.

08:04.390 --> 08:04.790
Haha.

08:04.830 --> 08:05.630
It's an adventure.

08:05.630 --> 08:13.150
As I say, it's a very interesting insight into some of the challenges of of autonomous AI, but still

08:13.150 --> 08:16.110
it works better if you define the manager separately.

08:16.150 --> 08:20.190
And one other point I'll make is that in defining that manager, I don't know if you spotted this,

08:20.190 --> 08:23.790
but I'm actually using GPT four, not GPT four mini.

08:23.790 --> 08:28.830
I'm using the bigger version, which means it's a slightly more pricey, so you can make that for a

08:28.830 --> 08:35.790
mini if you'd prefer, but I found that that helped it stay more coherent with the mission at hand.

08:36.110 --> 08:39.190
So anyway, that is defining the crew.
