WEBVTT

00:00.160 --> 00:00.720
Okay.

00:00.720 --> 00:05.240
And I will, uh, run the creating of the new servers and let's get on with it.

00:05.240 --> 00:09.240
So we're going to be creating two agents in this in this lab.

00:09.360 --> 00:12.320
One of them is called the researcher, and one of them is called the trader.

00:12.320 --> 00:16.840
And the researcher, of course, does market research on on the behest of the trader.

00:17.040 --> 00:19.320
And the trader makes trading decisions.

00:19.320 --> 00:24.320
And we're going to arm the researcher with tools to look online and both in the headless browser and

00:24.320 --> 00:26.520
by doing an actual search using brave.

00:26.960 --> 00:28.200
And now you might wonder why.

00:28.200 --> 00:34.000
Why not just simply give those two tools to the trader, just give all the tools to the trader, and

00:34.000 --> 00:38.800
let the trader do everything autonomously, and just have control of all of the different tools it uses.

00:38.840 --> 00:40.200
And you certainly can do that.

00:40.200 --> 00:46.320
And it might be worth experimenting with a benefit of separating out the researcher is it allows you

00:46.320 --> 00:52.880
to focus your prompting on one task to make sure that you don't distract the trader agent too much with

00:52.880 --> 00:59.960
too much optionality, almost so that there's some goal, some some tighter objective around research

00:59.960 --> 01:02.160
that we can set the researcher agent.

01:02.160 --> 01:04.440
And we also give it both of these tools.

01:04.480 --> 01:08.820
And if we were to give all of these tools to the trader agent, there's a risk that we confuse it by

01:08.820 --> 01:11.260
just giving it too many different tools that it could use.

01:11.380 --> 01:17.060
So this technique of trying to identify different steps, different stages, and then identifying an

01:17.060 --> 01:21.860
agent around it, it's a it's a great way to tackle a genetic projects.

01:22.140 --> 01:23.380
And it's experimental.

01:23.380 --> 01:25.140
There's no hard and fast rules.

01:25.140 --> 01:30.140
Sometimes it helps to give more flexibility to one agent with just a greater number of tools.

01:30.140 --> 01:35.900
Sometimes it helps to put boundaries around an activity and carve off an agent for that activity.

01:35.940 --> 01:37.420
And that's what we're doing right now.

01:38.220 --> 01:46.580
So the researcher agent we're saying the instructions for we're writing a coroutine get researcher instructions,

01:46.580 --> 01:48.020
which is the system prompt.

01:48.060 --> 01:49.620
You are a financial researcher.

01:49.620 --> 01:54.740
You're able to search the web for interesting news, look for possible trading opportunities and help

01:54.740 --> 01:56.940
with research based on a request.

01:56.940 --> 02:01.100
You carry out necessary research responding with your findings.

02:01.420 --> 02:08.500
Uh, and then, uh, we end by saying the current date time is and give the current date and time.

02:08.500 --> 02:15.130
It's just, again, a good a good tactic to arm the research agent with that information so that it

02:15.130 --> 02:16.290
doesn't think it's still.

02:16.330 --> 02:19.890
Its knowledge cut off date, which might be October of 2023 or something.

02:20.290 --> 02:24.650
So we're giving it the current date and that could be provided as a tool.

02:24.690 --> 02:29.850
But again, that would be a sort of needless distraction to confuse it by making it have to also call

02:29.850 --> 02:34.450
an extra tool, we might as well just shove that in the context every single time.

02:34.770 --> 02:41.530
And so with that, this will create an agent object an open AI agents SDK agent.

02:41.570 --> 02:42.970
The name is researcher.

02:43.010 --> 02:44.250
The instructions is.

02:44.250 --> 02:47.530
This system prompt will use GPT four mini for now.

02:47.530 --> 02:52.170
And we are passing in our MCP servers that get get brought in here.

02:52.170 --> 02:58.010
So we will pass them in to be the MCP servers for the researcher.

02:58.290 --> 02:59.770
And that I will run.

03:00.050 --> 03:08.090
And now I'm going to do this a get researcher tool, which is going to return the researcher converted

03:08.090 --> 03:14.850
into a tool using the as tool function that, uh, that OpenAI agents SDK gives us.

03:14.850 --> 03:15.890
Do you remember this?

03:15.890 --> 03:21.030
You remember that when you've got agents collaborating with the agents SDK, there's two ways of doing

03:21.030 --> 03:21.310
it.

03:21.350 --> 03:28.430
One is using handoffs, and the other is using as tool to convert an agent into a tool.

03:28.550 --> 03:32.230
And there are pros and cons and the different different use cases for using them.

03:32.510 --> 03:38.310
And the big distinction is that when it's a handoff the control is passed over to that other agent,

03:38.670 --> 03:44.070
and it's now delegated to the other agent to continue work and take it from there.

03:44.110 --> 03:46.950
When it's a tool, it's more of a request response.

03:47.310 --> 03:52.070
We will use that tool and the response will come back to the agent that initiated it.

03:52.110 --> 03:53.950
And that's the mode we're working on right now.

