WEBVTT

1
00:00:00.460 --> 00:00:03.960
Welcome to the tools section of this course.

2
00:00:04.600 --> 00:00:07.440
So, in this example, we're going to make

3
00:00:07.440 --> 00:00:10.080
some tools and going to try and use

4
00:00:10.080 --> 00:00:11.880
them against an agent.

5
00:00:12.740 --> 00:00:18.320
So, you can make both informational tools and

6
00:00:18.320 --> 00:00:19.260
action tools.

7
00:00:20.160 --> 00:00:22.120
And in this case, I have made some

8
00:00:22.120 --> 00:00:23.160
tools down here.

9
00:00:23.940 --> 00:00:28.420
In terms of, I have a person info

10
00:00:28.420 --> 00:00:31.460
record here with just name and favourite colour

11
00:00:31.460 --> 00:00:31.980
of people.

12
00:00:32.520 --> 00:00:34.640
And I made a few tools that can

13
00:00:34.640 --> 00:00:35.300
work with them.

14
00:00:35.620 --> 00:00:39.820
I have a set of data here with

15
00:00:39.820 --> 00:00:42.780
just some names and some favourite colours.

16
00:00:43.580 --> 00:00:45.340
And then I exposed two tools.

17
00:00:45.740 --> 00:00:49.520
I exposed a get persons, and I've just

18
00:00:49.520 --> 00:00:51.060
put in so we can see that when

19
00:00:51.060 --> 00:00:51.620
they are called.

20
00:00:52.380 --> 00:00:54.820
And I get a person by name.

21
00:00:57.140 --> 00:00:59.880
This is just a C# class.

22
00:01:00.000 --> 00:01:02.220
It has nothing to do with AI or

23
00:01:02.220 --> 00:01:03.160
tools or anything.

24
00:01:03.599 --> 00:01:06.140
But it's just a class, and we are

25
00:01:06.140 --> 00:01:07.720
going to turn this into a tool.

26
00:01:08.700 --> 00:01:10.540
In the same manner, we just have a

27
00:01:10.540 --> 00:01:12.420
small static class down here.

28
00:01:12.560 --> 00:01:15.300
That's called change colour of the console.

29
00:01:15.740 --> 00:01:17.460
And again, we are calling so we can

30
00:01:17.460 --> 00:01:18.520
see what happens.

31
00:01:20.700 --> 00:01:23.460
So, this is how we define our tools.

32
00:01:23.820 --> 00:01:25.320
Just plain C# code.

33
00:01:25.500 --> 00:01:27.740
In this case, it's something that just works

34
00:01:27.740 --> 00:01:28.380
here in memory.

35
00:01:28.720 --> 00:01:30.680
But it could easily have gone out to

36
00:01:30.680 --> 00:01:32.600
a hard drive.

37
00:01:32.680 --> 00:01:34.780
It could have gone into another API.

38
00:01:36.580 --> 00:01:39.460
The action could have been to place an

39
00:01:39.460 --> 00:01:42.020
order in a system or whatever you want.

40
00:01:42.100 --> 00:01:43.880
It's just C#, and it can be

41
00:01:43.880 --> 00:01:45.060
pretty much anything.

42
00:01:45.060 --> 00:01:47.980
And it can take input, and it can

43
00:01:47.980 --> 00:01:48.940
take output.

44
00:01:51.500 --> 00:01:53.620
So, what we're going to do is we're

45
00:01:53.620 --> 00:01:56.820
going to make our normal Azure OpenAI client.

46
00:01:57.320 --> 00:01:59.320
We are going to new up our tool

47
00:01:59.320 --> 00:02:01.480
because we need that a little later on

48
00:02:01.480 --> 00:02:01.700
here.

49
00:02:02.820 --> 00:02:04.780
And then we're going to make our agent.

50
00:02:05.780 --> 00:02:08.160
And we have told the agent it knows

51
00:02:08.160 --> 00:02:10.780
people, and it can change colours of the

52
00:02:10.780 --> 00:02:11.020
console.

53
00:02:11.340 --> 00:02:13.720
We probably don't need to tell it this.

54
00:02:13.720 --> 00:02:17.200
Sometimes when it's very advanced tools, you might

