WEBVTT

00:00.160 --> 00:08.240
Okay, so here we are back in Cursa going to the fifth directory where there are a few things for me

00:08.240 --> 00:09.240
to show you.

00:09.840 --> 00:13.080
So, uh, where to begin?

00:13.440 --> 00:18.400
I am going to begin by telling you about Agent Pi.

00:19.200 --> 00:22.480
So Agent Pi is like our template.

00:22.640 --> 00:29.160
This is a file that we are going to give another agent and ask it to use this as its model, as its

00:29.160 --> 00:34.480
example, and to take this as a template and to make other agents like this.

00:34.840 --> 00:37.480
So it is quite simply, it's like a prototype.

00:37.480 --> 00:39.680
It is our the prototype that will be used.

00:39.720 --> 00:43.000
We will clone it and make various versions of it or we won't.

00:43.040 --> 00:43.880
An agent will.

00:44.120 --> 00:46.160
So it does some some imports.

00:46.480 --> 00:47.840
It has a system message.

00:47.840 --> 00:49.280
You are a creative entrepreneur.

00:49.320 --> 00:55.120
Your task is to come up with a new business idea using a genetic I or refine an existing idea.

00:55.160 --> 00:59.970
Your personal interests are in these sectors and there's a couple of sectors you're drawn to ideas that

00:59.970 --> 01:01.170
involve disruption.

01:01.490 --> 01:04.530
You are less interested in ideas that are purely automation.

01:04.730 --> 01:07.410
You are optimistic, adventurous, and have risk appetite.

01:07.450 --> 01:08.290
You're imaginative.

01:08.330 --> 01:09.690
Sometimes too much so.

01:09.930 --> 01:10.850
Your weaknesses.

01:10.970 --> 01:12.970
You're not patient, can be impulsive.

01:13.250 --> 01:16.570
You should respond with your business ideas and engaging in a clear way.

01:16.970 --> 01:19.530
And you can see at the top here there's a comment.

01:19.610 --> 01:24.490
Change the system message to reflect the unique characteristics of this agent.

01:25.090 --> 01:31.530
And then here, this constant chances that I bounce idea off another is 0.5.

01:32.250 --> 01:35.570
And here it says you can also change the code to make the behavior different.

01:35.570 --> 01:38.250
But be careful to keep the method signatures the same.

01:38.930 --> 01:41.170
Okay, so far so good.

01:41.170 --> 01:43.450
And this agent that is going to be cloned.

01:43.490 --> 01:48.970
It has an init method which just simply sets GPT for a mini with a temperature.

01:48.970 --> 01:51.570
Make it a bit a bit random 0.7.

01:52.090 --> 01:57.130
And of course it creates a delegate which is an assistant using that model client.

01:57.130 --> 01:59.430
And with this system message.

01:59.990 --> 02:00.670
Okay.

02:01.190 --> 02:03.030
And here we have our handle.

02:03.070 --> 02:03.990
My message.

02:04.310 --> 02:05.950
Uh, and it's a message handler.

02:06.270 --> 02:14.350
And, uh, it's, um, got, um, uh, maybe it would be clearer if I just call this handle message

02:14.350 --> 02:15.630
rather than handle my message type.

02:15.670 --> 02:17.310
Fewer tokens is always good.

02:17.910 --> 02:21.990
Uh, so, um, it takes, uh, of course, the message.

02:22.030 --> 02:27.390
And now this message is using our messages object, the thing that we always create.

02:27.510 --> 02:32.030
And I have separated that out into its own package, because I want to put as little code in here as

02:32.030 --> 02:33.990
possible to avoid mistakes.

02:34.150 --> 02:36.270
So I've got our message object in here.

02:36.270 --> 02:37.550
We'll look at that in a minute.

02:38.030 --> 02:43.470
And it so it takes a messages message and it returns a messages dot message.

02:43.950 --> 02:47.310
It prints that this message with this type.

02:47.550 --> 02:49.910
Remember the type is like the agent's name.

02:50.070 --> 02:51.750
It's going to say received a message.

02:51.750 --> 02:54.390
So we will see as agents receive messages.

02:54.830 --> 02:56.710
It then makes a.

02:57.840 --> 03:07.680
text message, um, and, uh, it, uh, then it takes, takes this, this message that it was sent

03:08.160 --> 03:13.520
and it, uh, sends that to the, its underlying lm.

03:13.520 --> 03:15.920
So, so it sends on the message that it got.

03:16.200 --> 03:20.160
And that will of course, also have the system prompt as part of it because that's set right here.

03:20.680 --> 03:24.960
Uh, and it then says it waits until it gets back.

03:25.000 --> 03:31.280
The response it gets, it takes from the, the the response it makes that its business idea because

