Hi, and welcome to this AI in C# video
on the Microsoft Agent Framework.
Today we're going to look into the A2A
protocol, which is something Google have made, where
we have multiple agents talking to each other.
Before we jump into the code, let's quickly
talk a little about what this is.
And if you are familiar with MCPs, they
are very similar to...
A2A is very similar to MCPs, but there
is a bit more of intelligence in here.
Also, if you have seen my video about
an agent calling another agent as a tool,
that would be beneficial in order to understand
this, because that is essentially what's happening, but
where the other agent is just remote.
But what happens is you have a local
app, and you know a URL for another
agent.
That is something called an agent card.
So the remote agent have some kind of
skills.
It's normally tools, but it could also be
that it's very good at something, or use
a special model, or something like that.
So it's just a normal agent, and it
has these tools, and it shows it to,
or exposes that to the local app as
what is called an agent card, where it
tells, I'm this, I'm good at this, you
can use me for this, and so on.
It's sort of like a business card.
If you met a person where you could
find information about what they can do, and
how they can help, and what to talk
with them.
So a little like MCPs list tools.
And then the local app can use these
tools over here through this connection, as if
they were connected directly to it itself.
And what we're about to see in code
is of course happening all on my machine,
but the important thing to remember is that
these two machines can be in different parts
of the world, because they're just talking via
a URL.
So let's jump in and see it in
action.
So in the sample repo, we have agent
to agent here, and we have a server
and a client.
And first I will just show it run,
and then we will go through the code.
And in order to run it, I need
to run both systems, and for that reason
I went into the setup configuration here, and
set up that these two start at the
same time.
So if I run it, and arrange a
bunch of screens here so we can see
it, then we have the server here, and
here we have the client.
And if I ask it, in this case
it knows about some files on my machine.
So if we find the files up here,
you can see there's 10 files in this
folder, so I can ask how many files.
These files are the same as you saw
in my function calling scenario, and it can
see there's 10 files.
And we can go in and say delete
the orange.txt file.
If we do that, it removes it over
here.
So we are about to get information, but
also actions.
And over here, things are happening on behalf
of this, and had this just been one
agent with the skills, meaning had it been
down here in features, our normal function calling,
it would just have been a tool that
we gave to a system, and that would
be it.
But now it's happening over a URL, and
again, the important part is to think the
server here could be in a completely different
part of the world while the client would
be on my machine.
But let's see how it's implemented.
So let's first look at the server, because
without the server, we can't call the client.
So first up, we are using a new
NuGet packet we haven't used before, and we're
using AI hosting A2A ASP.NET Core.
And since this is a console app, we're
still making it work as ASP.NET Core,
so we are actually exposing a URL.
So when I run it and show you
the server, you can see we get this
URL up here, just like if it had
been a web API or whatever.
And as well, we also get something called
well-known agent card JSON.
And the way it works is we go
to our server, and we do the normal
business part as we do with any agents
we have done so far.
We take the Azure OpenAI client.
In this case, we are grabbing the different
tools.
Again, exactly the same as we did down
here in the tool calling advanced, which there's
a separate video on.
And then we're just making an agent just
like we do, and we give them these
tools, and we set up a little function
calling middleware so we can see that the
tools are being called.
You don't technically need tools here.
It could be that it was very good
at understanding something.
It was hooked up to a vector store.
It could be something that you would like
to expose to the world through something more
intelligent than just bringing raw data back.
But then we begin with the agent part,
and the agent part not really here.
We're just setting up that ASP.NET Core
can have a URL.
And then we're building something called an agent
card.
Again, the agent's business card.
So this is what is being exchanged between
the two, the client and the server.
So we tell, hey, I'm an agent.
I'm called files agent.
I can handle requests related to files.
I'm version 1.0. My input modes are
text, and my output modes are text.
Again, this protocol has lots and lots of
other features, authentication and so on, but we're
just diving into the basics here.
We're not streaming.
We're just giving data fullback, and we're not
sending any notifications because something can also be
long running and such things like that.
But we have one skill, which we call
an agent skill, which is just that we
are file experts, and we can do the
questions about the files.
We can give some tags so different agent
cards can be categorised and stuff, and we
give a small example on how we work.
And then we give the URL that we
need to be.
And the tools themselves are fairly simple.
It's just create folder, delete folder, just normal
C-sharp code.
And again, if you want to know about
this, see the tool calling advanced for full
details.
The final thing we do is just like
a map get, map post in a minimal
API.
We do a map A to A, and
we tell this is the agent we are
exposing.
Here's the part we are exposing it, meaning
just the root.
Here is the agent card, and here is
the well-known agent card, so it knows
this information when it needs to work.
And then we are just running, meaning we
are starting the little mini web server in
our console app here.
On the client side, it is fairly simple.
In here, we instead use the A to
A instead of hosting A2A, because
we are the consumer.
And we are going to start, because I'm
starting at the same time, I'm just waiting
one second just to be sure that the
server is ready to begin to be consumed
by the client.
Then we do something called an A to
A card resolver where we take the URL.
Again, this could be a remote URL.
And we get that, and the agent framework
just gives us and give me that as
an AI agent, and we're done.
Because then we have an AI agent, we
could begin to use that as such.
But what we are doing is we're giving
it as a tool to an agent that
we control over on our side.
That agent is just like normal.
We give it instructions like normal, and we
just make a chat loop.
So nothing over here is different other than
this, which we then give as a tool.
Beyond that, it's just normal agent framework like
we normally do.
So there's not much to this.
It's just this exchange between the two that
this running in one process can get an
agent that can be used as skills in
another process.
So when we again look at it here,
and the server, let me try to get
them a little more side-by-side here,
this and the files, then we could, for
example, say group the files into folders
based on their colour.
So now it begins to work over here.
It found the root folder.
It found the content of each file and
so on, and it wants us to confirm.
We want to proceed.
But that is just AI.
Had it been in the same root, then
the same thing would have happened.
But right now, it's doing its work and
putting in banana and lemon and pear into
the yellow and so on.
So it's just AI, and again, it's just
as if we had one agent without two,
but the cool thing is, of course, that
these are in two different locations in the
world.
In my case, it's two different processes that
talk with each other, but it could have
been two different servers, one sitting in US
and one sitting in Europe, talking to each
other.
And again, this sounds very much like MCP,
but you have more.
You could technically just make a tool called
files tool in MCP and have an AI
work behind the scenes, but it's not really
meant for that.
This is more meant for that.
It's bigger things.
It's more advanced things that are happening.
So if you're using one or the other,
I will probably use MCP more than A2A,
but I can't see a world where A2A
makes sense.
So that is everything.
Very simple to do.
A little complex topic, but behind the scenes
it's actually very simple that it's just these
two lines of code that give us an
agent that we can use as a tool.
That's it.
Thank you for attending.