Next we're going to peel back the onion a little bit more on workflows. 接下来，我们将在工作流程上进一步深入探讨。
Looking at different types of workflow, anthropic identifies five different design patterns that you'll 着眼于不同类型的工作流程，人择确定了五种不同的设计模式，您将使用它们
find when building a genetic systems that have workflows in them. 在构建具有工作流程的遗传系统时发现。
And let's go through each of them and talk about them. 让我们逐一讨论并讨论它们。
This is the first one. 这是第一个。
They call it prompt chaining. 他们称之为即时链接。
And it's a simple one. 这很简单。
What you're seeing here in this diagram obviously the in and the out on the left and the right is the 您在此图中看到的显然左侧和右侧的输入和输出是
beginning and the end of the workflow. 工作流程的开始和结束。
The yellow boxes represent calls to models to Llms. 黄色框代表对 Llm 模型的调用。
And the blue boxes is where you potentially have just some code that you've written, some some software 蓝色方框中可能只有您编写的一些代码，一些软件
and it's optional. 并且它是可选的。
And what you'll see there is that this is simply saying you could have an LLM carry out some task and 你会看到这只是说你可以让法学硕士执行一些任务并且
then potentially based on some code, you could then pass that to a second LLM and that output could 然后可能基于一些代码，您可以将其传递给第二个LLM，并且该输出可以
go to a third LLM. 去第三个法学硕士。
And that could be the conclusion. 这可能就是结论。
And actually this is really similar to what you just did. 实际上，这与您刚刚所做的非常相似。
This is similar to that commercial question. 这与商业问题类似。
When we ask an LLM first pick a sector. 当我们要求法学硕士时，首先选择一个部门。
And then given that sector pick a pain point and then pick a solution. 然后针对该领域选择一个痛点，然后选择一个解决方案。
And obviously it doesn't need to be three LMS. 显然它不需要是三个 LMS。
It can be as many as you want, but this is the idea. 你想要多少都可以，但这就是想法。
You are chaining a series of LM calls decomposing into a fixed set of subtasks. 您将一系列 LM 调用链接起来，分解为一组固定的子任务。
And the reason you might want to do that is because you can take care to frame each LM call very precisely 您可能想要这样做的原因是因为您可以非常精确地构建每个 LM 调用
to get the the best, the most effective LM response based on that prompt. 根据该提示获得最佳、最有效的 LM 响应。
So it allows you to to really work on each of those tasks being very effective. 因此，它可以让您真正有效地完成每一项任务。
And then keep your whole process, your workflow on guardrails by taking it step by step through a sequence 然后通过按顺序逐步进行，让整个过程、工作流程保持在护栏上
of well-defined tasks. 明确定义的任务。
Now I want to make a point that you might have already thought of. 现在我想指出一个你可能已经想到的观点。
Whilst anthropic is quite clear to define this as a workflow and not an agent pattern, it is perfectly 虽然人类很清楚地将其定义为工作流程而不是代理模式，但它是完美的
possible for prompt chaining workflow like this to be giving the LM some discretion on what activities 像这样的提示链接工作流程可以让LM在哪些活动上有一定的自由裁量权
happen, because just as we did in our example, the first call to the LM might come up with a topic, 发生这种情况是因为正如我们在示例中所做的那样，对 LM 的第一次调用可能会提出一个主题，
and it's that topic that gets worked on by LMS two and three. 这正是学习管理系统二号和三号所研究的主题。
So in some ways, the way that anthropic distinguishes between workflows and agents, it's a little 所以在某些方面，人类区分工作流和代理的方式有点不同
bit artificial. 有点人工。
There is definitely a blurred line between them. 他们之间肯定有一条模糊的界限。
It's perfectly possible for there to be an element of autonomy about a workflow pattern like this. 像这样的工作流程模式完全有可能存在自治元素。
Onwards. 以后。
The second design pattern is called routing, and this is where an input comes in. 第二种设计模式称为路由，这就是输入的用武之地。
And an LLM has the task of deciding which of multiple possible models are selected to carry out this 法学硕士的任务是决定选择多个可能的模型中的哪一个来执行此操作
function. 功能。
And the idea is that you might have specialist models in here. 我们的想法是，这里可能有专业模型。
They're shown by LLM one, two and three. 它们由法学硕士一、二和三展示。
And they're each good at different tasks. 他们各自擅长不同的任务。
And the router's job is to classify the task, understand which of the specialists will be best equipped 路由器的工作是对任务进行分类，了解哪些专家最适合
to tackle this task. 来完成这项任务。
And it allows for, as I say here, separation of concerns for being able to have different LMS that 正如我在这里所说，它允许关注点分离，以便能够拥有不同的 LMS
have different levels of expertise and have them and have an LLM decide how to route to those experts. 拥有不同水平的专业知识，让他们和法学硕士决定如何联系这些专家。
So this is a powerful model. 所以这是一个强大的模型。
It's very common. 这很常见。
And it's something which again, I would say I would argue there is some it's a bit artificial to say 我想说的是，我认为有些说法有点不自然
that there's no autonomy here, because clearly that router is able to make some decisions, albeit 这里没有自主权，因为显然路由器能够做出一些决定，尽管
on guardrails. 在护栏上。
Again, it still has to follow a given workflow. 同样，它仍然必须遵循给定的工作流程。
And on to the third design pattern. 接下来是第三种设计模式。
Parallelization, which is at first blush, might look quite similar to what we just talked about. 乍一看，并行化可能与我们刚才讨论的非常相似。
But there is a lot in common with these design patterns. 但这些设计模式有很多共同点。
But the idea here is that you have. 但这里的想法是你已经有了。
Remember, the blue boxes represent code R code, not an LM. 请记住，蓝色框代表代码 R 代码，而不是 LM。
So we write some code that takes a task and breaks it down into multiple pieces that should all run 因此，我们编写一些代码来接受一个任务并将其分解为多个部分，这些部分都应该运行
in parallel. 并联。
So in the previous design pattern it was an LM doing the routing. 因此，在之前的设计模式中，是由 LM 进行路由。
And it was one of these three experts that was given the task in this design pattern. 在这个设计模式中，正是这三位专家之一被赋予了任务。
It's code. 这是代码。
It's let's say Python code that's deciding what to do or how to coordinate. 假设 Python 代码决定做什么或如何协调。
And in parallel, it's being sent to three llms to carry out three different activities concurrently. 与此同时，它被发送到三个 llms，同时开展三项不同的活动。
And then there's more code. 然后还有更多代码。
Maybe it's Python code that takes those answers and stitches them together. 也许是 Python 代码获取了这些答案并将它们拼接在一起。
And actually, anthropic makes the point that these tasks don't necessarily need to be different tasks. 实际上，人择指出这些任务不一定需要是不同的任务。
You could imagine a situation where you send the same task and have it be done three times, and you 您可以想象这样一种情况，您发送相同的任务并让它完成三次，然后您
use the aggregator, perhaps to take the average or something like that. 使用聚合器，也许可以取平均值或类似的东西。
So there are various situations where this might be the same thing that you're doing three times doesn't 所以在很多情况下，这可能是你做三遍的同一件事，但并非如此
need to be different, but I think most commonly it's when there are multiple subtasks happening concurrently. 需要有所不同，但我认为最常见的是当多个子任务同时发生时。
That is the parallelization. 这就是并行化。
It's hard to say of the design patterns. 设计模式很难说。
Okay. 好的。
And now this one orchestrator worker. 现在是这一位协调员。
This is when a difficult, challenging task is broken down and recombined. 这是一个困难的、具有挑战性的任务被分解和重新组合的时候。
And you might be thinking, hang on, isn't that just what we just did? 你可能会想，等等，这不正是我们刚刚所做的吗？
I just flick between them. 我只是在它们之间快速浏览。
Don't these two slides, these two design patterns are really similar? 难道这两张幻灯片，这两种设计模式真的很相似吗？
Well, you'll notice a subtle color change along with the change in terminology. 好吧，您会注意到随着术语的变化，颜色也发生了微妙的变化。
The key point is that this is exactly like the prior design pattern, except it's no longer code that's 关键点是，这与之前的设计模式完全相同，只是不再是代码
doing the orchestration. 进行编排。
It's an LLM. 这是一个法学硕士。
So you are using a model to break down a complex task into smaller steps, and then you are using a 因此，您正在使用模型将复杂的任务分解为较小的步骤，然后使用
model to combine the results. 模型来组合结果。
And so this is a much more dynamic kind of system where the orchestrator can choose how to divvy up 所以这是一个更加动态的系统，协调者可以选择如何分配
the task. 任务。
And again, I would argue that it's quite artificial to categorize this as a workflow rather than an 再说一遍，我认为将其归类为工作流程而不是流程是相当人为的。
agent pattern that we'll look at in a minute, because clearly that orchestrator has discretion over 我们稍后会讨论代理模式，因为很明显，编排者可以自行决定
how it divvies up the tasks, and it could choose how many different llms get assigned the activity. 它如何分配任务，并且可以选择为多少个不同的 LLMS 分配该活动。
So saying that this is just a fixed workflow is perhaps a stretch. 所以说这只是一个固定的工作流程也许有点夸张。
So, you know, I think you get the overall idea. 所以，你知道，我认为你已经了解了总体想法。
There's certainly more constraints on this than when we come to the more flexible agent flows. 与我们采用更灵活的代理流程相比，这肯定有更多的限制。
But but generally the idea here LLM breaks down the task Llms carry out each expert task, LM synthesizes 但一般来说，这里的想法 LLM 分解了任务 Llm 执行每个专家任务，LM 综合
the task for an output that is pattern for the orchestrator worker. 输出的任务是 Orchestrator Worker 的模式。
And now on to pattern five. 现在来看模式五。
The final workflow pattern and the one that I use most commonly. 最终的工作流程模式也是我最常用的一种。
This is one that I come against all the time, and it's called an evaluator optimizer by anthropic. 这是我一直遇到的一个问题，anthropic 将其称为评估器优化器。
I tend to call them just evaluators or validation validation agents. 我倾向于称他们为评估者或验证验证代理。
You hear that a lot, but the idea is it's very simple. 你听过很多这样的说法，但想法很简单。
You have an LM that's doing your job. 你有一个 LM 正在做你的工作。
Let's call it the LM generator. 我们将其称为 LM 生成器。
It's it's doing something. 它正在做某事。
And it comes up with a solution shown in this white arrow here. 它提出了一个解决方案，如此处的白色箭头所示。
And you have a second LM that's playing the role of evaluator. 还有第二个 LM 扮演评估者的角色。
It's there to check the work of the first LM. 它的作用是检查第一个 LM 的工作。
And it's given any extra information, any context, everything to, to arm itself to, to not be trying 它被给予任何额外的信息，任何背景，一切，武装自己，而不是尝试
to generate content, but check the work of a prior LM. 生成内容，但要检查先前 LM 的工作。
And based on that it can choose to either accept or reject the work. 并据此可以选择接受或拒绝该工作。
If it accepts it, then that's it goes to the output. 如果它接受它，那么它就会进入输出。
If it rejects it. 如果它拒绝的话。
It should come up with a reason. 它应该拿出一个理由。
And the rejection and the reason goes back to the LM generator. 拒绝和原因可以追溯到 LM 发电机。
And that can then choose to come up with another solution which comes back here. 然后可以选择提出另一个回到这里的解决方案。
And so you can see this, this sort of feedback loop setup. 所以你可以看到这种反馈循环设置。
It's very powerful. 它非常强大。
Of course, one of the key concerns of building production systems with LMS is about accuracy, predictability, 当然，使用 LMS 构建生产系统的关键问题之一是准确性、可预测性、
robustness of the responses and having validation agents. 响应的稳健性和验证代理。
Having these kinds of evaluator optimizer flows in your LMS solutions is a really powerful way to increase 在您的 LMS 解决方案中拥有这些类型的评估器优化器流程是一种非常有效的提高效率的方法。
the accuracy and build more guarantees. 的准确性，建立更多的保证。
There's never full guarantees with LMS, but build a higher level of guarantee around the quality of LMS 永远不会提供全面的保证，但会围绕产品的质量建立更高水平的保证
the final output. 最终输出。
So this is a really effective pattern. 所以这是一个非常有效的模式。
I use it all the time, and of course we'll have plenty of examples on the course, and you should be 我一直在使用它，当然我们的课程中会有很多例子，你应该
able to think about how you could apply this to LM solutions in your day jobs right away. 能够立即思考如何将其应用到日常工作中的 LM 解决方案中。