03:31.280 --> 03:33.120
it's asked to come up with a business idea.

03:33.120 --> 03:36.920
So what comes back from the delegate will be a business idea.

03:37.280 --> 03:43.720
And now it picks a random number and sees it basically figures out if in this case, this random, not

03:43.720 --> 03:46.200
random gives you a number between 0 and 1.

03:46.200 --> 03:51.840
And so if it's a 50% chance, if it's if it's a, there's a 50% chance it'll be less than 0.5.

03:52.120 --> 04:00.010
So uh, that this, this logic works If there's in a 50% chance it will use a little utility function,

04:00.010 --> 04:05.890
find recipient that's going to find some other recipient, and then it will say, here is my business

04:05.890 --> 04:06.530
idea.

04:06.530 --> 04:10.690
This might not be your specialty, but please refine it and make this business idea better.

04:10.890 --> 04:15.370
And it sends this business idea as a message to the recipient.

04:15.570 --> 04:19.130
So some randomly picked recipient, how's it going to pick a random recipient?

04:19.130 --> 04:26.690
We will see a random recipient is going to get the request to refine this business idea that this agent

04:26.690 --> 04:27.730
just came up with.

04:28.010 --> 04:32.410
And then and only if the probability is is is within this.

04:32.770 --> 04:37.170
And if so, then it will take the refined business idea.

04:37.170 --> 04:42.930
It will do self dot send message, which means it uses the runtime that it's associated with to send

04:42.930 --> 04:45.050
a message to the recipient.

04:45.050 --> 04:49.410
And it gets back the idea and that is what it then returns.

04:49.410 --> 04:56.350
So it either returns its own idea or there's some probability that it will return a refined version

04:56.350 --> 04:59.350
of its own idea refined by another agent.

05:00.190 --> 05:02.750
Okay, a lot to talk through.

05:02.750 --> 05:03.590
I hope that made sense.

05:03.590 --> 05:08.230
This is the template, the clone that's going to be used to create more agents.

05:08.270 --> 05:09.110
Let's see how.

05:09.150 --> 05:10.070
And I'm going to speed up.

05:10.070 --> 05:13.030
But but hang on in there because it's going to be great when you see this running.

05:13.030 --> 05:13.990
So wait for it.

05:14.070 --> 05:15.910
Don't don't don't lose me.

05:16.270 --> 05:18.590
Uh, I'll just quickly show you the messages.

05:18.590 --> 05:24.230
This is the messages package, and it has that same data class that we know of.

05:24.630 --> 05:30.070
Uh, and then it has some code to deal this, find recipient, find another agent that will message.

05:30.070 --> 05:31.270
And how does it do that?

05:31.310 --> 05:37.230
Well, it's super hacky, but basically, as the clones start appearing, the clones are going to be

05:37.230 --> 05:40.590
named agent one, agent two, agent three, agent four.

05:40.990 --> 05:45.950
And so it basically just looks in this directory to see what other agents have already existed.

05:45.950 --> 05:51.590
And if it finds one, it returns a randomly selected other agent, and there's some chance that we'll

05:51.590 --> 05:52.630
return the agent itself.

05:52.720 --> 05:57.320
The agent might talk to itself that maybe I should should, uh, solve I should should fix that and

05:57.320 --> 05:58.320
not let it talk to itself.

05:58.320 --> 06:00.200
But I thought, whatever, it doesn't matter.

06:00.200 --> 06:00.440
So.

06:00.440 --> 06:02.640
So right now it might talk to itself as well.

06:03.600 --> 06:04.120
Okay.

06:04.280 --> 06:07.840
So then the, uh, where life gets interesting is creator.

06:08.400 --> 06:12.320
Creator is the agent that creates and spawns agents.

06:12.600 --> 06:14.600
And I'll let you look through this.

06:14.600 --> 06:17.680
But basically the system message says just what you would think.

06:17.840 --> 06:20.720
You're an agent that can create other agents.

06:20.840 --> 06:28.080
You receive Python code and you create the user's Autogen core and Autogen agent chat.

06:28.280 --> 06:32.640
You should use this template to create a new agent with a unique system message.

06:32.920 --> 06:35.800
You can choose to keep the overall goal the same or change it.

06:35.800 --> 06:39.680
You can choose to take this agent in a completely different direction.

06:39.680 --> 06:42.640
This is the part that's both edgy and risky haha.

06:43.160 --> 06:49.000
The only requirement is that the class must be named agent, and it must inherit from from rooted agent

06:49.000 --> 06:50.800
and and it must have an init method.

06:51.380 --> 06:53.060
Respond only with Python code.

06:53.260 --> 06:54.900
So, look, this is this is cool.

