WEBVTT

00:00.160 --> 00:02.320
Well, I'm extremely excited about today.

00:02.320 --> 00:09.160
This is of course, day four of week two, and we're getting on to our first large, juicy project in

00:09.160 --> 00:11.760
the form of deep research.

00:11.880 --> 00:18.560
This is one of the classic use cases of Agentic AI, the case where you have an agent that is able to

00:18.600 --> 00:24.800
go off, search the internet and do some research, look at different links and try and research a topic

00:24.800 --> 00:25.720
that you give it.

00:25.720 --> 00:33.280
And we know this so well because many of the Frontier Labs offer this agent via their online chat tools.

00:33.280 --> 00:38.560
And for example, on OpenAI, you can go to GPT and you can press the deep research button.

00:38.560 --> 00:44.320
And that runs a model in deep research mode, which is basically running an agentic workflow.

00:44.520 --> 00:45.880
So we are going to do that.

00:45.920 --> 00:51.480
We are going to give our agents the ability to do deep research, and we're going to use a few things

00:51.480 --> 00:52.440
that we've already learned about.

00:52.440 --> 00:53.360
We're going to use tools.

00:53.360 --> 00:55.760
Of course we're going to use structured outputs again.

00:55.800 --> 00:58.880
We encountered it briefly last time a little bit more this time.

00:59.080 --> 01:04.340
And we're going to use something called hosted tools for the first time, using tools that are running

01:04.340 --> 01:05.220
remotely.

01:05.500 --> 01:07.620
All right, let's get straight to it.

01:08.100 --> 01:09.660
Okay, so here we are in Quito.

01:09.700 --> 01:12.820
We're going to open up the directory for week two.

01:12.860 --> 01:17.300
And we're now going to lab for deep research.

01:17.580 --> 01:24.420
And we are going to start again in a notebook like this in one of the notebooks running within cursor.

01:24.660 --> 01:28.820
And I know that a lot of you would prefer to be working with real Python modules.

01:28.820 --> 01:29.860
And fear not.

01:29.900 --> 01:31.220
We will get to that tomorrow.

01:31.260 --> 01:35.300
We will do this in Python code and proper modules.

01:35.540 --> 01:41.420
The lab, this kind of format, these notebooks, they're so good for talking through things for experimenting.

01:41.420 --> 01:46.060
And it gives you the power to be changing things, playing around while we go through this.

01:46.060 --> 01:47.860
So I think it's good just for today.

01:48.340 --> 01:53.340
So this is of course a enormous classic agentic use case.

01:53.340 --> 01:59.160
And what's great about it is it applies so broadly you can apply this to any business area.

01:59.200 --> 02:05.440
You can build a deep research agent that's focused on your business area, or you can use this as something

02:05.440 --> 02:07.400
which is like a sidekick for yourself.

02:07.440 --> 02:09.600
We're going to build a different kind of sidekick later in this course.

02:09.600 --> 02:13.800
But but this is one kind already and it should be useful for you immediately.

02:13.920 --> 02:19.320
So I think it's terrific that we're doing this, and I hope you're as excited as me to be building your

02:19.320 --> 02:23.720
own deep research agent, something which the Frontier Labs have done themselves.

02:23.960 --> 02:26.040
Okay, so let's get started.

02:26.080 --> 02:27.600
Enough of my prattling away.

02:27.600 --> 02:29.040
We do some imports.

02:29.040 --> 02:31.800
We do one of these usual load dot envs.

02:32.160 --> 02:32.800
All right.

02:32.800 --> 02:38.280
And now it's time for me to talk about the big the big change this week, which is that we are going

02:38.280 --> 02:44.520
to use some things called hosted tools, which means that they are tools that OpenAI is going to run

02:44.520 --> 02:45.360
for us.

02:45.400 --> 02:49.640
There only are three of them that OpenAI provides, at least as of now, and we're going to use one

02:49.640 --> 02:50.120
of them.

02:50.120 --> 02:54.200
The three are the web search tool, the file search tool, and the computer tool.

02:54.440 --> 03:01.220
The web search tool All lets us do what we're going to do today, which is ask OpenAI to run a search

03:01.260 --> 03:02.220
on our behalf.

03:02.740 --> 03:09.380
The file search tool is how we can run searches across the vector stores that you can run.

