WEBVTT

00:00.400 --> 00:03.840
Okay, so now we get to the meat of Autogen core.

00:04.240 --> 00:11.360
We are going to create a runtime, a single threaded agent runtime it's called, which is a standalone

00:11.360 --> 00:17.640
runtime running on my computer, which as it says, will handle agents in a single threaded way.

00:18.160 --> 00:22.640
And the first thing that we're going to do is register.

00:22.640 --> 00:28.920
We call register on the agent itself to say, I want you to register yourself with this runtime.

00:29.040 --> 00:31.560
Now, this isn't creating an agent.

00:31.600 --> 00:34.440
This is just saying you are a type of agent.

00:34.440 --> 00:40.680
And I want you to tell the runtime that you are a type of agent that can be spawned, you can be created,

00:40.920 --> 00:45.560
and you are a type of agent of type simple agent that's going to be your type.

00:45.920 --> 00:52.920
And this, this thing here, this is a function which can generate new versions of you.

00:52.920 --> 00:54.240
It can instantiate you.

00:54.280 --> 00:55.360
It is a factory.

00:55.640 --> 00:57.600
And you pass that in as well.

00:57.840 --> 00:58.960
And so I will do this.

00:59.000 --> 01:03.660
It's now created a runtime and it's created a type of agent called a simple agent.

01:03.700 --> 01:05.980
We haven't actually yet built any of these.

01:05.980 --> 01:07.300
We haven't instantiated one.

01:07.300 --> 01:12.660
But the as a type of agent is now a known thing to our runtime.

01:12.700 --> 01:15.500
Our runtime knows that there are such things as simple agents.

01:15.740 --> 01:18.380
And we're now going to start our runtime.

01:18.380 --> 01:20.220
It is now running.

01:20.220 --> 01:21.980
It is a it is a proper runtime.

01:22.460 --> 01:31.460
And now we are going to uh, we're going to first of all create an agent ID object to identify an agent.

01:32.100 --> 01:34.340
And we'll we'll do this properly.

01:34.380 --> 01:41.100
We'll say agent ID equals that, that is an ID that would identify this.

01:41.100 --> 01:45.980
And we are going to say that we want the default agent.

01:47.100 --> 01:52.860
Uh, because, because that, that will then, uh, we'll make sure that we have an agent created,

01:53.140 --> 01:59.860
and then we're going to send a message to, we're going to send a message to the, to the agent, which

01:59.860 --> 02:04.630
is called simple agent, The default ID and we're going to send a message.

02:04.630 --> 02:06.550
Well hi there to it.

02:06.750 --> 02:09.990
And then we will print whatever comes back.

02:10.470 --> 02:12.790
So any ideas what's going to come back I wonder.

02:14.590 --> 02:18.950
Uh, so uh it replied this is simple agent default.

02:18.950 --> 02:24.830
So it's simple agent is its type, which is the same one we registered and it default is the, uh,

02:24.990 --> 02:29.150
the, the id uh, and it said, you said, well hi there.

02:29.190 --> 02:30.310
And I disagree.

02:31.510 --> 02:32.190
Charming.

02:32.630 --> 02:34.990
Uh, and that is uh, that's it.

02:34.990 --> 02:39.870
So there is a demo of auto gen core and that's what auto gen core does.

02:39.910 --> 02:44.950
And putting in agent functionality like having code in there that calls LMS.

02:44.990 --> 02:46.510
That's your job or my job.

02:46.510 --> 02:48.950
That's not auto gen core's job.

02:49.070 --> 02:54.630
What it's there to do is to handle the passing of messages around by looking things up based on their

02:54.630 --> 02:57.230
type and their ID, and that's what it does.

02:57.510 --> 03:03.770
So now I'll show you one which has an LM behind it, but it shouldn't be any surprise to you because

03:03.770 --> 03:05.370
it's just the same infrastructure.

03:05.370 --> 03:13.370
The fact that we're calling an LLM is is almost of no consequence to, to, uh, the Autogen core framework.

03:13.530 --> 03:19.050
So what we're going to do is we're going to make a slightly more interesting one called my LM agent,

03:19.090 --> 03:21.210
still a subclass of rooted agent.

03:21.450 --> 03:24.050
And we're going to use a proper LM.

03:24.050 --> 03:30.210
And we could just call OpenAI directly using OpenAI dot create.

03:30.250 --> 03:32.490
We could just call the Python client library.

03:32.690 --> 03:39.490
But we can also use Autogen agent chat and we might as well since it's autogen week.

03:39.810 --> 03:46.090
So this is the same kind of thing, a subclass of rooted agent that's going to be two functions again

03:46.130 --> 03:49.330
init and handle my message.

03:49.570 --> 03:53.450
So the init just just calls the superclass.

03:53.770 --> 03:56.610
But it then creates a model client.

03:56.890 --> 03:58.050
But this could be doing anything.

03:58.050 --> 04:00.650
But this is the Autogen agent chat way.

04:00.690 --> 04:05.070
We're going to create one of these things, a GPT four mini model client.

04:05.070 --> 04:10.190
And we're going to set a field called underscore delegate, which we're just sort of holding on to.

04:10.230 --> 04:12.470
This is this is the the underlying.

04:12.510 --> 04:18.390
This is what our agent object is going to delegate to when it actually needs some code, some, some

04:18.430 --> 04:19.550
an LLM to run.

04:19.550 --> 04:21.110
And we could have anything we want.

04:21.110 --> 04:26.670
We could, we could do we could reply back with random things or we could create an instance of assistant

04:26.670 --> 04:27.030
agent.

04:27.030 --> 04:28.310
And that's what we're going to do.

04:28.550 --> 04:29.870
And that's where we put in.

