WEBVTT

1
00:00:00.520 --> 00:00:02.980
Hi, and welcome to this AI in C#

2
00:00:02.980 --> 00:00:06.560
video on the Agent Framework Toolkit, which is

3
00:00:06.560 --> 00:00:09.840
a series of NuGet packages I've made to

4
00:00:09.840 --> 00:00:12.400
make Agent Framework easier to work with.

5
00:00:13.020 --> 00:00:15.400
In the previous video, we saw about easier

6
00:00:15.400 --> 00:00:15.960
agents.

7
00:00:16.340 --> 00:00:18.340
Now we're going to look at easier tools.

8
00:00:23.680 --> 00:00:29.900
So, if we look at our sample repository

9
00:00:29.900 --> 00:00:32.800
here, we have something called Agent Framework Toolkit,

10
00:00:32.840 --> 00:00:33.560
easier tools.

11
00:00:35.160 --> 00:00:38.240
And all we need to do when we

12
00:00:38.240 --> 00:00:42.320
work with tools is, of course, that we

13
00:00:42.320 --> 00:00:44.340
need to get a list of tools out.

14
00:00:45.240 --> 00:00:47.480
And if we were to do it this,

15
00:00:48.240 --> 00:00:52.260
the regular way, and we had a set

16
00:00:52.260 --> 00:00:54.340
of tools like this, where we have 10

17
00:00:54.340 --> 00:00:58.560
different tools to do file system work, like

18
00:00:58.560 --> 00:01:01.940
getting folders, creating folders, moving files and stuff,

19
00:01:03.060 --> 00:01:05.540
we would end up writing some code like

20
00:01:05.540 --> 00:01:06.020
this.

21
00:01:06.840 --> 00:01:09.620
So we would new up our objects, and

22
00:01:09.620 --> 00:01:13.260
then we would use the AI Function Factory

23
00:01:13.260 --> 00:01:17.760
Create in order to take the various delegates

24
00:01:17.760 --> 00:01:21.760
here, and put in a name and a

25
00:01:21.760 --> 00:01:22.140
description.

26
00:01:24.780 --> 00:01:27.380
We could, of course, begin to use reflection

27
00:01:27.380 --> 00:01:29.800
here in order to do this, but then

28
00:01:29.800 --> 00:01:31.600
it will be more difficult to get some

29
00:01:31.600 --> 00:01:33.400
good names and descriptions in.

30
00:01:34.760 --> 00:01:40.240
So, if we instal the Agent Framework Toolkit,

31
00:01:41.440 --> 00:01:45.140
all we need to do is make a

32
00:01:45.140 --> 00:01:50.500
new instance of AIToolsFactory, or if you use

33
00:01:50.500 --> 00:01:55.780
dependency injection, builder.services.AIToolsFactory, and then you

34
00:01:55.780 --> 00:01:56.760
just say GetTools.

35
00:01:57.820 --> 00:02:00.400
And GetTools have two overloads.

36
00:02:00.400 --> 00:02:04.220
You can either get it by types, or

37
00:02:04.220 --> 00:02:05.180
by instances.

38
00:02:05.760 --> 00:02:07.680
So if you have a tool like this,

39
00:02:08.539 --> 00:02:13.340
where we don't have a constructor, our parameterless

40
00:02:13.340 --> 00:02:17.140
constructor, it is possible to just get the

41
00:02:17.140 --> 00:02:23.580
tools by type of object, and what it

42
00:02:23.580 --> 00:02:27.100
does is it will go in here, and

43
00:02:27.100 --> 00:02:29.180
then will look for attributes.

44
00:02:29.180 --> 00:02:31.560
So these are attributes you can put on

45
00:02:31.560 --> 00:02:34.240
your tools, where you can write the name

46
00:02:34.240 --> 00:02:35.220
and the description.

47
00:02:36.160 --> 00:02:38.600
And both name and description are optional, so

48
00:02:38.600 --> 00:02:40.380
if you just want to quickly have them,

49
00:02:40.700 --> 00:02:42.720
you can just put AITool, and it will

50
00:02:42.720 --> 00:02:44.220
use this as the name.

51
00:02:44.840 --> 00:02:46.280
But if you want to do it right,

52
00:02:47.060 --> 00:02:49.340
you put in a name and a description

53
00:02:49.340 --> 00:02:49.820
as well.

54
00:02:50.960 --> 00:02:54.300
So all I've done to this class is

55
00:02:54.300 --> 00:02:58.760
I've decorated the 10 tools with the AITool

56
00:02:58.760 --> 00:03:03.220
attribute, and then everything just comes out as

57
00:03:03.220 --> 00:03:03.600
tools.

58
00:03:05.320 --> 00:03:11.360
Had my file system tools here needed things

59
00:03:11.360 --> 00:03:14.700
in the constructor via dependency injection, I would

60
00:03:14.700 --> 00:03:17.000
need to new up the instance instead, or

61
00:03:17.000 --> 00:03:22.140
get a dependency injection version, and then I

62
00:03:22.140 --> 00:03:24.240
can just put in the instance instead.

63
00:03:25.040 --> 00:03:29.140
And if I had multiple objects, so for

64
00:03:29.140 --> 00:03:31.520
example, if the AITool factory itself had some

65
00:03:31.520 --> 00:03:35.480
tools, I could put in just multiple objects

66
00:03:35.480 --> 00:03:38.360
for various different tool classes you had.