03:09.420 --> 03:16.020
You can upload and have remotely with OpenAI and computer tool allows things like taking screenshots

03:16.020 --> 03:17.660
and clicking around a computer.

03:17.700 --> 03:19.180
Now we're not going to be using either of those two.

03:19.180 --> 03:20.580
We're going to be doing the web search tool.

03:20.580 --> 03:25.260
But fear not, later in the course we will have basically our own computer tool, but we won't be running

03:25.260 --> 03:25.860
it at hosted.

03:25.860 --> 03:28.900
We'll be running it on our own computers, as you will see.

03:28.940 --> 03:32.780
In case that sounds intriguing, but for now we're going to be using the web search tool.

03:32.780 --> 03:38.780
And I want to make an important point, which is that OpenAI's web search tool is not that cheap for

03:38.780 --> 03:41.580
some reason, which seems not entirely clear to me.

03:41.580 --> 03:50.540
It actually costs 2.5 cents right now for me to run this for, even at the low end of the cheapest model

03:50.540 --> 03:56.040
at the lowest end, 2.5 cents per call, which may not sound like it's a huge amount, But typically

03:56.040 --> 03:59.440
if we're running a deep research, we might be doing like ten different searches.

03:59.440 --> 04:05.520
And that means it's $0.25 a pop, which means that you can quite quickly add up to 2 to $3, which is

04:05.520 --> 04:07.160
what I spent the first time I did this.

04:07.160 --> 04:09.560
I think the way I have it set up now would be more like $1.

04:09.760 --> 04:11.920
Still, that's maybe not to be sniffed at.

04:11.920 --> 04:17.520
So I would suggest monitor this and you can decide to skip doing the searches, or I'll show you where

04:17.520 --> 04:20.840
you can turn it all the way down so that you're only spending a few cents.

04:21.000 --> 04:24.400
And then later in future weeks, we're going to be doing this a bit differently.

04:24.400 --> 04:27.560
And we'll have other ways to do this which will cost a fraction of this.

04:27.560 --> 04:27.880
So.

04:27.880 --> 04:28.640
So fear not.

04:28.640 --> 04:30.800
But for now, it's nice for us to use OpenAI's.

04:30.800 --> 04:32.560
And OpenAI's is actually really good.

04:32.600 --> 04:32.960
So.

04:32.960 --> 04:35.280
So maybe maybe it's worth a 2.5 cents.

04:35.280 --> 04:36.000
I don't know.

04:36.560 --> 04:38.920
The costs themselves are on this link here.

04:38.920 --> 04:39.320
So.

04:39.320 --> 04:43.960
So it's always worth double checking because it might be different for your region, or OpenAI might

04:43.960 --> 04:45.200
change the pricing all the time.

04:45.240 --> 04:51.960
So go there and you can look we are going to be using GPT four mini low search okay.

04:52.200 --> 04:55.580
With that, let's get started with our first search.

04:56.180 --> 04:56.620
Okay.

04:56.660 --> 05:00.220
It's now time for us to create our first agent for this product.

05:00.220 --> 05:04.460
And the first agent is called the search agent.

05:04.700 --> 05:06.300
So here are the instructions.

05:06.300 --> 05:07.940
The system prompt for this agent.

05:08.220 --> 05:09.780
You are a research assistant.

05:09.820 --> 05:13.060
Given a search term, you search the web for that term.

05:13.060 --> 05:20.060
You produce a concise summary 2 to 3 paragraphs, capture the main points, write succinctly, and no

05:20.060 --> 05:23.260
need to have good grammar because it will be consumed by someone else.

05:23.340 --> 05:24.980
Synthesizing a report.

05:25.340 --> 05:30.740
It's a very clearly written set of instructions right here, and I would love to take credit for it.

05:30.740 --> 05:37.140
But I must confess that I just took this verbatim from OpenAI's documentation for how to do web searches

05:37.140 --> 05:42.940
with that tool, so we can probably take it on good authority that this is a well written prompt, since

05:42.940 --> 05:45.060
it's written by the people that built the model.

05:45.300 --> 05:47.140
So, um, we're going to use this prompt.

05:47.140 --> 05:49.260
We're going to create a search agent.

05:49.260 --> 05:51.460
It is an agent named search agent.

05:51.700 --> 05:53.680
This is the the instructions.

05:53.840 --> 05:55.600
And we're going to give it one tool.

