WEBVTT

00:00.160 --> 00:00.600
Okay.

00:00.640 --> 00:03.320
So now we're going to work on another agent.

00:03.320 --> 00:07.840
And we're going to make heavier use of structured outputs than we did last time.

00:08.080 --> 00:12.080
So the agent in particular that we're going to work on, we're going to call the planner agent.

00:12.320 --> 00:19.640
This is the one that's going to be responsible for taking a query and coming up with a handful of searches

00:19.640 --> 00:24.440
that it should run based on that query in order to do some deep research.

00:24.720 --> 00:31.320
Now, I'm going to keep the number of searches small to three searches because as I say, it's two and

00:31.320 --> 00:32.800
a half cents for each search.

00:32.840 --> 00:35.200
And I don't want to add up to some big old bill.

00:35.200 --> 00:37.400
When I first did this, I had that at ten.

00:37.400 --> 00:39.560
So you certainly can have it at bigger numbers.

00:39.560 --> 00:44.280
You obviously get better results if you do that, and it's very much a personal preference thing.

00:44.320 --> 00:46.000
Run it with three to start with.

00:46.040 --> 00:48.080
See you know your cost $0.10, $0.20.

00:48.080 --> 00:54.040
And if you're enjoying yourself then you know splash out, spend half a dollar and get one really good

00:54.040 --> 00:55.760
comprehensive result.

00:56.440 --> 00:57.040
Okay.

00:57.360 --> 00:59.400
So we're going to keep it on three.

00:59.560 --> 01:03.110
So the instructions what is the system prompt we're going to use here?

01:03.350 --> 01:05.670
You are a helpful research assistant.

01:05.670 --> 01:13.310
Given a query, come up with a set of web searches to perform to best answer that query output.

01:13.510 --> 01:17.070
And then the number three terms to query for.

01:18.030 --> 01:20.150
So that hopefully is super simple.

01:20.150 --> 01:26.470
We're just building an agent that is going to, given some sort of a query, come up with a bunch of

01:26.470 --> 01:31.190
things you would search the internet for in order to research that query, and we're calling that the

01:31.190 --> 01:31.870
planner.

01:32.110 --> 01:36.150
So keep that in mind because then everything is going to click into place.

01:36.670 --> 01:38.150
So now we use structured outputs.

01:38.190 --> 01:38.870
Remember this.

01:38.870 --> 01:45.310
This is where you have a class that is a subclass of this thing called base model from pedantic.

01:45.470 --> 01:47.870
And that means that we're going to use it as like a schema.

01:47.910 --> 01:54.470
We're going to use it to describe a structure, which we will later ask a model to return information

01:54.470 --> 01:54.750
in.

01:55.350 --> 02:01.930
And we in the case of a web search item, we're going to have a reason and a query.

02:02.850 --> 02:09.010
And the reason is a string, and the query is a string, and the doc string that we have right here

02:09.010 --> 02:12.730
underneath this is this is super important.

02:12.850 --> 02:20.850
And by by adding this documentation, by annotating these fields with this comment right underneath

02:20.850 --> 02:26.850
them, we ensure that that that information is actually provided as part of structured outputs.

02:26.850 --> 02:29.530
That is part of the information that's provided to the model.

02:29.530 --> 02:32.930
So it knows why it's populating these fields.

02:33.050 --> 02:34.530
So this is another good trick.

02:34.530 --> 02:35.530
We didn't do that yesterday.

02:35.530 --> 02:39.570
So so now you've you've got this in your toolkit as well.

02:40.330 --> 02:42.250
Now one other small point.

02:42.970 --> 02:47.690
There's various reasons why you might ask for a reason as well as just the query.

02:47.690 --> 02:54.930
But one of them is that this does actually result in sort of reasoning style behavior.

02:55.170 --> 02:58.170
This is very similar to to what people call chain of thought prompting.

02:58.170 --> 03:05.280
I guess it is chain of thought teleprompter, but by asking the model to output its rationale for why

03:05.280 --> 03:11.640
that search is important, and actually by asking for that first before the query itself, you encourage

03:11.640 --> 03:18.400
the model to be sort of apparently thinking through, and as a result, you tend to get better outputs,

03:18.400 --> 03:23.880
you get better queries, just as a side effect of asking for a rationale first.

03:24.320 --> 03:30.080
And I've said it before, but you always have to come back to remembering that while we try and treat

03:30.080 --> 03:36.760
models like they're like there's a bit of humanity to them, this is just a strange side effect of great

03:36.800 --> 03:41.320
next token prediction, because it's predicting the most likely next tokens.

03:41.320 --> 03:43.000
That's all these models are doing.

03:43.600 --> 03:48.840
If you ask it to start predicting tokens reflecting a reason, then when it starts to predict tokens

03:48.840 --> 03:55.600
reflecting the query, it is more likely to be consistent with that reason, and it ends up with this

03:55.600 --> 03:59.190
very coherent output that just makes more sense.

03:59.190 --> 04:02.590
That has a higher likelihood of being what you're after.

04:02.870 --> 04:05.270
So another those little sidebars.

04:05.310 --> 04:08.830
And I do have a bunch of YouTube videos that clarify that more.

04:08.830 --> 04:13.790
But it's so important to keep that in your mind because it really helps figure out what works well with