04:29.910 --> 04:33.750
If you remember, when you create an assistant agent, there's the name of the agent and there's the

04:33.750 --> 04:35.350
model client, and there it is.

04:35.550 --> 04:43.190
And as a result in underscore delegate underscore often used to show sort of like private secret, uh,

04:43.510 --> 04:47.230
variables that other people should know about, like, like private in the, in the Java world.

04:47.470 --> 04:52.110
Um, so the this is being set to an assistant agent.

04:53.270 --> 04:57.790
So, uh, now we just have to write our message handler.

04:58.070 --> 05:00.350
And as I say, it can be called anything you like.

05:00.510 --> 05:02.640
I'm calling it handle my message type.

05:03.040 --> 05:08.680
Um, and that's really to sort of draw your attention to the fact that what matters is what type of

05:08.680 --> 05:16.800
object comes in the message field, because Autogen core will automatically route messages to agents

05:16.800 --> 05:24.680
that should receive them based on the the finding a handler that that looks for a message of that type.

05:24.840 --> 05:25.520
That's how it works.

05:25.520 --> 05:27.320
That's the clever routing that it does.

05:27.360 --> 05:31.200
And by the way, you can send a message direct to an agent, which is what we're doing right now.

05:31.200 --> 05:37.120
But it also has a whole kind of pub sub thing there where you can subscribe to topics and you can publish

05:37.120 --> 05:41.200
out messages to lots of agents that are all interested in one particular topic.

05:41.360 --> 05:48.160
So the whole process of dispatching messages to the right agent and then calling the right handler,

05:48.320 --> 05:49.560
that's the clever stuff.

05:49.560 --> 05:50.960
That's what it does well.

05:51.000 --> 05:55.120
And why why we use a framework like this rather than coding it ourselves.

05:55.360 --> 05:57.520
But for some of these examples, it's pretty trivial.

05:57.520 --> 05:59.320
So we could equally code it ourselves.

05:59.640 --> 06:03.820
But you can imagine that this is done in a way that can be scaled and distributed.

06:04.100 --> 06:06.740
So anyways, handle my message type.

06:07.100 --> 06:14.100
Uh, as long as, uh, message is sent to this agent with the ID and and type, and that the object

06:14.100 --> 06:17.580
that's sent is of this type, it will arrive at this function.

06:17.780 --> 06:21.820
And I'm going to say that I received a message and print the content.

06:22.340 --> 06:24.700
Then I'm going to now now this is confusing.

06:25.300 --> 06:31.020
This object here text message looks subtly different to this object here.

06:31.020 --> 06:31.780
Message.

06:32.180 --> 06:34.300
Uh, do you know what's going on here?

06:34.500 --> 06:39.180
This text message is text message from the, um, autogen.

06:39.500 --> 06:40.460
It's this thing here.

06:40.460 --> 06:42.060
It's the agent chat messages.

06:42.060 --> 06:43.020
The text message.

06:43.020 --> 06:50.020
The same thing we were using yesterday and the day before when we were interacting with agent chat agents.

06:50.020 --> 06:55.260
So this is a autogen agent chat, uh, message, which can be a bit confusing.

06:55.260 --> 06:56.020
And you might.

06:56.220 --> 06:59.900
Yeah, there are ways you could you could get around that by, by giving it a different you can say

06:59.900 --> 07:08.960
like as agent chat text message if you wanted to to like make it so the code is a little bit clearer

07:08.960 --> 07:13.560
and you're distinguishing between the Autogen core and the Autogen agent chat.

07:13.880 --> 07:14.520
All right.

07:14.960 --> 07:16.080
Anyways, so sorry.

07:16.080 --> 07:16.760
Back we go.

07:16.920 --> 07:24.920
So we create the sort of text message that you need for Autogen agent chat passing in the content of

07:24.920 --> 07:27.000
our message and the source is user.

07:27.240 --> 07:35.080
And this is the onmessage that we call in agent Chat land with this text message and the cancellation

07:35.080 --> 07:36.520
token if you remember that thing.

07:37.160 --> 07:39.840
And then we get back the content.

07:40.120 --> 07:41.880
We say that that was the reply.

07:41.880 --> 07:49.160
And we return a new instance of message of our message, with the content being that reply.

07:50.120 --> 07:53.280
I hope you followed all that, or at least got enough of an idea of it.

07:53.320 --> 07:54.760
Let's give this a shot.

07:54.920 --> 08:00.320
Let's create a new runtime, a single threaded agent runtime, standalone runtime.

08:00.320 --> 08:06.490
We're going to register two agents the simple agent and the LM agent.

08:06.530 --> 08:10.610
The new one, Simple Agent, isn't really an LM at all.

08:10.610 --> 08:12.770
It just disagrees with whatever it's told.

08:12.770 --> 08:21.250
And LM agent is actually going to dispatch through this underscore delegate down to a true gpt4 mini.

08:21.730 --> 08:23.850
So we're going to start the runtime.

08:24.330 --> 08:27.130
Then we are going to send a message.

08:27.130 --> 08:30.410
Hi there to the real agent.

08:30.610 --> 08:33.610
And with whatever it replies we're going to send that.

08:33.610 --> 08:39.890
We're going to forward that on to the other agent, to the simple agent and see what comes out there.

08:42.210 --> 08:44.850
So the LM agent received hi there.

08:44.850 --> 08:46.930
And it said hello, how can I assist you today?

08:46.970 --> 08:49.170
A classic GPT four minion response.

08:49.570 --> 08:53.770
And, uh, the simple agent said, this is simple agent default.

08:53.770 --> 08:55.690
You said, hello, how can I assist you today?

08:55.690 --> 08:59.610
And I disagree, and there you go.

09:00.050 --> 09:04.330
Um, and with that, we will we will stop this pantomime.