55
00:02:17.200 --> 00:02:20.200
want an instruction to say, when this happened,

56
00:02:20.420 --> 00:02:22.700
call this tool, when this happened, call this

57
00:02:22.700 --> 00:02:23.060
tool.

58
00:02:23.680 --> 00:02:25.700
So, I could, for example, here say change

59
00:02:25.700 --> 00:02:26.600
the colours of the console.

60
00:02:26.820 --> 00:02:29.680
I could have told that that tool is

61
00:02:29.680 --> 00:02:32.460
called change console colour.

62
00:02:32.900 --> 00:02:35.320
In this case, it's so obvious that we

63
00:02:35.320 --> 00:02:37.120
actually don't need it.

64
00:02:39.900 --> 00:02:41.460
Then we have our tools.

65
00:02:42.120 --> 00:02:45.500
And our tools are just something called an

66
00:02:45.500 --> 00:02:49.380
AI function factory, where we say create.

67
00:02:50.000 --> 00:02:52.320
And there we give some kind of delegate.

68
00:02:52.780 --> 00:02:55.620
In this case, it's the get person method

69
00:02:55.620 --> 00:02:57.640
down here that we are getting.

70
00:02:58.280 --> 00:03:00.660
And we're telling it this is the name

71
00:03:00.660 --> 00:03:01.280
of the tool.

72
00:03:01.980 --> 00:03:05.220
And tools and AIs in general really like

73
00:03:05.220 --> 00:03:07.160
this snake case with the underscores.

74
00:03:08.860 --> 00:03:12.200
So, we just call it get persons, and

75
00:03:12.200 --> 00:03:14.480
we tell here's the description of the tool

76
00:03:14.480 --> 00:03:16.820
that it can get all persons you know,

77
00:03:17.520 --> 00:03:19.260
you meaning the AI.

78
00:03:20.320 --> 00:03:22.620
And get persons, so you get a specific

79
00:03:22.620 --> 00:03:23.500
person by name.

80
00:03:24.460 --> 00:03:27.940
And the final tool is just static methods.

81
00:03:27.940 --> 00:03:30.740
So, we're going to use that and say

82
00:03:30.740 --> 00:03:33.960
change console colour, and change the colour of

83
00:03:33.960 --> 00:03:34.380
the console.

84
00:03:35.700 --> 00:03:39.780
And beyond that, it's the same chat loop

85
00:03:39.780 --> 00:03:41.460
that we have done in the past.

86
00:03:41.880 --> 00:03:43.960
So, let's see this in action on how

87
00:03:43.960 --> 00:03:44.560
it works.

88
00:03:46.940 --> 00:03:49.480
So, we can ask it a set of

89
00:03:49.480 --> 00:03:49.940
questions.

90
00:03:50.140 --> 00:03:54.220
For example, we could ask, what is John's

91
00:03:54.220 --> 00:03:54.880
favourite colour?

92
00:03:56.300 --> 00:03:58.540
And it will come back and say John's

93
00:03:58.540 --> 00:03:59.800
favourite colour is red.

94
00:04:00.960 --> 00:04:09.180
We could then ask it, who have blue

95
00:04:09.180 --> 00:04:10.320
as their favourite colour?

96
00:04:11.320 --> 00:04:13.760
And we saw that up here it called

97
00:04:13.760 --> 00:04:16.120
get person because it could do that.

98
00:04:16.420 --> 00:04:18.880
And we can set breakpoints in here if

99
00:04:18.880 --> 00:04:21.940
we want to and see what's going on.

100
00:04:21.940 --> 00:04:23.560
So, we can do that.

101
00:04:24.440 --> 00:04:25.660
We get a breakpoint.

102
00:04:25.820 --> 00:04:26.980
We call it to get person.

103
00:04:28.720 --> 00:04:31.500
And it tells that Rasmus have blue as

104
00:04:31.500 --> 00:04:34.240
their favourite colour, which was down here as

105
00:04:34.240 --> 00:04:34.400
well.

106
00:04:36.140 --> 00:04:39.400
So, that is fairly simple to work with

107
00:04:39.400 --> 00:04:40.760
information like that.

108
00:04:40.880 --> 00:04:43.000
And we can, in a similar manner, do

109
00:04:43.000 --> 00:04:43.920
actions.

