WEBVTT

00:00.120 --> 00:02.920
And welcome to week two, day three.

00:02.960 --> 00:04.440
We have lots to cover today.

00:04.480 --> 00:09.440
Continuing our exploration of OpenAI agents SDK and with our SDR project.

00:09.760 --> 00:14.040
So I want to quickly take a moment to recap what we did last time.

00:14.240 --> 00:22.960
We looked at tools by just using that simple decorator as as a way to allow us to wrap a function into

00:22.960 --> 00:28.480
a tool and to be able to call that tool so easily without the boilerplate JSON that we'd needed to use

00:28.480 --> 00:29.400
in week one.

00:29.680 --> 00:33.680
We then looked at the way that agents can also be turned into tools.

00:33.680 --> 00:39.160
By using the as tool function, we can simply change an agent into being a tool.

00:39.400 --> 00:42.120
And that turned out to be very easy indeed.

00:42.360 --> 00:46.840
And then slightly confusingly, we saw that there is another way that agents can collaborate with each

00:46.880 --> 00:48.920
other, which is using handoffs.

00:48.920 --> 00:54.000
When you're creating a new agent, you can give it any number of tools and you can give it handoffs.

00:54.040 --> 00:58.640
And I explained that the key difference between them is that when you're using tools, you can think

00:58.640 --> 01:02.330
of that as a call to the other agent, which will then return back.

01:02.530 --> 01:06.490
But when you're doing handoffs, you can really think of that as a transfer of control.

01:06.610 --> 01:13.490
The next step on the workflow is giving over control to that agent that is on the receiving end of the

01:13.530 --> 01:14.090
handoff.

01:14.810 --> 01:18.930
We're now going to go and extend what we did last time in three different ways.

01:18.930 --> 01:22.450
Three things that will allow us just to learn a bit more about the framework.

01:22.490 --> 01:27.650
First of all, we're going to do what I promised we'd do and look at models other than OpenAI.

01:28.050 --> 01:34.450
So using the OpenAI agents SDK to drive things like Gemini and deep tech, we're also going to look

01:34.450 --> 01:36.370
at structured outputs.

01:36.410 --> 01:42.530
The way that we can require an agent not to respond just with text, but to populate some kind of an

01:42.530 --> 01:46.490
object where we can specify the fields that are going to get populated.

01:46.810 --> 01:52.890
And then we're going to look importantly at guardrails, which are an approach to making sure that we

01:52.890 --> 01:59.370
have some controls over the information that comes in to our agent setup and what comes out.

02:00.010 --> 02:00.690
All right.

02:00.930 --> 02:04.890
With that intro, let's go back to cursor, back to the lab.

02:05.330 --> 02:07.130
And here we are back in cursor.

02:07.130 --> 02:10.050
And we are looking at the second week.

02:10.050 --> 02:12.130
And we're looking at day three.

02:12.170 --> 02:14.330
Here we are lab three week two day three.

02:14.770 --> 02:18.890
And we're going to start by doing a sort of quick recap of what we did last time.

02:18.930 --> 02:20.690
We're going to do some imports.

02:20.690 --> 02:22.570
We're going to load the env.

02:22.770 --> 02:26.770
We're actually going to bring in a bunch more environment variables than usual.

02:26.810 --> 02:29.330
I'm looking at a bunch of different keys here.

02:29.370 --> 02:30.690
Google deep sea grok.

02:30.730 --> 02:31.970
Now you don't have to do this.

02:31.970 --> 02:34.930
You can just stick with OpenAI if you don't have these other keys.

02:34.930 --> 02:39.130
But if you'd like to experiment with others, then this is the way to do it.

02:39.170 --> 02:43.690
And of course, if you have other things, perhaps you use Open Router as your way to connect to different

02:43.690 --> 02:44.210
models.

02:44.210 --> 02:46.450
You can be using any of these here.

02:47.210 --> 02:47.770
All right.

02:47.810 --> 02:52.450
Now we have the three instructions for our three different sales agents.

02:52.450 --> 02:58.740
You'll remember one is more professional, one is more witty and engaging, and one is more concise.

02:58.940 --> 03:00.980
So income are three instructions.

03:01.380 --> 03:08.060
We're now going to remember that we can use OpenAI's endpoints.

03:08.060 --> 03:15.300
We can use the compatible OpenAI endpoints to talk to other models like Gemini, Deep Seek, and Grok.

03:15.580 --> 03:22.100
And any time that we have this approach, we will be able to easily use the OpenAI agents SDK.

03:22.660 --> 03:26.220
So here we're setting the base URL for Gemini endpoint.

03:26.380 --> 03:29.140
The base URL for the deep sea endpoint and for the grok.

03:29.300 --> 03:32.100
These are the OpenAI compatible endpoints.

03:32.260 --> 03:35.260
So for Gemini you can see it's got OpenAI in there.

03:35.580 --> 03:37.540
And the same for grok for deep secret.

03:37.540 --> 03:38.260
Is there only one.