67
00:03:39.800 --> 00:03:43.300
So much, much more simpler with a one

68
00:03:43.300 --> 00:03:48.660
-liner plus putting in these attributes so the

69
00:03:48.660 --> 00:03:51.440
data is actually closest to the real data

70
00:03:51.440 --> 00:03:53.960
instead of putting in multiple places.

71
00:03:56.350 --> 00:03:59.650
But we can go beyond that because this

72
00:03:59.650 --> 00:04:03.370
can also work with MCP tools, in that

73
00:04:03.370 --> 00:04:06.590
if you add one more NuGet package, agent

74
00:04:06.590 --> 00:04:11.490
-framework-toolkit.tools.modelcontextprotocol, it will

75
00:04:11.490 --> 00:04:14.290
now be able to work with remote tools

76
00:04:14.290 --> 00:04:15.930
and local tools.

77
00:04:17.070 --> 00:04:19.829
So that would be that you simply say

78
00:04:19.829 --> 00:04:23.650
AITools factory, and then you get two extension

79
00:04:23.650 --> 00:04:24.490
methods on it.

80
00:04:25.070 --> 00:04:26.630
I didn't want to put it in the

81
00:04:26.630 --> 00:04:30.050
raw, so you wouldn't have a dependency on

82
00:04:30.050 --> 00:04:33.230
MCP unless you already used it.

83
00:04:34.730 --> 00:04:37.810
So with this way, we can simply get

84
00:04:37.810 --> 00:04:42.030
tools from either remote or a local.

85
00:04:42.930 --> 00:04:44.490
And if you want to get it from

86
00:04:44.490 --> 00:04:47.470
a remote, we would need to give a

87
00:04:47.470 --> 00:04:51.570
remote MCP URL or the entire transport options

88
00:04:51.570 --> 00:04:53.510
if you want to do something more advanced.

89
00:04:54.150 --> 00:04:57.170
But in my case, it's a MCP server

90
00:04:57.170 --> 00:05:01.650
that I do not have anything that needs

91
00:05:01.650 --> 00:05:02.530
to be done extra.

92
00:05:02.950 --> 00:05:04.570
But if I had, for example, an API

93
00:05:04.570 --> 00:05:06.630
key, I could give it in a dictionary.

94
00:05:09.250 --> 00:05:11.930
Or if I had some local tools, I

95
00:05:11.930 --> 00:05:14.090
would just simply need to go in and

96
00:05:14.090 --> 00:05:15.450
give my command.

97
00:05:16.670 --> 00:05:19.370
In many cases, it's just npx, and then

98
00:05:19.370 --> 00:05:22.060
the tool we wanted to do as arguments.

99
00:05:22.470 --> 00:05:23.830
In this case, it's Playwright.

100
00:05:25.330 --> 00:05:30.360
So if we set some breakpoints here, let's

101
00:05:30.360 --> 00:05:32.400
set it up here so we can see

102
00:05:32.400 --> 00:05:32.660
it.

103
00:05:35.910 --> 00:05:37.710
So if we wanted the tools, right now

104
00:05:37.710 --> 00:05:40.970
we have the tools by making them manually.

105
00:05:42.070 --> 00:05:44.830
But if we want to just get them

106
00:05:44.830 --> 00:05:49.590
via 18 Framework Toolkit, we can get them

107
00:05:49.590 --> 00:05:55.090
in exactly the same manner, either as type

108
00:05:55.090 --> 00:05:57.390
or instance, same deal.

109
00:05:58.630 --> 00:06:01.630
And then if we wanted MCP tools, we

110
00:06:01.630 --> 00:06:09.150
could simply use this extra extension method in

111
00:06:09.150 --> 00:06:10.230
order to get the tools.

112
00:06:10.450 --> 00:06:13.650
So it now remotely went up to the

113
00:06:13.650 --> 00:06:17.770
remote MCP and found the tools and the

114
00:06:17.770 --> 00:06:18.890
information about them.

115
00:06:20.450 --> 00:06:22.570
And then if we want to do local

116
00:06:22.570 --> 00:06:28.910
tools using npx, we would get those tools

117
00:06:28.910 --> 00:06:31.330
back, in this case all the different tools

118
00:06:31.330 --> 00:06:33.650
from Playwright.

119
00:06:34.950 --> 00:06:39.190
And then it's just using the tools, in

120
00:06:39.190 --> 00:06:41.650
my case the file tools, and I could

121
00:06:41.650 --> 00:06:45.110
say create 10 files with random fruit names.

122
00:06:46.570 --> 00:06:53.490
And I would end up in my test

123
00:06:53.490 --> 00:06:54.630
class with this.

124
00:06:55.870 --> 00:06:59.070
That will begin to make some tools that

125
00:06:59.070 --> 00:07:02.370
are called GetRootFolders and so on, create the

126
00:07:02.370 --> 00:07:05.030
files, end up with 10 files in my

127
00:07:05.030 --> 00:07:05.770
local tool.

128
00:07:07.470 --> 00:07:09.510
So that's everything there is to it.

129
00:07:09.510 --> 00:07:13.270
Don't sit and do this by yourself when

130
00:07:13.270 --> 00:07:15.410
you can do it so much easier with

131
00:07:15.410 --> 00:07:17.710
the 18 Framework Toolkit like this.

132
00:07:18.870 --> 00:07:19.390
So we're done.

133
00:07:19.910 --> 00:07:21.010
See you in the next one.
