1
00:00:00,400 --> 00:00:03,840
Okay, so now we get to the meat of Autogen core.

2
00:00:04,240 --> 00:00:11,360
We are going to create a runtime, a single threaded agent runtime it's called, which is a standalone

3
00:00:11,360 --> 00:00:17,640
runtime running on my computer, which as it says, will handle agents in a single threaded way.

4
00:00:18,160 --> 00:00:22,640
And the first thing that we're going to do is register.

5
00:00:22,640 --> 00:00:28,920
We call register on the agent itself to say, I want you to register yourself with this runtime.

6
00:00:29,040 --> 00:00:31,560
Now, this isn't creating an agent.

7
00:00:31,600 --> 00:00:34,440
This is just saying you are a type of agent.

8
00:00:34,440 --> 00: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,

9
00:00:40,920 --> 00:00:45,560
and you are a type of agent of type simple agent that's going to be your type.

10
00:00:45,920 --> 00:00:52,920
And this, this thing here, this is a function which can generate new versions of you.

11
00:00:52,920 --> 00:00:54,240
It can instantiate you.

12
00:00:54,280 --> 00:00:55,360
It is a factory.

13
00:00:55,640 --> 00:00:57,600
And you pass that in as well.

14
00:00:57,840 --> 00:00:58,960
And so I will do this.

15
00:00:59,000 --> 00:01:03,660
It's now created a runtime and it's created a type of agent called a simple agent.

16
00:01:03,700 --> 00:01:05,980
We haven't actually yet built any of these.

17
00:01:05,980 --> 00:01:07,300
We haven't instantiated one.

18
00:01:07,300 --> 00:01:12,660
But the as a type of agent is now a known thing to our runtime.

19
00:01:12,700 --> 00:01:15,500
Our runtime knows that there are such things as simple agents.

20
00:01:15,740 --> 00:01:18,380
And we're now going to start our runtime.

21
00:01:18,380 --> 00:01:20,220
It is now running.

22
00:01:20,220 --> 00:01:21,980
It is a it is a proper runtime.

23
00:01:22,460 --> 00: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.

24
00:01:32,100 --> 00:01:34,340
And we'll we'll do this properly.

25
00:01:34,380 --> 00:01:41,100
We'll say agent ID equals that, that is an ID that would identify this.

26
00:01:41,100 --> 00:01:45,980
And we are going to say that we want the default agent.

27
00:01:47,100 --> 00:01:52,860
Uh, because, because that, that will then, uh, we'll make sure that we have an agent created,

28
00:01:53,140 --> 00: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

29
00:01:59,860 --> 00:02:04,630
is called simple agent, The default ID and we're going to send a message.

30
00:02:04,630 --> 00:02:06,550
Well hi there to it.

31
00:02:06,750 --> 00:02:09,990
And then we will print whatever comes back.

32
00:02:10,470 --> 00:02:12,790
So any ideas what's going to come back I wonder.

33
00:02:14,590 --> 00:02:18,950
Uh, so uh it replied this is simple agent default.

34
00:02:18,950 --> 00:02:24,830
So it's simple agent is its type, which is the same one we registered and it default is the, uh,

35
00:02:24,990 --> 00:02:29,150
the, the id uh, and it said, you said, well hi there.

36
00:02:29,190 --> 00:02:30,310
And I disagree.

37
00:02:31,510 --> 00:02:32,190
Charming.

38
00:02:32,630 --> 00:02:34,990
Uh, and that is uh, that's it.

39
00:02:34,990 --> 00:02:39,870
So there is a demo of auto gen core and that's what auto gen core does.

40
00:02:39,910 --> 00:02:44,950
And putting in agent functionality like having code in there that calls LMS.

41
00:02:44,990 --> 00:02:46,510
That's your job or my job.

42
00:02:46,510 --> 00:02:48,950
That's not auto gen core's job.

43
00:02:49,070 --> 00:02:54,630
What it's there to do is to handle the passing of messages around by looking things up based on their

44
00:02:54,630 --> 00:02:57,230
type and their ID, and that's what it does.

45
00:02:57,510 --> 00: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

46
00:03:03,770 --> 00:03:05,370
it's just the same infrastructure.

47
00:03:05,370 --> 00:03:13,370
The fact that we're calling an LLM is is almost of no consequence to, to, uh, the Autogen core framework.

