WEBVTT

00:00.080 --> 00:06.360
Okay, it's time for a great function called a method called trade.

00:06.880 --> 00:07.960
This is this is the one.

00:07.960 --> 00:09.760
This is where the meat happens.

00:09.960 --> 00:12.040
And it's the same again as the one in the lab.

00:12.040 --> 00:14.160
We get the account, we get the strategy.

00:14.360 --> 00:18.560
And we say based on your investment strategy, you should now look for new opportunities.

00:18.560 --> 00:22.560
Use the research tool to find news and opportunities consistent with your strategy.

00:22.760 --> 00:25.640
Use the tools to research stock prices and other company information.

00:25.640 --> 00:27.120
Finally, make your decision.

00:27.400 --> 00:29.800
You don't need to rebalance your portfolio.

00:29.840 --> 00:31.560
You'll be asked to do so later.

00:31.600 --> 00:33.560
It's a little thing that I'm going to add in here.

00:33.600 --> 00:34.920
We didn't do it in the lab.

00:35.320 --> 00:38.600
Just make your trades on your strategy as needed.

00:38.840 --> 00:42.960
I'm not I'm not going to say a reminder of that mistake because we don't say it before your investment

00:42.960 --> 00:43.520
strategy.

00:43.560 --> 00:45.400
And then we lay out the investment strategy.

00:45.440 --> 00:48.120
Here is your account and we give it its account.

00:48.640 --> 00:50.520
Here is the current date.

00:50.520 --> 00:51.280
We tell it.

00:51.520 --> 00:54.200
And now carry out your analysis.

00:54.240 --> 01:01.120
Make your decision and, and uh, and add uh trade as necessary.

01:01.320 --> 01:05.890
After you've made your trades respond with a brief 2 to 3 sentence appraisal of your portfolio and its

01:05.890 --> 01:08.570
outlook, and we'll store that in self trading.

01:09.170 --> 01:12.370
Uh, so that's that's going to be convenient for us to look at later.

01:13.010 --> 01:14.370
Uh, okay.

01:15.010 --> 01:18.090
Now it seems like we should also be mentioning the fact that it has.

01:18.130 --> 01:23.410
Yes, we've got the, uh, we've got this mention about your entity tools as persistent memory.

01:23.650 --> 01:28.930
Um, let me make that point again here so that it knows, um.

01:31.250 --> 01:32.410
That it can do that.

01:32.690 --> 01:35.130
Use the entity tools.

01:37.570 --> 01:40.170
To store and recall information.

01:40.170 --> 01:42.050
I will take what cursor suggests.

01:42.050 --> 01:42.850
Perfect.

01:43.010 --> 01:44.530
That seems nice thing to add.

01:44.930 --> 01:45.690
All right.

01:45.930 --> 01:50.490
And then we've got something very similar called rebalance which is the same kind of thing.

01:50.490 --> 01:55.610
But it's saying think about your current portfolio, your current holdings and decide whether to change

01:55.610 --> 01:55.970
them.

01:56.210 --> 02:02.410
So this is an example of the same agent getting two different prompts, which is another sort of degree

02:02.410 --> 02:03.130
of freedom.

02:03.130 --> 02:07.810
You've got the idea of how many different agents, how do you carve up your problem into different autonomous

02:07.810 --> 02:10.380
agents and then within a given agent.

02:10.420 --> 02:12.340
How many different prompts do I use?

02:12.540 --> 02:18.100
And this should be familiar to you because in crew this is what they how they reorganize.

02:18.100 --> 02:21.700
They organize things around both your agents and your tasks.

02:21.820 --> 02:27.860
So task was a kind of first class object in crew land in OpenAI agents SDK.

02:27.900 --> 02:29.300
It doesn't particularly have that.

02:29.300 --> 02:34.980
It just has different different different runners run different different different things you might

02:34.980 --> 02:35.420
do.

02:35.660 --> 02:40.900
And the way we're doing it is we've just got two different functions trade and rebalance, two different

02:40.900 --> 02:41.340
steps.

02:41.340 --> 02:43.100
And we're calling it like this.

02:43.220 --> 02:47.180
So it's a good example of how crew is a bit more opinionated.

02:47.300 --> 02:51.940
Crew gives us this construct of a task separate to an agent.

02:51.940 --> 02:55.540
Whereas OpenAI a little bit a little bit more flexible.

02:55.580 --> 02:56.540
There's just the agent.

02:56.540 --> 03:01.180
And then it's up to you if you want to call it multiple times or how you want to organize yourself around

03:01.180 --> 03:01.500
it.

