And so here we are back in cursor and in the number five folder for Autogen.
And going to lab for Autogen Core Distributed.
I'm only giving a teaser of what this is about because, uh, I'm to be honest, I'm I'm not even sure
how relevant this is to, to many, many of you.
So I, you know, I'm going to give a flavor for it.
If you do want me to go into more detail, if you want more content, then please do.
Do, uh, send me a note, let me know.
I can I can always go deeper into this, but I don't want to hold, uh, others up.
Um, and, um, I think that particularly as Microsoft is saying, that it's, it's still experimental.
It's better to get a flavor for it.
Okay.
So I've done this and there's actually two different ways that I want to show you this working.
Uh, one of them is what I'm calling all in one worker.
And one of them is with multiple workers.
And so I've got this flag here that you can set from true to false.
And we're going to go through it once with it true, and then once with it at false.
And you'll see what I mean.
So we do some imports and we load the dot env.
And we start with our message, uh, class as as before, which I'm going to clear all outputs and restart.
Do this again.
Sorry.
Uh.
Run this.
I start as before, with our message class defining this thing.
It's the sort of analogy to the state with with Landgraf, although it's to to describe how we interact
between our agents.
Okay.
And now I mentioned that the distributed runtime consists of these two things.
One of them is the host.
And this is how you create the host Autogen runtimes, gRPC, the gRPC worker agent runtime host.
So this is something which uses gRPC, the remote procedure called technique to be able to to send messages.
And this host will run on my local host on port 551.
And I will start it with this.
So this is now going to be a running host.
And gRPC of course, is a cross-language, uh, approach for sending, uh, A function calls between
different languages, and it's super powerful.
It's used in many different, different places.
You can think of it.
It's like it's like making rest HTTP calls, except you're able to call directly from one function to
another, and gRPC is used all over the place where, uh, where interactive messaging needs to be implemented.
That crosses process boundaries.
So that is gRPC.
We've started a host and it is running.
And what we're now going to do is, first of all, reintroduce an old friend.
We're going to bring back the Autogen Sirpa tool using our Sirpa search API.
And the reason we're the way we're doing it is through we're we're doing it through Lang Chain.
So we're introducing a few things from, from before, uh, so we uh, we create the Google Serp API
wrapper.
We create a Lang chain tool for internet search.
Uh, this is the same tool that we used last week, and now we wrap that in a long chain tool wrapper
so that it becomes an autogen tool.
And there it is, an autogen tool for searching the internet using the Sirpa API.
So originally I was going to have this play rock paper, scissors in a distributed way, but I realized
that it's a bit frivolous and we should be trying to at least have some commercial footing here.
So I was going to make it do the the stock price comparison.
And I thought, you know, we've already done some, some of them and we've got a whole week coming
on that.
So instead I've gone with this trying to we're trying to make a business decision.
And let's say that business decision is whether we should use Autogen in a new AI agent project.
And we want to have a two different agents, one agent research the pros of autogen by using web searches
and the other agent research the cons, the negatives, the drawbacks.
Uh, and so the two agents will go off and do their analysis, do their searching, and then they will
come together and we will have a judge agent that must make a decision whether to use Autogen for a
project.
Uh, and, uh, it must be based purely on research from its team, from its agent team.
Respond with the decision.
Brief rationale.
So this is sort of by analogy with the rock paper, scissors.
We've got instruction one for player one, instruction two for player two.
And the judge that will make the call.
All right.
And so now we have our agents.
And this is again by analogy with last time.
It's really very similar.
Player one I've kept calling it player one because I you know, this really is a copy paste job basically.
Uh, except I'm using GPT four or mini for both because I thought it wasn't fair to use, uh, a llama,
we didn't get the same the same quality.
Uh, so we've got GPT four or mini, um, and, uh, so we are this is the the the the player one routed
agent, and we are passing in, uh, here we're using the Autogen gen super tool so that that is what
we're doing.
I realize even looking at this, that we don't actually need a player one and player two class.
This could be done in a simpler way with just one.
Uh, so uh, that's an obvious point.
But anyways, for whatever reason, we we've got two, two agents here, two different types of agent,
uh, that uh, but we're going to prompt it for whether it should find the pros or cons, but you could
imagine you could switch in a different model here if you wanted, if you wanted to have deep seek,
do one of the research.
So I'll keep it as two separate agents in case you choose to do that.
Um, okay.
So other than that, this is exactly the same.
Other than supplying the search tool, reflecting on tool use, everything here is the same.
Uh, it delegates to its underlying LM and the judge is the same.
It also has a delegate, an underlying LM, and in its message handler, the the method that's decorated
message handler, it collects the two messages that we set up above.
It puts them, it finds the two agents player one and player two.
It uses this lookup and then it calls send message and this code is identical.
This is all exactly the same as the code we just used yesterday with the runtime.
That was that was local.
And so the reason I do this, I want to show you that without changing anything I didn't.
There's nothing here about it being distributed.
It doesn't know that it's distributed.
This this could still be doing rock, paper, scissors.
It would be the same thing.
We're just calling self dot send message.
And what we don't realize is this is running remotely and it's running on a, on a runtime that's running
on a port here.
And uh, it's going to be the, the Autogen core is going to be handling calling the right function
in the right, uh, agent.
So these calls that appear to just be simply, uh, I'm calling send message, uh, right here, I call
send message.
And that is going to result in this handle my message getting called.
And before that was just directly like some if statements in Python that we're just making that call.
Now this is going to be happening using gRPC remotely orchestrated by this distributed runtime.
But that is completely unknown to us as far as we're concerned.
We're just doing exactly the same thing.
And that is the power of Autogen core distributed that we don't have to worry about the fact that these
are different processes running, and they could be written in different computer programming languages.
And all of the stitching together of messages is happening for us, just based on looking up player
one and player two.
Um, everything is happening.
So enough prattle.
Let's run that.
Okay.
And this is where this is where the meat happens.
So I've got two different implementations that I want to show you.
And we're starting with all in one worker.
And here's how it works.
We we, uh, first of all, say that we want to create a new worker agent runtime, and we point it
at our host.
This is the host.
So this will be a new runtime connecting to that host and we will start that worker.
We are then going to register, uh, three agents with that worker.
Agent one a player one, player two.
And the judge.
Here they are.
Player one.
Player two, and the judge all being registered with this worker with this gRPC worker agent runtime
at that host.
And there we go.
There is a player one, player two.
And the, the the judge.
These are the factories that will create them.
And we are now um, now we, uh, collect the agent ID of the judge.
So I'm going to run this.
And because this is set to true, only this code here is going to run and it's done.
And now this is the same as before.
It's just the same thing we're going to send go the go message to the agent ID that is that I've just
that I set here to the judge, uh, and let's see what happens.
So it's thinking stuff is happening.
I'm still thinking.
Messages are flying.
It's what we hope is happening is that OpenAI, GPT four, and Minnie is coming up with pros and cons
through two separate agent calls.
And then a judge has put it all together, and this is what we get back.
Pros of Autogen.
Here are some advantages of using Autogen in your AI agent projects.
The cons are right here.
Uh, limited AI capabilities, less customizable, less structured potential bugs and performance issues
with lower end models.
Okay, but based on this, basically there's also some, uh, some strengths that appears, uh, memory,
coherent context, ease of development, scalability, which is what we're experiencing and versatile
applications.
And the decision is recommend using Autogen.
So the uh based purely on this research, that is the decision.
And with that we will then stop our workers and we stop our host.
And we have just experienced distributed autogen core.