Hi and welcome to this AI and C-Sharp video on the Microsoft agent framework
and today we are going to look into yet another new format from Anthropic which
is called agent skills. Agent skills is a way to try and save tokens, have things
run more offline and in general just work better and they have made a site
called agentskills.io and they have open-sourced everything but they use
internally and it's adopted by many and it's mostly aimed at the various coding
tools but you can also use it in normal AI. So when I saw this the first time
and saw that you need to have some skills and stuff I thought I wanted to
make an integration into it, into my agent framework toolkit as well. But
let's first see what it's more is in general. So what is agent skills? According
from the agentskills.io it's a simple open format for giving agents new
capabilities and expertise. Agent skills are folders of instructions, scripts and
resources that agents can discover and use to do things more accurately and
efficiently. Fancy words. In reality it is a folder on your hard drive and inside
that you will have some subfolders and each of these subfolders will be skills
and the way a skill is defined is that it has a skill.md file. Such a skill.md
file you can see over here where it has header where you give it a name and this
name should match the folder in order to follow the spec and you need to have a
description where you put in what the field is. A little like a tool description
or a tool name. And then you have full control you can just write somebody and
in this case I'm using Markdown but you can use whatever there's no rules on
what after the header how it should look. So this one is a skill with just the
skill file that tells a little about in this case a pirate called C-Dog John who
is aimed at kids and telling a little about how he should react. We can also go
into things that you can run scripts with this. So for example here is a
skill called secret formulas and one of the secret formulas is inside this
pi script that we can execute on the fly. And up here a more corporate version of
an employee handbook where we have a skill that is the employee handbook and
then further references underneath. Because you can have soft folders like
this like script folders, reference folders, assets folders and you can
essentially put everything you want in here but these are the main things that
happens. There's a bit more information over here like metadata license and so
on that are optional. But this is what it is. Let's see it in action. So in my
samples as always I have something called agent skills. And before we go
into the code let me quickly show you the three skills in more details. So we
already saw this skill which is just a persona of a pirate. We have the secret
formula skills which just tells that we have a formula and it should use an
execute pi tool in order to run it. And the final one is just a handbook where
it references the other reference documents. Something about benefits,
something about cultures and values for a made-up company, something about hours
and attendance and something about the pay. So that is what it essentially is.
It's just a folder structure. So if we look at in normal file explorer we just
see the three folders with the references, the scripts and so on. So
nothing fancy, nothing major, nothing special here. But of course we want to
use them in AI and this I could give to for example Codex that can do skills,
Cloud Code that can do skills and so on. But if we want to run them ourselves we
need to parse these files and turn them into tools and instructions. And in order
to do that I have made a new NuGet package called agentskills.net.
I have referenced it here which is technically not needed because it's also
part of my Agent Framework Toolkit as a dependency on that. So you
either can use it directly with the Agent Framework Toolkit no matter what
provider you choose, or you can reference it directly if you don't want to use the
Agent Framework Toolkit. It's NuGet, it's MIT like normal, so nothing special there.
But let's see how we do this then. Let's close all these and look at the program.
So what we do is we just clear the console and get our normal Agent Factory
from Toolkit, but you can of course also use the normal Microsoft Agent
Framework tools raw if you want, because this is just defining skills. And then we
have a new class called AgentSkillsFactory which you can just
new up, or there is a dependency version of it if you wish to do that. And on that
factory you have one method and that's called getAgentSkills. And you simply
just need to, as a minimum, give a folder path. I will go into the more advanced
options after we've seen the first pass through here. But we just need to give it
here is my subfolders, pass them for me. So let's have this run and see this in action.
So when we get our skills, we will see that we will get three skills, and there's
an exclude skills lock if there's any of the skills that are invalid in terms of
structure and stuff, if it doesn't have the right format in the skills MD and so
on. But each skill have various things, allow tools, the body, the folder it's in,
what reference files it have, and so on and so forth. So these are the raw skills
that we can access,
and the locks. We can then take these skills and get instructions that if it's
the desired format into instructions. So we could see here that we can make some
XML-like structure here that tells the default about each skill, the name, the
description, and the location for all three. And we can use this in the agents
instructions as normal. We can then make them into tools, and in this case I'm
making it into three different tools. I'm making into a get available skills, a get
skill by name, and a read skill file content. So the first one can list all
the skills, the second one can show the exact skill, and the third one can read
any of the reference files or script files. I also make a Python runner script
here, and that's not included in the package because I don't want to control
how you secure Python, or if you even want to have Python be able to run, or
even have Python installed. So this is just for the sample, where it just takes
a Python file and run it, nothing special, and give the output. I made chatGBT
make this for me. So we get the tools, and then we have the normal agent as always.
We make a chatGBT 4.1 mini here. It's a tool, and we give it what skills it's
available, and we tell it, hey, don't call the read tool before you have
actually asked for the skills, so you know what the files are called. We add
the tools, and we put in a little thing about, so we can see what tools are being
called. Then we make the normal chat loop, and nothing special there. So if we go in
and say, what skills are available, it will call a tool to get available skills,
and it will get back that it has the three skills. And then we can, of course,
use these skills. So let's start by trying to use the pirate. So I can just
say, enter pirate mode. It will understand that. And then it will call
that specific skill and get, essentially, on the fly, this information. So on the
fly, we have now loaded that in via a tool, like normal, and we are now in
pirate mode, where we had the direct instructions. And yes, we could have put
those instructions up here, but then we could not have multiple ways of doing
things. It would be filling up even when we say hello, and stuff like that.
And we can now talk to John the pirate here. Do you drink rum?
And in the instructions, it was told not to talk about such things,
because it's kid-friendly, and so on. So it is now being controlled as a pirate.
If we restart again, just so we have a clean slate, and we should get our
things over here. We can also use the employee handbook. So, for example,
we could just go in and say, is maternity leave paid?
So what's happening now, it's getting the tool by name.
And the reason why it could do that directly was because it was put in the
instruction what each of the tool are called. And it then looked both in the
benefits part of the system, and the pay parts of the system.
So it, on the fly, read what was in this file, and what was in this file.
Of course, it got all that was here, so it knew that it had those available.
And it came back and talked about maternity leave is typically benefits.
It's briefly mentioned over here in the system.
If we try the final one, which is a bit more advanced,
in that we are going to run this Python script, which just gives back 42.
So it's not a very secret formula, but if we go in and see,
we can now go in and say, what is the result of the extra secret formula?
So what happens here is it's going in, getting the skill by name,
the secret formula. So it reads this file on the fly,
and it knows that there is a secret formula called the extra secret formula.py.
Go back to this one, and get rid of that one.
And on the fly, it actually executed the Python,
and just gave the file directly.
So it's not like we used a lot of tokens on doing that, sending it out on the fly.
And right now, the Python file was very small, but it had been very, very big.
We would not have spent tokens on using those,
because we only referenced it by the file name.
And had it been 10 lines, or 100 lines, a thousand lines of Python,
we would still have only used the tokens for the tools.
And it come back, and says that the secret formula is 42.
So this is the out-of-the-box experience for the AgentSkillFactory,
but it can do much, much more.
So let's go a little more details-oriented,
in that in here, for getting the skills by itself,
we have some options as well.
So we have two options.
We have the validation rules, and by default, this is set to be strict.
So if a tool doesn't follow the correct format,
and there's various formats for this.
So for example, let's say that this one doesn't.
One of the things that are not allowed is double quotes like this, for some reason.
And we could say there's no description.
So if we do it like this, and get our skills...
we will see that we only get two skills now.
And the speak-like-a-pirate one was excluded,
because it didn't match the parent directory,
and must not have consecutive hyphens.
So those are just rules that they have chosen,
and by default, this will try to be strict.
But if you want to let things like that through,
you can go down to lose,
where it's only looking for, does it have a name?
If it have a name, it's okay, else we will ignore it.
Or you can completely turn this on, and then off,
and then even the name is not needed,
then it will take the folder name,
and choose as a name for the system.
So you can get things out.
If someone cannot follow the rules, you can loosen the rules up here.
The other thing you can do is do filtering.
So for example, you just get a bunk here,
and in here, you can return true, if that specific tool,
because this will be called for each single tool,
if it should be included, or if it should not be included.
So for example, we could go and say,
skills.scriptfiles.count equals zero.
So now it will only return skills that doesn't have any script files.
So if we run it again,
we will now see that our skills, we only have two again, which is there.
Employ, and speak like a pirate,
and it says here the SQL formula was excluded, as it did not hit filter.
We could have turned it the other way around,
and we could have gotten that we only got one,
and two of them was thrown away, because they didn't have script files.
So you have full control over everything that is about this,
so it could say if the description mentions a certain word,
or the license is not MIT, or whatever you want to do.
So those are the options for getting the skills themselves.
Then there's the instructions. There's no special things about that.
And then there's the tools, because the tools can get extra setups.
First of all, you can get a strategy for how you want to have these tools.
And by default, it's using the available skills and lookup tools that we just saw,
but you can also say that each skill is a tool.
So if we do that,
let's set a breakpoint here,
we will now see that we get four tools.
We get the Employee Handbook as a tool by itself, the Secret Formulas as a tool,
the Speak Like a Pirate, and our Read Skill File Content,
which is out-of-the-box default every time.
So then we turn each skill folder into its own skill.
This might not be the best if you have a lot of skills,
because then you are ending up spending a lot of tokens.
The default is that you only get the two available lookup tools
and the Read File tool by default,
because then, no matter how many skills you put in,
you will only end up with three tools.
What you can do as well is control some extra options here.
So here we can control, for example,
if we want to include the tool for Read Content.
If we don't trust the system to read any files,
by default, this tool is actually set up
that it can only read the files that are in the skills.
So behind the scenes, when it runs the tool,
it will actually check, is it any of the files that are in any of the skills,
and if not, it will say it's not a valid file.
So it's not dangerous to do, other than what skills you have,
and it can only read.
But if you don't want it, you can simply go and say False here,
and then we only get the two tools,
to Get Available and to Get Skill By Name.
Similar, you see these tools, but you can go in
and choose that they should be called something else.
So Get Available Tools could be called Boo.
So they are controllable,
if you don't like the names I have chosen.
The same, you can change the description, and so on and so forth.
So that's for all these tools and description here.
And the final thing you can do is,
you can choose how each tool are being generated,
in that you can choose, should it include the description,
should it include the metadata,
should it include the files lists, and all these kinds of things.
And behind the scenes, each of the tool,
we look in here, we can say AgentSkills.
Just take one of the skills.
We can go in and say Get Definition,
and we can also validate the result, if we want to validate it.
But we can get the definition, and then you will also be able to see
how each tool are being presented to the LLM.
So if we set a breakpoint here,
and run it,
you will see that each skill will be shown as a skill,
with the name and description, instructions,
and then the files, in this case the reference files,
but if there was other files, and so on.
So each of them are being presented in this manner,
to the LLM, on the fly.
And if you don't like that, you can, of course,
just go in and use the raw skills, build your own definitions,
build your own tools, if you want to.
But out-of-the-box, I've made it as opinionated as possible,
and as I would use it default.
So if we just go back to this,
we get the three out-of-the-box tools.
We get the good names, in my opinion.
Again, if you don't like them, you can overwrite them.
And from that, we just need to build our skills,
and use them in the system,
and everything is up and running.
So that's everything.
See you in the next one.