03:53.990 --> 04:00.310
We want the researcher to be something which is just only there for the purposes of helping the trader,

04:00.310 --> 04:03.950
and that's why it makes sense to convert the researcher to a tool.

04:04.230 --> 04:07.990
And you give it a tool name researcher and you describe the tool.

04:07.990 --> 04:11.430
This tool researches online for news and opportunities.

04:12.310 --> 04:15.310
Describe what kind of research you are looking for.

04:15.310 --> 04:17.950
So that would become the input to this tool.

04:18.590 --> 04:23.580
And if you need a refresher on that then just drop back to to week two when we had so much fun with

04:23.580 --> 04:25.820
both handoffs and tools.

04:25.860 --> 04:32.820
Okay, so in the past when we've used MCP servers, we've used something called a context manager,

04:32.820 --> 04:38.540
which is when you have stuff like, uh, you say um, uh, with.

04:41.140 --> 04:44.100
MCP studio Server, something like that.

04:44.100 --> 04:50.420
As server, when you use a context manager like that, what happens is that behind the scenes, the

04:50.460 --> 04:54.380
server, this server here is is called with connect.

04:54.420 --> 04:57.460
Server connect is called immediately when you do this.

04:57.500 --> 05:04.140
And then whenever it comes out of scope, uh, then automatically server cleanup is called which cleans

05:04.140 --> 05:07.140
up resources and stops connecting to the server.

05:07.420 --> 05:11.180
Uh, and uh, we are not going to do it that way.

05:11.180 --> 05:17.380
This time we're going to separately connect and later clean up, because we're going to want to distribute

05:17.380 --> 05:18.580
this over multiple cells.

05:18.580 --> 05:22.020
So we don't want to be constrained by having it in one context manager.

05:22.020 --> 05:23.340
But it's the same thing.

05:23.540 --> 05:31.160
So this here when we're going to say for all of the servers in our list of research servers await server

05:31.160 --> 05:32.320
dot connect.

05:32.440 --> 05:36.200
That's what happens automatically at the beginning of the with with statement.

05:37.200 --> 05:42.720
And then we are going to call our researcher passing in the research servers.

05:43.040 --> 05:51.240
And then we are going to call runner Dot saying what's the latest news on Amazon and then display the

05:51.240 --> 05:51.920
result.

05:51.920 --> 05:53.920
So this is us using this researcher.

05:53.920 --> 05:54.840
We're just going direct.

05:54.840 --> 05:56.080
We're not going through the tool.

05:56.080 --> 05:57.280
But it's the same idea.

05:57.280 --> 06:00.320
And we're asking for news on Amazon.

06:00.520 --> 06:02.160
Let's see how it does.

06:02.320 --> 06:03.440
It's thinking about that.

06:03.480 --> 06:05.240
It's no doubt showing some autonomy.

06:05.280 --> 06:11.200
Remember it has access to either run a headless browser or it can call the brave API.

06:11.640 --> 06:15.040
And it's got some news as of as of now.

06:15.040 --> 06:16.240
So it's got the current date.

06:16.240 --> 06:23.680
Well, the the bid to acquire TikTok, the spring sale success, new Prime Video content.

06:23.680 --> 06:29.000
So there's some some interesting stuff there that's coming from the news.

06:29.120 --> 06:31.880
So it shows that our research agent is working nicely.

06:31.880 --> 06:36.430
And again, it's the reason I like working in notebooks like this as we are iterating, because we're

06:36.430 --> 06:42.150
in this experimenters mindset where we try different things, explore different agents, make sure they're

06:42.150 --> 06:45.430
behaving the way we want before we move to a Python module.

06:45.430 --> 06:50.910
It's a great mode to work in as a scientist first and foremost before you become the engineer.

06:51.310 --> 06:56.550
But the other part of being a scientist is that we should come and look at the traits in, uh, in the

06:56.550 --> 06:57.310
platform.

06:57.510 --> 07:01.030
Openai.com going to traces to see what's happened.

07:01.030 --> 07:06.350
And there is a trace for researcher in we come and we can see what's going on here.

07:06.390 --> 07:09.390
It's, it's it's found out what MCP tools it has.

07:09.590 --> 07:11.510
It's then it's used the brave search.

07:11.550 --> 07:12.350
It's used it twice.

07:12.350 --> 07:13.950
It's done two different searches.

07:14.190 --> 07:18.430
Uh, latest news on Amazon and Amazon news April 2025.

07:18.430 --> 07:19.710
So a couple of different searches.

07:19.710 --> 07:20.310
It's done.

07:20.310 --> 07:21.710
It's got back the results.

07:21.710 --> 07:25.190
And it used that to craft its response that we already saw.

07:25.470 --> 07:27.470
Uh, so this is the trace.

07:27.470 --> 07:32.510
This is showing uh, what was what was going on that it was at work and, uh, yeah, that's that's

07:32.510 --> 07:33.830
all good to see.

07:34.230 --> 07:35.910
Um, okay.

07:36.670 --> 07:38.590
So back we go.