48
00:03:13,530 --> 00: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,

49
00:03:19,090 --> 00:03:21,210
still a subclass of rooted agent.

50
00:03:21,450 --> 00:03:24,050
And we're going to use a proper LM.

51
00:03:24,050 --> 00:03:30,210
And we could just call OpenAI directly using OpenAI dot create.

52
00:03:30,250 --> 00:03:32,490
We could just call the Python client library.

53
00:03:32,690 --> 00:03:39,490
But we can also use Autogen agent chat and we might as well since it's autogen week.

54
00:03:39,810 --> 00:03:46,090
So this is the same kind of thing, a subclass of rooted agent that's going to be two functions again

55
00:03:46,130 --> 00:03:49,330
init and handle my message.

56
00:03:49,570 --> 00:03:53,450
So the init just just calls the superclass.

57
00:03:53,770 --> 00:03:56,610
But it then creates a model client.

58
00:03:56,890 --> 00:03:58,050
But this could be doing anything.

59
00:03:58,050 --> 00:04:00,650
But this is the Autogen agent chat way.

60
00:04:00,690 --> 00:04:05,070
We're going to create one of these things, a GPT four mini model client.

61
00:04:05,070 --> 00:04:10,190
And we're going to set a field called underscore delegate, which we're just sort of holding on to.

62
00:04:10,230 --> 00:04:12,470
This is this is the the underlying.

63
00:04:12,510 --> 00:04:18,390
This is what our agent object is going to delegate to when it actually needs some code, some, some

64
00:04:18,430 --> 00:04:19,550
an LLM to run.

65
00:04:19,550 --> 00:04:21,110
And we could have anything we want.

66
00:04:21,110 --> 00:04:26,670
We could, we could do we could reply back with random things or we could create an instance of assistant

67
00:04:26,670 --> 00:04:27,030
agent.

68
00:04:27,030 --> 00:04:28,310
And that's what we're going to do.

69
00:04:28,550 --> 00:04:29,870
And that's where we put in.

70
00:04:29,910 --> 00:04:33,750
If you remember, when you create an assistant agent, there's the name of the agent and there's the

71
00:04:33,750 --> 00:04:35,350
model client, and there it is.

72
00:04:35,550 --> 00:04:43,190
And as a result in underscore delegate underscore often used to show sort of like private secret, uh,

73
00:04:43,510 --> 00:04:47,230
variables that other people should know about, like, like private in the, in the Java world.

74
00:04:47,470 --> 00:04:52,110
Um, so the this is being set to an assistant agent.

75
00:04:53,270 --> 00:04:57,790
So, uh, now we just have to write our message handler.

76
00:04:58,070 --> 00:05:00,350
And as I say, it can be called anything you like.

77
00:05:00,510 --> 00:05:02,640
I'm calling it handle my message type.

78
00:05:03,040 --> 00:05:08,680
Um, and that's really to sort of draw your attention to the fact that what matters is what type of

79
00:05:08,680 --> 00:05:16,800
object comes in the message field, because Autogen core will automatically route messages to agents

80
00:05:16,800 --> 00:05:24,680
that should receive them based on the the finding a handler that that looks for a message of that type.

81
00:05:24,840 --> 00:05:25,520
That's how it works.

82
00:05:25,520 --> 00:05:27,320
That's the clever routing that it does.

83
00:05:27,360 --> 00:05:31,200
And by the way, you can send a message direct to an agent, which is what we're doing right now.

84
00:05:31,200 --> 00: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

85
00:05:37,120 --> 00:05:41,200
out messages to lots of agents that are all interested in one particular topic.

86
00:05:41,360 --> 00:05:48,160
So the whole process of dispatching messages to the right agent and then calling the right handler,

87
00:05:48,320 --> 00:05:49,560
that's the clever stuff.

88
00:05:49,560 --> 00:05:50,960
That's what it does well.

89
00:05:51,000 --> 00:05:55,120
And why why we use a framework like this rather than coding it ourselves.

90
00:05:55,360 --> 00:05:57,520
But for some of these examples, it's pretty trivial.

91
00:05:57,520 --> 00:05:59,320
So we could equally code it ourselves.

92
00:05:59,640 --> 00:06:03,820
But you can imagine that this is done in a way that can be scaled and distributed.

93
00:06:04,100 --> 00:06:06,740
So anyways, handle my message type.

