Okay, now there's something a bit confusing now, which I'll have to get your head around, which is 好吧，现在有些事情有点令人困惑，我得让你明白，那就是
that you can, as we've just done, turn a function into a tool. 您可以像我们刚刚所做的那样，将函数变成工具。
There's something else you can turn into a tool as well. 您还可以将其他东西变成工具。
You can turn a whole agent into a tool. 您可以将整个代理变成一个工具。
You can say, we've got this sales agent, something that can write a sales email. 你可以说，我们有这个销售代理，可以写销售电子邮件。
Well, that whole thing, that whole process of calling that LM with that prompt, that can just be 嗯，整个事情，用那个提示调用 LM 的整个过程，可以是
considered itself to be a tool. 认为自己是一个工具。
We can think of it as a sales agent tool. 我们可以将其视为一种销售代理工具。
And doing that might sound like there's a fair amount of work to be done to package an LM call into 这样做听起来可能需要做大量的工作才能将 LM 调用打包到
a tool. 一个工具。
But no, all you have to do is call as tool on the agent, and you will convert the agent into a tool. 但不，你所要做的就是在代理上调用作为工具，然后你就会将代理转换为工具。
What does it mean to convert an agent into a tool? 将代理转变为工具意味着什么？
All it means is it's going to create a new tool. 这意味着它将创建一个新工具。
It's going to have all of the JSON gunk that describes what that tool can do. 它将包含所有描述该工具功能的 JSON 内容。
And if that tool is called it's going to actually call the agent and make the agent make the call to 如果调用该工具，它将实际调用代理并让代理进行调用
the LM. LM。
So it's a wrapper. 所以它是一个包装器。
A wrapper around the agent that turns the agent into a tool. 代理的包装器，将代理变成工具。
That's all it is. 仅此而已。
So let's look at this sales agent one as tool. 那么让我们看看这个销售代理作为一种工具。
We're going to give it a tool name sales agent one still and write a cold sales email is our description 我们将给它一个工具名称销售代理一仍然并写一封冷销售电子邮件是我们的描述
of what that tool can do. 该工具可以做什么。
And now if we look at tool one you can see it's a function tool just like this one. 现在，如果我们看一下工具一，您会发现它是一个功能工具，就像这个工具一样。
Just like send email. 就像发送电子邮件一样。
It's got a different name. 它有一个不同的名字。
Its description is this description here. 它的描述就是这里的描述。
Now it's got the same parameters, the JSON blob that we would expect. 现在它具有相同的参数，即我们期望的 JSON blob。
And it's got a special function to tell it what to do when the tool is actually called. 它有一个特殊的函数来告诉它在实际调用该工具时要做什么。
And that of course is actually going to call our agent. 当然，这实际上是要打电话给我们的代理人。
So hopefully that makes sense. 希望这是有道理的。
We're now going to package our agents into tools and use them. 我们现在将把我们的代理打包成工具并使用它们。
All right here we go. 好吧，我们开始吧。
So this I could have done this with a fancy loop, but I thought, you know what? 所以我可以用一个奇特的循环来完成这个，但我想，你知道吗？
I'll just spell it out so that you're crystal clear on what's happening here. 我只是将其拼写出来，以便您清楚地了解这里发生的事情。
We're going to have three tools. 我们将拥有三个工具。
Tool one, tool two, and tool three. 工具一、工具二、工具三。
And it is just taking the three agents. 而且只是拿了三个特工而已。
Sales agent one, two and three. 销售代理一、二、三级。
And calling as tool on each of them. 并作为每个工具的调用。
And for each one we just give it a tool name and a tool description which is the same tool description. 对于每一个，我们只需给它一个工具名称和一个工具描述，这是相同的工具描述。
That is it. 就是这样。
Now if you if you feel up to it, just rewrite that as a nice little loop so that we don't have a silliness 现在，如果你愿意的话，只需将其重写为一个漂亮的小循环，这样我们就不会犯傻了
with repetition like this. 像这样重复。
But but I wanted to spell it out. 但我想把它说出来。
And now I'm giving myself a list called tools and tools has tool one, tool two, tool three. 现在我给自己一个名为工具的列表，工具有工具一、工具二、工具三。
And these are like the agents wrapped as tools. 这些就像被包裹成工具的代理。
They're tools that would simply call the agents and then send email is the real tool that is just a 它们是简单地呼叫代理然后发送电子邮件的工具，这是真正的工具，只是一个
function. 功能。
Send email that calls SendGrid the email program. 发送电子邮件，调用电子邮件程序 SendGrid。
And let's have a look at what we get if we run this. 让我们看看运行这个程序会得到什么。
So now this is our list of tools. 现在这是我们的工具列表。
And it is indeed four function tools sales agent one, sales agent two, salesperson three and send 确实是四功能工具销售代理一、销售代理二、销售员三、发送
email all in a list of tools. 通过电子邮件发送工具列表中的所有内容。
Okay, now it's time to put all of that into a sales manager. 好的，现在是时候将所有这些都交给销售经理了。
Our planning agent. 我们的策划代理。
So now it's a bit like we did before, except we're giving an agent the ability to choose what to run 所以现在有点像我们之前做的，只是我们让代理能够选择运行什么
when. 什么时候。
It's not like we're just writing Python code to say, do this, this, this, and then send email. 这不像我们只是编写 Python 代码来说，做这个，这个，这个，然后发送电子邮件。
But rather, we're letting the agent decide. 相反，我们让代理人来决定。
You are a sales manager working for comply. 您是一名为Compliance 工作的销售经理。
You use the tools given to you to generate cold sales emails. 您可以使用提供给您的工具来生成冷销售电子邮件。
You never generate sales emails yourself. 您永远不会自己生成销售电子邮件。
You always use the tools. 你总是使用这些工具。
You try all three tools once before choosing the best. 在选择最好的工具之前，您需要尝试所有三种工具一次。
You pick the single best email and use the Send Email tool to send the best email and only the best 您选择最好的一封电子邮件，然后使用发送电子邮件工具发送最好的电子邮件，并且仅发送最好的电子邮件
email to the user. 发送电子邮件给用户。
Now, I'm probably over spelling it out here. 现在，我可能已经把它拼写完了。
You can experiment. 你可以尝试一下。
It's not always required to be so pedantic, but I'm also doing it to show you what's going on. 并不总是需要如此迂腐，但我这样做也是为了向你展示发生了什么。
And it's never a bad thing to be very precise and instructive with your prompts. 非常精确且具有启发性的提示绝不是一件坏事。
Okay, so with that, we want to create a new sales manager agent. 好的，我们想创建一个新的销售经理代理。
There it is. 就在那里。
We want to give it these instructions. 我们想给它这些指示。
It's system prompt. 是系统提示。
We want to pass in all four tools, all these tools right here. 我们想要传递所有四个工具，所有这些工具都在这里。
And we give it a model. 我们给它一个模型。
And then we say send a cold sales email addressed to dear CEO. 然后我们说向亲爱的首席执行官发送一封冷冰冰的销售电子邮件。
And we start this going and off it runs. 我们开始这个过程并开始运行。
And this will take about 30s. 这大约需要 30 秒。
So I will see you in a sec. 所以我很快就会见到你。
Well actually it didn't take 30s. 好吧，实际上并没有花费30秒。
It took 18 seconds. 花了18秒。
So it's quite quick and it finished and we can first let's look look in my email I did in fact just 所以它很快就完成了，我们可以先看看我的电子邮件，事实上我只是这样做了
receive an email and here it is. 收到一封电子邮件，就在这里。
And very good. 而且非常好。
It does indeed do things quite nicely. 它确实做得很好。
You'll see it's put like like a template CEO's name not dear CEO you can improve the prompting to stop 你会看到它像模板一样放置首席执行官的名字不是亲爱的首席执行官你可以改进提示停止
it doing that if you wish, but there's an exercise at the end to incorporate mail merge. 如果您愿意，它可以这样做，但最后有一个合并邮件合并的练习。
So it actually would put in real people's names here. 所以它实际上会在这里输入真实的人名。
But but very nice. 但是但是非常好。
We got the email, it came through to me and it came from the verified email sender as expected. 我们收到了电子邮件，它发送给我，并且按预期来自经过验证的电子邮件发件人。
The other thing to do, of course, is to go and have a look at the trace. 当然，另一件事就是去看看踪迹。
Let's go and do that now. 我们现在就去做吧。
So here it is. 所以就是这样。
Sales manager is what we called it for. 销售经理就是我们所说的。
Tools were used. 使用了工具。
It took 18 seconds. 花了18秒。
Let's go in and have a look. 我们进去看看吧。
So it called Sales Agent one. 所以它被称为销售代理一。
It called sales agent two. 它打电话给销售代理二号。
Sales agent three. 销售代理三．
And then it called Send Email. 然后它调用发送电子邮件。
That's the the the tool that is just a tool. 这就是工具，它只是一个工具。
If you look at each of these sales agents tools representing by this this sort of green thing, you'll 如果您查看由此类绿色事物代表的每个销售代理工具，您会
see that underneath that was an agent. 看到下面是一个特工。
So this hopefully makes it crystal clear for you that we had an agent, the professional sales agent 因此，希望这能让您清楚地知道我们有一个代理，专业的销售代理
that was wrapped in the tool, sales agent one. 那是包裹在工具里的，销售代理之一。
And you can see that again for this one and for this one. 您可以再次看到这一点和这一点。
But in the case of send email, it was simply a function that was called with a body. 但在发送电子邮件的情况下，它只是一个用主体调用的函数。
But you can look through the trace and you should look through the trace and understand the interactions 但是你可以查看跟踪，并且应该查看跟踪并理解交互
between tools and agents to allow the sales manager to carry out its full activity, allowing itself 工具和代理之间的联系，使销售经理能够开展其全部活动，让自己
to make its decisions about what it does, in what order. 做出关于做什么、按什么顺序的决定。