03:01.580 --> 03:04.860
So these are like two different tasks for the same agent.

03:04.860 --> 03:11.460
And it's an interesting agentic design, uh, question that you have to wrestle through about.

03:11.460 --> 03:15.510
To what extent do you divide up your, your bigger problem into different agents.

03:15.510 --> 03:18.350
And then to what extent do you do that into different tasks?

03:18.350 --> 03:22.190
And if you're going to ask me, how do you go about making that decision, you know what the answer

03:22.190 --> 03:22.590
is?

03:22.590 --> 03:28.310
You experiment, you try out some different, different approaches and you see which one performs best.

03:28.670 --> 03:29.190
Okay.

03:29.470 --> 03:33.150
So we've got the rebalance is very similar to the trade.

03:33.150 --> 03:40.670
And it makes just just the instruction that it should look to rebalance based on your strategy with

03:40.750 --> 03:42.590
your investment strategy listed out.

03:42.590 --> 03:44.310
And we'll take out the words reminder.

03:44.590 --> 03:45.710
Just make it consistent.

03:45.710 --> 03:46.430
There we go.

03:46.630 --> 03:53.430
So those are our two big tasks that we're assigning for this agent okay.

03:53.470 --> 03:59.870
And now we have the run method I just before we look at that I should just just quickly talk through

03:59.870 --> 04:01.630
a bit more this runner run here.

04:01.630 --> 04:03.310
Because I think I went through this too quickly.

04:03.510 --> 04:05.870
Both trade and rebalance.

04:05.870 --> 04:08.430
Both have this, uh, with runner run.

04:08.430 --> 04:13.150
And I just noticed there that we're missing the trace here, so we should we should absolutely have

04:13.150 --> 04:16.070
that in there with trace self dot name.

04:16.750 --> 04:18.600
Let's make this a little bit better.

04:18.600 --> 04:22.640
So it will trace and we'll say self dot name.

04:29.640 --> 04:30.400
Trading.

04:33.200 --> 04:41.880
And then down below we'll have this as rebalancing so that it's it's very clear what's going on.

04:42.280 --> 04:44.400
Uh here we go with trace.

04:45.480 --> 04:48.160
Cursor is interfering a bit I'm not sure what's happening there.

04:48.160 --> 04:48.640
There we go.

04:48.680 --> 04:50.440
Self dot trade rebalancing.

04:50.600 --> 04:53.680
So this way we will see it traced separately.

04:53.680 --> 04:58.840
And it's important to take time over your traces because this is really the the only insight you get

04:58.840 --> 05:00.000
into what's going on.

05:00.000 --> 05:04.280
And uh, you need to make sure that you can clearly distinguish different activities.

05:04.280 --> 05:10.040
So now our different our different tasks basically to use cruise language are being traced with different,

05:10.280 --> 05:11.520
uh, different names.

05:11.840 --> 05:14.200
And then we're calling Runner run.

05:14.880 --> 05:19.400
Uh, we're passing in the agent, our underlying agent, the message that we just wrote.

05:19.600 --> 05:20.600
And we've got this.

05:20.600 --> 05:22.250
Max Turns.

05:22.250 --> 05:28.690
This is where we specify don't go over 30 different LM calls to get to the outcome.

05:28.730 --> 05:31.130
And last time it was it was in the teens.

05:31.130 --> 05:32.650
So we should we should we should be safe.

05:32.650 --> 05:37.410
We have some headroom in there if it goes on for a long time, but hopefully it will stop it from going

05:37.410 --> 05:38.370
off the rails.

05:39.010 --> 05:40.090
Um, okay.

05:40.610 --> 05:49.130
And so with that, the run the async run coroutine for this class, which says if we're in a do trade

05:49.130 --> 05:52.690
mode, then let's call my trade method.

05:53.170 --> 05:59.450
Otherwise call rebalance and then reverse flip do trades or do trade is a boolean that will be toggled

05:59.490 --> 06:00.770
true false true false.

06:00.770 --> 06:04.490
And depending on which one it is we will either trade or we will rebalance.

06:04.730 --> 06:08.450
And then we will switch and return the result.

06:09.570 --> 06:11.530
So that really is it.

06:11.530 --> 06:16.530
There is at the bottom here a cleanup, which is the thing that goes through and cleans up.

06:16.530 --> 06:20.610
And that is what would have been called automatically if we were using with.

06:21.490 --> 06:22.850
So there is our module.

06:22.890 --> 06:24.130
I hope you like it.

06:24.330 --> 06:26.290
Now let's give it a whirl.

06:26.290 --> 06:27.170
Let's run it.