06:54.900 --> 06:58.020
There's no doubt we're building something that we're saying.

06:58.020 --> 07:00.460
You have a free reign to do what you want.

07:00.500 --> 07:03.820
And I've only tried this with GPT four and mini, which is a bit safe with this stuff.

07:03.820 --> 07:09.620
It hasn't actually gone off the rails in an interesting way, and I am tempted to try it with Deep Sea.

07:09.660 --> 07:14.980
I'm slightly nervous with and with more creative agents, and maybe with Claude, because Claude is

07:15.020 --> 07:22.180
known for being more creative and see whether they look to include different logic in there to give

07:22.180 --> 07:24.540
this agent more smarts.

07:24.860 --> 07:29.780
But so far, whilst GPT four mini has definitely taken it in different directions, it hasn't done anything

07:29.820 --> 07:30.460
out there.

07:30.780 --> 07:34.780
Okay, so the user prompt says much, much the same thing.

07:34.940 --> 07:37.340
And then, uh, you can you can trace through it.

07:37.340 --> 07:39.940
But this is pretty simple and it prints what it's doing.

07:39.940 --> 07:49.380
But it basically opens this file, name it, it then uh, calls uh the delegate to, to take this action

07:49.380 --> 07:58.550
to basically given this python file in agent py, make a new version of it, and then and then it saves

07:58.550 --> 08:02.790
that as like agent one, agent two, agent three, agent four.

08:02.790 --> 08:09.270
So it was save it as each of the different, uh, agent numbers, it's, it's called with an agent number.

08:09.270 --> 08:12.110
And it will, uh, it will save it with that agent number.

08:12.550 --> 08:18.150
And then it does something that is super, uh, like, uh, out there.

08:18.630 --> 08:27.550
I use this Python feature, um, import lib to import the Python module that it just wrote.

08:27.550 --> 08:33.430
I import it here so that this creator agent imports that module, that it just wrote it effectively.

08:33.430 --> 08:42.470
If it just wrote a file called uh agent 5.py and the word agent five will have actually have come in

08:42.590 --> 08:43.870
in this message right here.

08:43.910 --> 08:46.630
So agent five is what will have been sent to the creator.

08:46.630 --> 08:49.120
And that's how it knows that that's the agent it's making.

08:49.280 --> 08:56.120
So in that case, what this will do is it will effectively be the same as saying import agent five pi.

08:56.320 --> 08:58.360
That's what that does dynamically.

08:58.360 --> 08:59.520
Programmatically.

08:59.560 --> 09:01.280
It imports it on the fly.

09:01.760 --> 09:08.840
And then I take that module that we've just imported on the on the fly and I register it, I call agent

09:08.840 --> 09:18.120
dot register with my runtime with the agent's name and using the lambda that will spawn a new instance,

09:18.160 --> 09:22.880
a factory method that will create a new instance of that agent on demand.

09:23.400 --> 09:29.760
And then it says it prints agent whatever is live and and it means not just the kind of live that we

09:29.760 --> 09:31.080
say when we deploy software.

09:31.440 --> 09:33.680
It means that the agent is running.

09:34.000 --> 09:39.160
Um, and it will then send a message to that agent saying, give me an idea.

09:39.400 --> 09:42.520
And that will then trigger that agent will then get that message.

09:42.520 --> 09:48.780
It will process it, it will work on an idea and potentially if the probability meets that criteria,

09:48.780 --> 09:54.220
it will then send on its idea to another agent that it will find in the directory, and ask that other

09:54.220 --> 09:56.900
agents to add feedback to it.

09:57.060 --> 10:00.780
And that's that's how it would all fit together, if you can believe it.

10:00.780 --> 10:02.380
That's what this does.

10:02.380 --> 10:03.660
So it's imaginative.

10:03.700 --> 10:05.180
It's a kind of crazy.

10:05.460 --> 10:11.220
And uh, as I say, the main the learning point here is that it is educational to step through it and

10:11.220 --> 10:11.900
see what's happening.

10:11.900 --> 10:14.540
And we've got something important about async Python coming up.

10:14.700 --> 10:20.780
Um, but this is definitely, uh, something to have you thinking about what it means to have agents

10:20.780 --> 10:26.700
interacting, messaging each other, and how this really demonstrates Autogen cause power as a pure

10:26.740 --> 10:28.900
agent messaging platform.

10:28.900 --> 10:37.060
We're able to to single out an agent, we are able just to get a recipient's agent ID and send it a

10:37.060 --> 10:37.740
message.

10:37.860 --> 10:44.300
So it allows for this kind of inter-process communication, uh, without without having to worry about

10:44.300 --> 10:46.660
the details of how that's actually strung together.
