Hi, and welcome to this AI in C#
video on the Agent Framework Toolkit, which is
a series of NuGet packages I've made to
make Agent Framework easier to work with.
In the previous video, we saw about easier
agents.
Now we're going to look at easier tools.
So, if we look at our sample repository
here, we have something called Agent Framework Toolkit,
easier tools.
And all we need to do when we
work with tools is, of course, that we
need to get a list of tools out.
And if we were to do it this,
the regular way, and we had a set
of tools like this, where we have 10
different tools to do file system work, like
getting folders, creating folders, moving files and stuff,
we would end up writing some code like
this.
So we would new up our objects, and
then we would use the AI Function Factory
Create in order to take the various delegates
here, and put in a name and a
description.
We could, of course, begin to use reflection
here in order to do this, but then
it will be more difficult to get some
good names and descriptions in.
So, if we instal the Agent Framework Toolkit,
all we need to do is make a
new instance of AIToolsFactory, or if you use
dependency injection, builder.services.AIToolsFactory, and then you
just say GetTools.
And GetTools have two overloads.
You can either get it by types, or
by instances.
So if you have a tool like this,
where we don't have a constructor, our parameterless
constructor, it is possible to just get the
tools by type of object, and what it
does is it will go in here, and
then will look for attributes.
So these are attributes you can put on
your tools, where you can write the name
and the description.
And both name and description are optional, so
if you just want to quickly have them,
you can just put AITool, and it will
use this as the name.
But if you want to do it right,
you put in a name and a description
as well.
So all I've done to this class is
I've decorated the 10 tools with the AITool
attribute, and then everything just comes out as
tools.
Had my file system tools here needed things
in the constructor via dependency injection, I would
need to new up the instance instead, or
get a dependency injection version, and then I
can just put in the instance instead.
And if I had multiple objects, so for
example, if the AITool factory itself had some
tools, I could put in just multiple objects
for various different tool classes you had.
So much, much more simpler with a one
-liner plus putting in these attributes so the
data is actually closest to the real data
instead of putting in multiple places.
But we can go beyond that because this
can also work with MCP tools, in that
if you add one more NuGet package, agent
-framework-toolkit.tools.modelcontextprotocol, it will
now be able to work with remote tools
and local tools.
So that would be that you simply say
AITools factory, and then you get two extension
methods on it.
I didn't want to put it in the
raw, so you wouldn't have a dependency on
MCP unless you already used it.
So with this way, we can simply get
tools from either remote or a local.
And if you want to get it from
a remote, we would need to give a
remote MCP URL or the entire transport options
if you want to do something more advanced.
But in my case, it's a MCP server
that I do not have anything that needs
to be done extra.
But if I had, for example, an API
key, I could give it in a dictionary.
Or if I had some local tools, I
would just simply need to go in and
give my command.
In many cases, it's just npx, and then
the tool we wanted to do as arguments.
In this case, it's Playwright.
So if we set some breakpoints here, let's
set it up here so we can see
it.
So if we wanted the tools, right now
we have the tools by making them manually.
But if we want to just get them
via 18 Framework Toolkit, we can get them
in exactly the same manner, either as type
or instance, same deal.
And then if we wanted MCP tools, we
could simply use this extra extension method in
order to get the tools.
So it now remotely went up to the
remote MCP and found the tools and the
information about them.
And then if we want to do local
tools using npx, we would get those tools
back, in this case all the different tools
from Playwright.
And then it's just using the tools, in
my case the file tools, and I could
say create 10 files with random fruit names.
And I would end up in my test
class with this.
That will begin to make some tools that
are called GetRootFolders and so on, create the
files, end up with 10 files in my
local tool.
So that's everything there is to it.
Don't sit and do this by yourself when
you can do it so much easier with
the 18 Framework Toolkit like this.
So we're done.
See you in the next one.