Okay, so now we get to the meat of Autogen core.
We are going to create a runtime, a single threaded agent runtime it's called, which is a standalone
runtime running on my computer, which as it says, will handle agents in a single threaded way.
And the first thing that we're going to do is register.
We call register on the agent itself to say, I want you to register yourself with this runtime.
Now, this isn't creating an agent.
This is just saying you are a type of agent.
And I want you to tell the runtime that you are a type of agent that can be spawned, you can be created,
and you are a type of agent of type simple agent that's going to be your type.
And this, this thing here, this is a function which can generate new versions of you.
It can instantiate you.
It is a factory.
And you pass that in as well.
And so I will do this.
It's now created a runtime and it's created a type of agent called a simple agent.
We haven't actually yet built any of these.
We haven't instantiated one.
But the as a type of agent is now a known thing to our runtime.
Our runtime knows that there are such things as simple agents.
And we're now going to start our runtime.
It is now running.
It is a it is a proper runtime.
And now we are going to uh, we're going to first of all create an agent ID object to identify an agent.
And we'll we'll do this properly.
We'll say agent ID equals that, that is an ID that would identify this.
And we are going to say that we want the default agent.
Uh, because, because that, that will then, uh, we'll make sure that we have an agent created,
and then we're going to send a message to, we're going to send a message to the, to the agent, which
is called simple agent, The default ID and we're going to send a message.
Well hi there to it.
And then we will print whatever comes back.
So any ideas what's going to come back I wonder.
Uh, so uh it replied this is simple agent default.
So it's simple agent is its type, which is the same one we registered and it default is the, uh,
the, the id uh, and it said, you said, well hi there.
And I disagree.
Charming.
Uh, and that is uh, that's it.
So there is a demo of auto gen core and that's what auto gen core does.
And putting in agent functionality like having code in there that calls LMS.
That's your job or my job.
That's not auto gen core's job.
What it's there to do is to handle the passing of messages around by looking things up based on their
type and their ID, and that's what it does.
So now I'll show you one which has an LM behind it, but it shouldn't be any surprise to you because
it's just the same infrastructure.
The fact that we're calling an LLM is is almost of no consequence to, to, uh, the Autogen core framework.
So what we're going to do is we're going to make a slightly more interesting one called my LM agent,
still a subclass of rooted agent.
And we're going to use a proper LM.
And we could just call OpenAI directly using OpenAI dot create.
We could just call the Python client library.
But we can also use Autogen agent chat and we might as well since it's autogen week.
So this is the same kind of thing, a subclass of rooted agent that's going to be two functions again
init and handle my message.
So the init just just calls the superclass.
But it then creates a model client.
But this could be doing anything.
But this is the Autogen agent chat way.
We're going to create one of these things, a GPT four mini model client.
And we're going to set a field called underscore delegate, which we're just sort of holding on to.
This is this is the the underlying.
This is what our agent object is going to delegate to when it actually needs some code, some, some
an LLM to run.
And we could have anything we want.
We could, we could do we could reply back with random things or we could create an instance of assistant
agent.
And that's what we're going to do.
And that's where we put in.
If you remember, when you create an assistant agent, there's the name of the agent and there's the
model client, and there it is.
And as a result in underscore delegate underscore often used to show sort of like private secret, uh,
variables that other people should know about, like, like private in the, in the Java world.
Um, so the this is being set to an assistant agent.
So, uh, now we just have to write our message handler.
And as I say, it can be called anything you like.
I'm calling it handle my message type.
Um, and that's really to sort of draw your attention to the fact that what matters is what type of
object comes in the message field, because Autogen core will automatically route messages to agents
that should receive them based on the the finding a handler that that looks for a message of that type.
That's how it works.
That's the clever routing that it does.
And by the way, you can send a message direct to an agent, which is what we're doing right now.
But it also has a whole kind of pub sub thing there where you can subscribe to topics and you can publish
out messages to lots of agents that are all interested in one particular topic.
So the whole process of dispatching messages to the right agent and then calling the right handler,
that's the clever stuff.
That's what it does well.
And why why we use a framework like this rather than coding it ourselves.
But for some of these examples, it's pretty trivial.
So we could equally code it ourselves.
But you can imagine that this is done in a way that can be scaled and distributed.
So anyways, handle my message type.
Uh, as long as, uh, message is sent to this agent with the ID and and type, and that the object
that's sent is of this type, it will arrive at this function.
And I'm going to say that I received a message and print the content.
Then I'm going to now now this is confusing.
This object here text message looks subtly different to this object here.
Message.
Uh, do you know what's going on here?
This text message is text message from the, um, autogen.
It's this thing here.
It's the agent chat messages.
The text message.
The same thing we were using yesterday and the day before when we were interacting with agent chat agents.
So this is a autogen agent chat, uh, message, which can be a bit confusing.
And you might.
Yeah, there are ways you could you could get around that by, by giving it a different you can say
like as agent chat text message if you wanted to to like make it so the code is a little bit clearer
and you're distinguishing between the Autogen core and the Autogen agent chat.
All right.
Anyways, so sorry.
Back we go.
So we create the sort of text message that you need for Autogen agent chat passing in the content of
our message and the source is user.
And this is the onmessage that we call in agent Chat land with this text message and the cancellation
token if you remember that thing.
And then we get back the content.
We say that that was the reply.
And we return a new instance of message of our message, with the content being that reply.
I hope you followed all that, or at least got enough of an idea of it.
Let's give this a shot.
Let's create a new runtime, a single threaded agent runtime, standalone runtime.
We're going to register two agents the simple agent and the LM agent.
The new one, Simple Agent, isn't really an LM at all.
It just disagrees with whatever it's told.
And LM agent is actually going to dispatch through this underscore delegate down to a true gpt4 mini.
So we're going to start the runtime.
Then we are going to send a message.
Hi there to the real agent.
And with whatever it replies we're going to send that.
We're going to forward that on to the other agent, to the simple agent and see what comes out there.
So the LM agent received hi there.
And it said hello, how can I assist you today?
A classic GPT four minion response.
And, uh, the simple agent said, this is simple agent default.
You said, hello, how can I assist you today?
And I disagree, and there you go.
Um, and with that, we will we will stop this pantomime.