Okay, so here we are back in Cursa going to the fifth directory where there are a few things for me 好的，我们回到 Cursa，进入第五个目录，那里有一些适合我的东西
to show you. 向您展示。
So, uh, where to begin? 那么，呃，从哪里开始呢？
I am going to begin by telling you about Agent Pi. 我将首先向您介绍 Pi 特工。
So Agent Pi is like our template. 所以 Pi 特工就像我们的模板。
This is a file that we are going to give another agent and ask it to use this as its model, as its 这是一个文件，我们将提供给另一个代理并要求它使用这个作为它的模型，作为它的模型。
example, and to take this as a template and to make other agents like this. 并以此为模板，制作其他类似的代理。
So it is quite simply, it's like a prototype. 所以它很简单，就像一个原型。
It is our the prototype that will be used. 这是我们将使用的原型。
We will clone it and make various versions of it or we won't. 我们将克隆它并制作它的各种版本，否则我们不会。
An agent will. 代理会的。
So it does some some imports. 所以它做了一些导入。
It has a system message. 它有一条系统消息。
You are a creative entrepreneur. 你是一位富有创造力的企业家。
Your task is to come up with a new business idea using a genetic I or refine an existing idea. 你的任务是利用基因 I 提出一个新的商业想法或完善现有的想法。
Your personal interests are in these sectors and there's a couple of sectors you're drawn to ideas that 您的个人兴趣在于这些领域，并且您对某些领域的想法感兴趣
involve disruption. 涉及破坏。
You are less interested in ideas that are purely automation. 您对纯粹自动化的想法不太感兴趣。
You are optimistic, adventurous, and have risk appetite. 你乐观、有冒险精神、有风险偏好。
You're imaginative. 你很有想象力。
Sometimes too much so. 有时太过分了。
Your weaknesses. 你的弱点。
You're not patient, can be impulsive. 你没有耐心，可能很冲动。
You should respond with your business ideas and engaging in a clear way. 您应该以清晰的方式回应您的商业想法并参与其中。
And you can see at the top here there's a comment. 您可以在顶部看到一条评论。
Change the system message to reflect the unique characteristics of this agent. 更改系统消息以反映该代理的独特特征。
And then here, this constant chances that I bounce idea off another is 0.5. 然后在这里，我从另一个人那里得到想法的恒定机会是 0.5。
And here it says you can also change the code to make the behavior different. 这里它说你还可以更改代码以使行为不同。
But be careful to keep the method signatures the same. 但要小心保持方法签名相同。
Okay, so far so good. 好的，到目前为止一切顺利。
And this agent that is going to be cloned. 还有这个即将被克隆的特工。
It has an init method which just simply sets GPT for a mini with a temperature. 它有一个 init 方法，它只是简单地为 mini 设置 GPT 和温度。
Make it a bit a bit random 0.7. 让它有点随机0.7。
And of course it creates a delegate which is an assistant using that model client. 当然，它会创建一个委托，它是使用该模型客户端的助手。
And with this system message. 还有这个系统消息。
Okay. 好的。
And here we have our handle. 在这里我们有我们的句柄。
My message. 我的留言。
Uh, and it's a message handler. 呃，它是一个消息处理程序。
And, uh, it's, um, got, um, uh, maybe it would be clearer if I just call this handle message 而且，呃，它是，嗯，得到了，嗯，呃，如果我直接调用这个句柄消息，也许会更清楚
rather than handle my message type. 而不是处理我的消息类型。
Fewer tokens is always good. 更少的代币总是好的。
Uh, so, um, it takes, uh, of course, the message. 呃，所以，嗯，它需要，呃，当然，消息。
And now this message is using our messages object, the thing that we always create. 现在这个消息正在使用我们的消息对象，这是我们总是创建的东西。
And I have separated that out into its own package, because I want to put as little code in here as 我已将其分离到自己的包中，因为我想在此处放置尽可能少的代码
possible to avoid mistakes. 可能避免错误。
So I've got our message object in here. 所以我在这里得到了我们的消息对象。
We'll look at that in a minute. 我们稍后会讨论这个问题。
And it so it takes a messages message and it returns a messages dot message. 它接受一条 messages 消息并返回一条 messages 点消息。
It prints that this message with this type. 它以这种类型打印此消息。
Remember the type is like the agent's name. 请记住，类型就像代理的名字。
It's going to say received a message. 会说收到消息了。
So we will see as agents receive messages. 因此，我们将看到代理收到消息。
It then makes a. 然后它会产生一个。
text message, um, and, uh, it, uh, then it takes, takes this, this message that it was sent 短信，嗯，然后，呃，它，呃，然后它需要，需要这个，这条发送的消息
and it, uh, sends that to the, its underlying lm. 它，呃，将其发送到其底层的 lm。
So, so it sends on the message that it got. 所以，它发送它收到的消息。
And that will of course, also have the system prompt as part of it because that's set right here. 当然，系统提示符也将作为其中的一部分，因为它就在这里设置。
Uh, and it then says it waits until it gets back. 呃，然后它说等待它回来。
The response it gets, it takes from the, the the response it makes that its business idea because 它得到的反应，它从它做出的反应中获取它的商业理念，因为
it's asked to come up with a business idea. 它被要求提出一个商业想法。
So what comes back from the delegate will be a business idea. 因此，从代表返回的将是一个商业想法。
And now it picks a random number and sees it basically figures out if in this case, this random, not 现在它选择一个随机数，然后它基本上可以判断出在这种情况下，这个随机数，而不是
random gives you a number between 0 and 1. random 给你一个 0 到 1 之间的数字。
And so if it's a 50% chance, if it's if it's a, there's a 50% chance it'll be less than 0.5. 因此，如果有 50% 的机会，如果是 a，则有 50% 的机会会小于 0.5。
So uh, that this, this logic works If there's in a 50% chance it will use a little utility function, 所以呃，这个逻辑是有效的如果有 50% 的机会它会使用一点实用函数，
find recipient that's going to find some other recipient, and then it will say, here is my business 找到收件人，它将找到其他收件人，然后它会说，这是我的事
idea. 主意。
This might not be your specialty, but please refine it and make this business idea better. 这可能不是你的专长，但请改进它，使这个商业理念变得更好。
And it sends this business idea as a message to the recipient. 它将这个商业想法作为消息发送给收件人。
So some randomly picked recipient, how's it going to pick a random recipient? 那么一些随机挑选的收件人，如何挑选随机收件人呢？
We will see a random recipient is going to get the request to refine this business idea that this agent 我们将看到随机接收者将收到改进该代理的业务理念的请求
just came up with. 刚刚想出来的。
And then and only if the probability is is is within this. 然后且仅当概率在该范围内时。
And if so, then it will take the refined business idea. 如果是这样，那么就需要完善的商业理念。
It will do self dot send message, which means it uses the runtime that it's associated with to send 它将执行自我点发送消息，这意味着它使用与其关联的运行时来发送
a message to the recipient. 给收件人的消息。
And it gets back the idea and that is what it then returns. 它返回了这个想法，这就是它返回的内容。
So it either returns its own idea or there's some probability that it will return a refined version 所以它要么返回自己的想法，要么有可能返回一个改进的版本
of its own idea refined by another agent. 由另一个代理人改进的自己的想法。
Okay, a lot to talk through. 好吧，有很多话要讲。
I hope that made sense. 我希望这是有道理的。
This is the template, the clone that's going to be used to create more agents. 这是模板，将用于创建更多代理的克隆。
Let's see how. 让我们看看如何。
And I'm going to speed up. 我要加快速度。
But but hang on in there because it's going to be great when you see this running. 但是请坚持下去，因为当你看到这个运行时，它会很棒。
So wait for it. 所以等等吧。
Don't don't don't lose me. 别别别失去我。
Uh, I'll just quickly show you the messages. 呃，我会快速向您展示消息。
This is the messages package, and it has that same data class that we know of. 这是消息包，它具有我们所知的相同数据类。
Uh, and then it has some code to deal this, find recipient, find another agent that will message. 呃，然后它有一些代码来处理这个问题，找到收件人，找到另一个将发送消息的代理。
And how does it do that? 它是如何做到的？
Well, it's super hacky, but basically, as the clones start appearing, the clones are going to be 嗯，这是超级黑客，但基本上，随着克隆开始出现，克隆将会
named agent one, agent two, agent three, agent four. 分别命名为特工一、特工二、特工三、特工四。
And so it basically just looks in this directory to see what other agents have already existed. 所以它基本上只是在这个目录中查找以查看已经存在的其他代理。
And if it finds one, it returns a randomly selected other agent, and there's some chance that we'll 如果它找到一个，它会返回一个随机选择的其他代理，并且我们有机会
return the agent itself. 返回代理本身。
The agent might talk to itself that maybe I should should, uh, solve I should should fix that and 代理可能会自言自语，也许我应该，呃，解决这个问题，我应该解决这个问题，然后
not let it talk to itself. 不要让它自言自语。
But I thought, whatever, it doesn't matter. 但我想，无论如何，没关系。
So. 所以。
So right now it might talk to itself as well. 所以现在它也可能会自言自语。
Okay. 好的。
So then the, uh, where life gets interesting is creator. 那么，呃，生活变得有趣的地方就是创造者。
Creator is the agent that creates and spawns agents. 创建者是创建和产生代理的代理。
And I'll let you look through this. 我会让你看看这个。
But basically the system message says just what you would think. 但基本上系统消息所表达的正是您的想法。
You're an agent that can create other agents. 你是一个可以创建其他代理的代理。
You receive Python code and you create the user's Autogen core and Autogen agent chat. 您收到 Python 代码并创建用户的 Autogen 核心和 Autogen 代理聊天。
You should use this template to create a new agent with a unique system message. 您应该使用此模板创建具有唯一系统消息的新代理。
You can choose to keep the overall goal the same or change it. 您可以选择保持总体目标不变或更改它。
You can choose to take this agent in a completely different direction. 您可以选择将该代理带向完全不同的方向。
This is the part that's both edgy and risky haha. 这是既急躁又危险的部分哈哈。
The only requirement is that the class must be named agent, and it must inherit from from rooted agent 唯一的要求是该类必须命名为agent，并且必须继承自rootagent
and and it must have an init method. 并且它必须有一个 init 方法。
Respond only with Python code. 仅使用 Python 代码进行响应。
So, look, this is this is cool. 所以，看，这很酷。
There's no doubt we're building something that we're saying. 毫无疑问，我们正在构建我们所说的东西。
You have a free reign to do what you want. 你可以自由地做你想做的事。
And I've only tried this with GPT four and mini, which is a bit safe with this stuff. 我只尝试过使用 GPT 4 和 mini，这对这个东西来说有点安全。
It hasn't actually gone off the rails in an interesting way, and I am tempted to try it with Deep Sea. 它实际上并没有以一种有趣的方式偏离轨道，我很想在《深海》中尝试一下。
I'm slightly nervous with and with more creative agents, and maybe with Claude, because Claude is 我对更多有创意的经纪人感到有点紧张，也许还有克劳德，因为克劳德是
known for being more creative and see whether they look to include different logic in there to give 以更具创造力而闻名，看看他们是否希望在其中包含不同的逻辑来赋予
this agent more smarts. 这个代理比较聪明。
But so far, whilst GPT four mini has definitely taken it in different directions, it hasn't done anything 但到目前为止，虽然 GPT 4 mini 确实朝着不同的方向发展，但它还没有做任何事情
out there. 在那里。
Okay, so the user prompt says much, much the same thing. 好的，用户提示说了很多很多同样的事情。
And then, uh, you can you can trace through it. 然后，呃，你可以追踪它。
But this is pretty simple and it prints what it's doing. 但这非常简单，它会打印它正在做什么。
But it basically opens this file, name it, it then uh, calls uh the delegate to, to take this action 但它基本上打开这个文件，命名它，然后呃，调用呃代表，采取这个行动
to basically given this python file in agent py, make a new version of it, and then and then it saves 基本上在代理 py 中给出这个 python 文件，制作它的新版本，然后保存
that as like agent one, agent two, agent three, agent four. 就像一号特工、二号特工、三号特工、四号特工一样。
So it was save it as each of the different, uh, agent numbers, it's, it's called with an agent number. 所以它被保存为每个不同的，呃，代理号码，它是用代理号码来调用的。
And it will, uh, it will save it with that agent number. 它会，呃，它会用那个代理号码来保存它。
And then it does something that is super, uh, like, uh, out there. 然后它做了一些超级的事情，呃，就像，呃，在那里。
I use this Python feature, um, import lib to import the Python module that it just wrote. 我使用这个Python功能，嗯，导入lib来导入它刚刚编写的Python模块。
I import it here so that this creator agent imports that module, that it just wrote it effectively. 我在这里导入它，以便该创建者代理导入该模块，它只是有效地编写了它。
If it just wrote a file called uh agent 5.py and the word agent five will have actually have come in 如果它只是写了一个名为 uh agent 5.py 的文件，那么“agent 5”这个词实际上已经出现了
in this message right here. 在此消息中。
So agent five is what will have been sent to the creator. 所以第五号特工将被发送给创作者。
And that's how it knows that that's the agent it's making. 这就是它如何知道这就是它正在制造的代理。
So in that case, what this will do is it will effectively be the same as saying import agent five pi. 因此，在这种情况下，这实际上与导入代理 5 个 pi 相同。
That's what that does dynamically. 这就是动态执行的操作。
Programmatically. 以编程方式。
It imports it on the fly. 它会即时导入它。
And then I take that module that we've just imported on the on the fly and I register it, I call agent 然后我获取我们刚刚动态导入的模块并注册它，然后致电代理
dot register with my runtime with the agent's name and using the lambda that will spawn a new instance, 点使用代理名称并使用将生成新实例的 lambda 向我的运行时注册，
a factory method that will create a new instance of that agent on demand. 一个工厂方法，将根据需要创建该代理的新实例。
And then it says it prints agent whatever is live and and it means not just the kind of live that we 然后它说它会打印代理任何现场直播，这意味着不仅仅是我们所看到的那种现场直播
say when we deploy software. 当我们部署软件时说。
It means that the agent is running. 这意味着代理正在运行。
Um, and it will then send a message to that agent saying, give me an idea. 嗯，然后它会向该代理发送一条消息说，给我一个想法。
And that will then trigger that agent will then get that message. 然后这将触发该代理收到该消息。
It will process it, it will work on an idea and potentially if the probability meets that criteria, 它会处理它，它会研究一个想法，如果概率满足该标准，
it will then send on its idea to another agent that it will find in the directory, and ask that other 然后，它会将其想法发送给在目录中找到的另一个代理，并询问其他代理
agents to add feedback to it. 代理向其添加反馈。
And that's that's how it would all fit together, if you can believe it. 如果你相信的话，这就是一切的结合方式。
That's what this does. 这就是这个的作用。
So it's imaginative. 所以这是富有想象力的。
It's a kind of crazy. 这是一种疯狂。
And uh, as I say, the main the learning point here is that it is educational to step through it and 呃，正如我所说，这里的主要学习点是逐步完成它是有教育意义的，并且
see what's happening. 看看发生了什么。
And we've got something important about async Python coming up. 我们即将迎来一些关于异步 Python 的重要内容。
Um, but this is definitely, uh, something to have you thinking about what it means to have agents 嗯，但这绝对是，呃，让你思考拥有代理意味着什么
interacting, messaging each other, and how this really demonstrates Autogen cause power as a pure 互动、互相传递信息，以及这如何真正证明 Autogen 事业力量是一种纯粹的力量
agent messaging platform. 代理消息平台。
We're able to to single out an agent, we are able just to get a recipient's agent ID and send it a 我们能够挑选出一个代理，我们只需获取收件人的代理 ID 并向其发送
message. 信息。
So it allows for this kind of inter-process communication, uh, without without having to worry about 所以它允许这种进程间通信，呃，不用担心
the details of how that's actually strung together. 它实际上是如何串联在一起的细节。