94
00:06:07,100 --> 00:06:14,100
Uh, as long as, uh, message is sent to this agent with the ID and and type, and that the object

95
00:06:14,100 --> 00:06:17,580
that's sent is of this type, it will arrive at this function.

96
00:06:17,780 --> 00:06:21,820
And I'm going to say that I received a message and print the content.

97
00:06:22,340 --> 00:06:24,700
Then I'm going to now now this is confusing.

98
00:06:25,300 --> 00:06:31,020
This object here text message looks subtly different to this object here.

99
00:06:31,020 --> 00:06:31,780
Message.

100
00:06:32,180 --> 00:06:34,300
Uh, do you know what's going on here?

101
00:06:34,500 --> 00:06:39,180
This text message is text message from the, um, autogen.

102
00:06:39,500 --> 00:06:40,460
It's this thing here.

103
00:06:40,460 --> 00:06:42,060
It's the agent chat messages.

104
00:06:42,060 --> 00:06:43,020
The text message.

105
00:06:43,020 --> 00:06:50,020
The same thing we were using yesterday and the day before when we were interacting with agent chat agents.

106
00:06:50,020 --> 00:06:55,260
So this is a autogen agent chat, uh, message, which can be a bit confusing.

107
00:06:55,260 --> 00:06:56,020
And you might.

108
00:06:56,220 --> 00:06:59,900
Yeah, there are ways you could you could get around that by, by giving it a different you can say

109
00:06:59,900 --> 00: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

110
00:07:08,960 --> 00:07:13,560
and you're distinguishing between the Autogen core and the Autogen agent chat.

111
00:07:13,880 --> 00:07:14,520
All right.

112
00:07:14,960 --> 00:07:16,080
Anyways, so sorry.

113
00:07:16,080 --> 00:07:16,760
Back we go.

114
00:07:16,920 --> 00:07:24,920
So we create the sort of text message that you need for Autogen agent chat passing in the content of

115
00:07:24,920 --> 00:07:27,000
our message and the source is user.

116
00:07:27,240 --> 00:07:35,080
And this is the onmessage that we call in agent Chat land with this text message and the cancellation

117
00:07:35,080 --> 00:07:36,520
token if you remember that thing.

118
00:07:37,160 --> 00:07:39,840
And then we get back the content.

119
00:07:40,120 --> 00:07:41,880
We say that that was the reply.

120
00:07:41,880 --> 00:07:49,160
And we return a new instance of message of our message, with the content being that reply.

121
00:07:50,120 --> 00:07:53,280
I hope you followed all that, or at least got enough of an idea of it.

122
00:07:53,320 --> 00:07:54,760
Let's give this a shot.

123
00:07:54,920 --> 00:08:00,320
Let's create a new runtime, a single threaded agent runtime, standalone runtime.

124
00:08:00,320 --> 00:08:06,490
We're going to register two agents the simple agent and the LM agent.

125
00:08:06,530 --> 00:08:10,610
The new one, Simple Agent, isn't really an LM at all.

126
00:08:10,610 --> 00:08:12,770
It just disagrees with whatever it's told.

127
00:08:12,770 --> 00:08:21,250
And LM agent is actually going to dispatch through this underscore delegate down to a true gpt4 mini.

128
00:08:21,730 --> 00:08:23,850
So we're going to start the runtime.

129
00:08:24,330 --> 00:08:27,130
Then we are going to send a message.

130
00:08:27,130 --> 00:08:30,410
Hi there to the real agent.

131
00:08:30,610 --> 00:08:33,610
And with whatever it replies we're going to send that.

132
00:08:33,610 --> 00:08:39,890
We're going to forward that on to the other agent, to the simple agent and see what comes out there.

133
00:08:42,210 --> 00:08:44,850
So the LM agent received hi there.

134
00:08:44,850 --> 00:08:46,930
And it said hello, how can I assist you today?

135
00:08:46,970 --> 00:08:49,170
A classic GPT four minion response.

136
00:08:49,570 --> 00:08:53,770
And, uh, the simple agent said, this is simple agent default.

137
00:08:53,770 --> 00:08:55,690
You said, hello, how can I assist you today?

138
00:08:55,690 --> 00:08:59,610
And I disagree, and there you go.

139
00:09:00,050 --> 00:09:04,330
Um, and with that, we will we will stop this pantomime.