04:13.790 --> 04:15.030
these kinds of prompts.

04:15.230 --> 04:15.910
All right.

04:16.110 --> 04:20.710
So this is a pedantic object with a reason and a query.

04:21.150 --> 04:26.070
And now we've got another one called Web Search plan.

04:26.110 --> 04:28.110
So this was web search item.

04:28.390 --> 04:34.350
A web search plan is a list of web search items in a field searches.

04:34.670 --> 04:38.070
So this is an object which has one field searches.

04:38.070 --> 04:40.470
And that is a list of these guys.

04:40.470 --> 04:47.350
And you can see it says they're a list of web searches to perform to best answer the query, a list

04:47.350 --> 04:50.110
of web searches to perform to best answer the query.

04:50.230 --> 04:51.630
And that is what goes there.

04:51.630 --> 04:55.390
And this annotation is associated with this field searches.

04:56.110 --> 04:56.710
Okay.

04:56.750 --> 05:03.050
Hopefully you are with me So then we now create our planner agent.

05:03.170 --> 05:05.450
It is an agent that's named planner agent.

05:05.570 --> 05:07.810
Its instructions are these ones right here.

05:08.010 --> 05:11.570
The model is GPT four mini and the output type.

05:11.610 --> 05:14.890
Remember this is where we specify structured outputs.

05:14.930 --> 05:20.250
We tell the planner agent that it shouldn't output in text like these things normally do.

05:20.250 --> 05:26.490
It shouldn't just create generate natural language in the form of text, but rather it should build

05:26.490 --> 05:33.450
an object of type web search plan, which means it's an object with one field searches, which has a

05:33.490 --> 05:36.090
list of items that looks like this.

05:36.850 --> 05:41.290
And remember, as another sidebar, keep in the back of your mind when I say that we're going to tell

05:41.290 --> 05:43.290
the model to create an object.

05:43.330 --> 05:44.930
Maybe that all sounds a bit magical.

05:44.970 --> 05:50.730
Like how does a model, how does a large language model, a transformer architecture, know to generate

05:50.890 --> 05:51.450
objects?

05:51.450 --> 05:52.690
Python objects.

05:52.730 --> 05:58.520
Remember, any time you hear magical stuff like that, it usually means we're talking about JSON behind

05:58.520 --> 05:59.080
the scenes.

05:59.080 --> 06:00.800
And that's exactly what this is.

06:00.800 --> 06:06.160
What happens is that this is turned into a bunch of JSON, and the model is prompted and it says your

06:06.160 --> 06:09.120
response should conform to this JSON.

06:09.160 --> 06:10.640
Here is how it needs to look.

06:10.680 --> 06:17.120
And as a result, the model generates that JSON and it gets populated into an object of this type.

06:17.360 --> 06:18.480
That's that's the end of it.

06:18.480 --> 06:20.200
There's nothing magical about it.

06:20.920 --> 06:21.640
All right.

06:21.880 --> 06:24.000
We should now run this and see it working.

06:24.560 --> 06:25.080
Here we go.

06:25.120 --> 06:25.960
Let's do it.

06:26.000 --> 06:29.880
We run this, and now we're going to say the same.

06:29.880 --> 06:34.960
The same thing that before we just did an internet search on latest AI frameworks in 2025, what we're

06:34.960 --> 06:36.240
now going to do is carry out.

06:36.240 --> 06:37.440
We're not going to do any searching at all.

06:37.440 --> 06:43.880
We're just going to use this planner agent to come up with three web searches that would be relevant,

06:43.880 --> 06:48.080
and we would want it to respond with an object of type web search plan.

06:48.120 --> 06:51.200
So let's see what we get if we run it and print the result.

06:52.440 --> 06:58.260
So what we get back is an object which has a field searches Like that.

06:58.580 --> 07:00.620
And that field is a list.

07:00.660 --> 07:01.260
Good.

07:01.500 --> 07:04.660
And it's a list of things called web search items.

07:04.860 --> 07:05.580
Great.

07:05.740 --> 07:11.940
And a web search item should have a reason and a query reason to find the most recent developments and

07:11.940 --> 07:14.820
releases in AI agent frameworks for 2025.

07:14.940 --> 07:18.300
And the query is just latest AI agent frameworks 2025.

07:18.460 --> 07:19.660
Okay, fine.

07:19.940 --> 07:23.180
That doesn't seem particularly profound, but it seems perfectly reasonable.

07:23.580 --> 07:27.620
The next one to explore industry specific or academic research.

07:27.780 --> 07:31.100
And the query is emerging AI agent frameworks.

07:31.220 --> 07:36.220
And the next one is to be updated with major conferences, publications or announcements.

07:37.020 --> 07:38.060
AI frameworks.

07:38.060 --> 07:38.620
Conferences.

07:38.620 --> 07:40.220
Announcements 2025.

07:40.260 --> 07:41.020
Fair enough.

07:41.380 --> 07:44.420
Seems like a perfectly plausible, reasonable way of doing it.

07:44.460 --> 07:46.260
I'm not sure I would have done that last one, but.

07:46.260 --> 07:52.020
But who's to say whether I would have done it better or GPT four or mini is going to do it better.

07:52.020 --> 07:57.660
But that is the planner at work and you're seeing structured outputs used very well there.