03:38.260 --> 03:40.100
It's already OpenAI compatible.

03:40.820 --> 03:49.660
Then we create a new instance of the client by instantiating an async OpenAI object, as you can see

03:49.860 --> 03:50.340
here.

03:50.380 --> 03:54.310
Passing in the base URL and passing in the key.

03:54.750 --> 03:58.710
And finally we create three model objects.

03:58.710 --> 04:06.190
These are called OpenAI chat completions model passing in the name of the model and the client that

04:06.190 --> 04:08.750
we just defined in the group above.

04:09.310 --> 04:11.470
So this is a little bit boilerplate.

04:11.470 --> 04:17.470
And if you're using GPT four or mini, if you're using any of OpenAI's models, you don't need to do

04:17.470 --> 04:21.230
any of this because it assumes by default that this is the case.

04:21.350 --> 04:27.310
So what I mean is that when we actually create our agents, we're going to give them a name instructions,

04:27.310 --> 04:29.830
and we're going to pass in one of these models.

04:30.110 --> 04:35.950
Now if for this model you pass in a string you just pass in text, which is what we did before we just

04:35.950 --> 04:38.990
passed in GPT four mini right there.

04:39.230 --> 04:43.470
If it's text, then it assumes that you're talking directly to OpenAI.

04:43.910 --> 04:52.270
But if, by contrast, you pass in a model object an instance of OpenAI chat completions Model, then

04:52.270 --> 04:56.030
it will connect to this model using this endpoint.

04:56.550 --> 05:01.030
And so as you can see we have three agents sales agents one, two and three.

05:01.230 --> 05:03.710
The first one is connecting to deep seek.

05:03.910 --> 05:06.470
The second one is connecting to Gemini.

05:06.710 --> 05:10.510
And the third one is connecting to llama 3.3.

05:10.670 --> 05:16.190
The massive llama model through grok the fast inference platform.

05:16.470 --> 05:17.390
So there they are.

05:17.430 --> 05:19.630
This is how it all connects together.

05:19.870 --> 05:21.070
And we'll run that.

05:21.070 --> 05:25.670
And we now have these three agents connecting to these three different models.

05:26.350 --> 05:31.870
We will now do exactly what we did before our description, write a cold sales email.

05:31.870 --> 05:38.230
And we're now going to repackage each of those three sales agents into tools called tool one.

05:38.270 --> 05:38.950
Tool two.

05:38.990 --> 05:39.710
Tool three.

05:39.950 --> 05:44.310
And passing in this description as the description of the tool.

05:44.550 --> 05:45.710
And that is done.

05:45.990 --> 05:49.560
And we will now have a normal function tool.

05:49.560 --> 05:58.200
We use this decorator to reconstitute wrap this function in the the the boilerplate JSON that describes

05:58.200 --> 05:58.840
this tool.

05:59.600 --> 06:01.760
And it's almost a wrap.

06:01.800 --> 06:04.600
We're zooming through everything we did last time.

06:04.600 --> 06:05.960
We've now got some instructions.

06:05.960 --> 06:08.120
You can write a subject for a cold email.

06:08.520 --> 06:11.200
We've got some HTML instructions.

06:11.200 --> 06:14.120
You can convert a text email to HTML.

06:14.800 --> 06:21.040
We then make a subject writer an agent, which is going to do this.

06:21.040 --> 06:25.160
And as I say, I'm just passing in the string GPT four mini.

06:25.400 --> 06:28.720
So this is an agent that can write the subject of an email.

06:29.080 --> 06:34.880
This is turning that into a tool, a tool that can write the subject of an email.

06:35.320 --> 06:39.680
This is an agent that can convert an email to HTML format.

06:40.040 --> 06:46.000
And here it is as a tool, a tool that can convert a text email body to HTML email.

06:46.160 --> 06:50.040
I know I'm going through this very fast, but we just did it yesterday, so hopefully this is just immediate

06:50.040 --> 06:50.760
revision.

06:50.760 --> 06:54.920
So we run that and we collect together those three tools.

06:55.920 --> 07:01.720
This is our emailer agent the agent which is able to take some instructions.

07:02.160 --> 07:03.480
The email tools.

07:03.600 --> 07:07.000
And it has a hand off description if you remember that.

07:07.360 --> 07:09.360
And now we're almost done.

07:09.680 --> 07:14.720
We now put these three sales tools into one group of tools.

07:14.920 --> 07:19.200
The hand off is now this one hand off agent.

07:19.200 --> 07:20.880
This emailer agent.

07:21.400 --> 07:22.400
We run that.

07:23.080 --> 07:27.200
And finally here we are, the same arrival as before.

07:27.240 --> 07:29.400
The sales manager's instructions.

07:29.400 --> 07:34.320
We pass in the instructions we pass in the tools, we pass in the hand offs.

07:34.520 --> 07:38.600
And we then write the cold sales email.

07:39.000 --> 07:41.440
And with that, I kick this off.

07:41.560 --> 07:45.640
It takes about a minute and I will see you in a second when it completes.