110
00:04:44.080 --> 00:04:45.500
So, we can say change the colour to

111
00:04:45.500 --> 00:04:45.720
green.

112
00:04:47.080 --> 00:04:49.320
And it will now change the console colour

113
00:04:49.320 --> 00:04:52.240
to green because we essentially just ran this

114
00:04:52.240 --> 00:04:55.060
piece of code being our action in our

115
00:04:55.060 --> 00:04:55.440
case.

116
00:04:58.800 --> 00:05:01.400
But because this is AI, it can also

117
00:05:01.400 --> 00:05:05.480
be more advanced than just simple commands like

118
00:05:05.480 --> 00:05:05.880
this.

119
00:05:06.320 --> 00:05:08.740
So, for example, what we could do is

120
00:05:08.740 --> 00:05:12.950
we could go in and say, change the

121
00:05:12.950 --> 00:05:15.170
colour of the main colour of the Canadian

122
00:05:15.170 --> 00:05:15.750
flag.

123
00:05:19.810 --> 00:05:22.990
And now it knew that the Canadian flag

124
00:05:22.990 --> 00:05:25.110
is red and white and the main colour

125
00:05:25.110 --> 00:05:25.830
is red.

126
00:05:26.290 --> 00:05:30.510
So, it used that information to grab that

127
00:05:30.510 --> 00:05:32.190
and run it.

128
00:05:35.670 --> 00:05:38.150
In a similar manner, let me try to

129
00:05:38.150 --> 00:05:40.730
restart this just so it's even easier to

130
00:05:40.730 --> 00:05:42.250
see what is going on here.

131
00:05:46.590 --> 00:05:49.510
If I go in and say, change the

132
00:05:49.510 --> 00:05:56.360
colour of Rasmus to Rasmus' favourite colour, what

133
00:05:56.360 --> 00:05:59.560
will happen is it's going to call persons.

134
00:06:00.900 --> 00:06:02.520
So, it finds all persons.

135
00:06:02.640 --> 00:06:05.560
In this case, it was unsure who Rasmus

136
00:06:05.560 --> 00:06:08.220
was, so it didn't dare try to call

137
00:06:08.220 --> 00:06:09.780
this, so it's confirming.

138
00:06:10.960 --> 00:06:14.200
It found me, it found the blue, and

139
00:06:14.200 --> 00:06:19.540
then it changed the colour by chaining the

140
00:06:19.540 --> 00:06:21.440
two tools together.

141
00:06:21.660 --> 00:06:23.780
So, it called this tool in order to

142
00:06:23.780 --> 00:06:25.060
call this tool after the fact.

143
00:06:25.460 --> 00:06:28.460
And you can chain tooling a lot of

144
00:06:28.460 --> 00:06:29.140
different things.

145
00:06:29.140 --> 00:06:37.000
So, we could say, change colour to yellow

146
00:06:37.000 --> 00:06:40.840
and then green.

147
00:06:43.740 --> 00:06:45.300
So, now it called both.

148
00:06:45.460 --> 00:06:47.760
We didn't see anything of yellow, but of

149
00:06:47.760 --> 00:06:51.420
course, it just follows instructions as it should.

150
00:06:52.160 --> 00:06:54.720
And again, these are just small party tricks

151
00:06:54.720 --> 00:06:57.060
here, but it could just as easily have

152
00:06:57.060 --> 00:07:00.160
been get the information for order number this

153
00:07:00.160 --> 00:07:03.400
and this in this API, get the weather

154
00:07:03.400 --> 00:07:08.060
for Paris, place this order into the system,

155
00:07:08.380 --> 00:07:14.700
because if we don't provide all information, it

156
00:07:14.700 --> 00:07:17.480
is intelligent enough to say, okay, I also

157
00:07:17.480 --> 00:07:19.200
need this, this, and this in order to

158
00:07:19.200 --> 00:07:19.940
call this tool.

159
00:07:20.820 --> 00:07:23.880
So, tools are very, very powerful.

160
00:07:24.360 --> 00:07:27.420
You just write some code that would normally

161
00:07:27.420 --> 00:07:30.160
be called, and then you create them using

162
00:07:30.160 --> 00:07:31.720
these AI function factories.