05:55.600 --> 05:58.080
And that tool is called a web search tool.

05:58.080 --> 06:02.160
And this is one of OpenAI's three hosted tools.

06:02.160 --> 06:04.480
So we're we're providing that as our tool.

06:04.760 --> 06:06.520
There is an optional parameter.

06:06.520 --> 06:12.680
You can specify the search context size which can be low, medium or high where that reflects the price

06:12.680 --> 06:13.440
that you'll pay.

06:13.480 --> 06:16.280
Low is of course the cheapest and then medium is.

06:16.280 --> 06:19.160
The default is only a little bit more, but high I think is quite a lot more.

06:19.440 --> 06:21.040
You can also pick the model.

06:21.040 --> 06:24.160
It's a lot cheaper to pick GPT four or mini GPT four.

06:24.200 --> 06:25.200
Zero is a lot more.

06:25.360 --> 06:28.440
And um, finally there's there's this here.

06:28.440 --> 06:32.240
This is a nice little snippet of code to to to keep in mind.

06:32.280 --> 06:37.080
This is how you say that this agent is required to run the tool.

06:37.080 --> 06:38.280
It is mandatory.

06:38.320 --> 06:40.280
It doesn't have discretion over this.

06:40.280 --> 06:41.560
So this is this is the way you do it.

06:41.560 --> 06:45.120
You pass in this model settings with tool choices required.

06:45.120 --> 06:47.120
And that's a nice handy thing to have to one side.

06:47.120 --> 06:48.960
And of course in this case we want to do that.

06:48.960 --> 06:49.760
We want to.

06:49.800 --> 06:53.540
It's basically this agent is wrapping this tool call.

06:53.900 --> 06:59.580
And so when we're picking GPT for our mini and we're picking low, this is when as of now this costs

06:59.580 --> 07:03.580
two and a half cents every time we run this agent.

07:04.100 --> 07:05.620
So let's run this agent.

07:05.620 --> 07:10.940
Let's ask for the latest AI agent frameworks in 2025.

07:10.980 --> 07:17.060
We will run that search and we will display the results and see what happens.

07:17.540 --> 07:19.940
It's running and there we go.

07:19.980 --> 07:20.940
There are the results.

07:20.940 --> 07:23.060
It's come in nice markdown.

07:23.100 --> 07:30.060
Let's see it says Lang lang graph crew semantic kernel autogen OpenAI gym.

07:30.060 --> 07:34.940
That's uh, not exactly I guess that's a that's a reinforcement learning framework.

07:35.180 --> 07:36.260
It doesn't know about itself.

07:36.260 --> 07:38.420
It doesn't know about OpenAI agents SDK.

07:38.460 --> 07:45.820
Amusingly, uh, Rasa is an older framework and Jade for Java people and, uh, yeah.

07:45.820 --> 07:50.360
So, so, uh, an interesting set of results, I'd say mixed accuracy because I would.

07:50.360 --> 07:56.960
I would argue that long chain and semantic kernel aren't really agent frameworks, but certainly Landgraf,

07:57.000 --> 08:03.520
crew, and Autogen are very much there, and ones that we will be spending a week on each.

08:03.880 --> 08:04.400
All right.

08:04.400 --> 08:11.000
But this is a perfectly pleasant search result, and it is the beginning of our deep research agent,

08:11.560 --> 08:15.520
and it's always worth taking a quick look at the trace in OpenAI.

08:15.920 --> 08:18.320
So click on this little useful link here.

08:18.640 --> 08:20.240
And up it comes.

08:20.440 --> 08:21.200
And here it is.

08:21.200 --> 08:24.840
The search agent is our current trace.

08:24.840 --> 08:26.440
If I open it up we'll see.

08:26.480 --> 08:29.120
Sure enough that the search agent was called.

08:29.120 --> 08:33.320
And it tells us over here the tool it used was web search.

08:33.520 --> 08:37.400
And we get a bit of information about the total number of tokens that it did.

08:37.400 --> 08:39.560
That's the instructions, the system prompt.

08:39.560 --> 08:40.960
That was the user prompt.

08:40.960 --> 08:43.120
And this comes back is the output.

08:43.120 --> 08:46.960
Just as we would expect the trace has worked nicely.

08:47.120 --> 08:49.240
Now we can get on with the show.
