第四章:Planner - 赋能大语言模型进行任务规划

In Last Chapter, we learned a very important function of Semantic Kernel - plug-ins, through which work in different fields can be completed. LLMs change the way human-computer interaction uses natural language to talk to LLMs and let the LLMs complete the work. But often the instructions we give are not just about completing a single task, such as "Please send a dressing reminder email to people on business trips based on the weather in Seattle." We have always wanted artificial intelligence to compare with humans. If we think about the above instructions using human thinking, we will have the following split:

在上一章中,我们掌握了Semantic Kernel的核心功能——插件系统,通过它可实现跨领域任务处理。大语言模型(LLMs)彻底改变了人机交互模式,使我们能够用自然语言指令驱动模型完成任务。但实际场景中的需求往往涉及多任务组合,例如"请根据西雅图天气情况,向出差人员发送着装提醒邮件"。我们始终期望人工智能能具备人类级思维。若以人类认知模式解析该指令,可拆解为以下步骤:

  1. Check the weather in Seattle    查询西雅图天气情况

  2. Query the business travelers and their contact information from the company system    从公司系统获取差旅人员及其联系方式

  3. Reminder email template    生成提醒邮件模板

  4. Send email    发送邮件

LLMs actually have the same thinking. There is a powerful Planner function in the Semantic Kernel to split tasks. This chapter will tell you the relevant content.

事实上,LLMs具备相同的思维逻辑。Semantic Kernel内置强大的Planner功能,专门用于任务分解与规划。本章将详细讲解这一功能。

What's Planner    什么是 Planner

Planner is an important component of the Semantic Kernel. It can receive task instructions and then correspond to the built-in plug-ins or custom plug-ins that have been defined in the Kernel, so that the task instructions can work step by step. As mentioned at the beginning, in fact, for the instruction "please send a dressing reminder email to business people based on the weather in Seattle", the relevant plugins will be defined in plugins and registered through Kernel, Semantic Kernel will Assist you with the pairing steps.

Planner 是 Semantic Kernel 的核心组件之一。它能够接收任务指令,并自动关联 Kernel 中已注册的内置插件(built-in plug-ins)或自定义插件(custom plug-ins),从而将任务拆解为可逐步执行的步骤。如开篇所述,对于指令 "请根据西雅图天气情况向商务差旅人员发送着装提醒邮件",相关功能模块会被封装为插件(plugins),并通过 Kernel 完成注册。此时,Semantic Kernel 的 Planner 将自动协助完成以下流程:

image

How to use Planner    如何使用 Planner

Now Planner is still in the evolutionary stage. In the latest .NET version, we found that the Semantic Kernel version of the Planner component Microsoft.SemanticKernel.Planners.Handlebars is different from the core Microsoft.SemanticKernel. Some users are questioning whether the Semantic Kernel version number is confusing. You can understand that the Semantic Kernel team has completed the core part in 2023, and component-based functions such as Planner, Memory, and some Connectors are still evolving. After all, these features are relevant to the development of LLMs.

当前Planner功能仍处于演进阶段。在最新的.NET版本中,我们发现Planner组件Microsoft.SemanticKernel.Planners.Handlebars的版本号与核心库Microsoft.SemanticKernel存在差异,这引发部分用户对版本号统一性的疑问。需要说明的是:Semantic Kernel团队在2023年已完成核心框架开发,而Planner、Memory及部分Connector等组件化功能仍在持续迭代——毕竟这些功能与LLM技术的发展密切相关。

If you need to use Planner, you need to consider your business scenario. For example, adding Planner to some business processes and adding Planner to tool chains are very useful. After all, humans think a lot about work automation.

如果您需要使用 Planner,需要考虑您的业务场景。例如将 Planner 集成至业务流程中(实现智能编排),以及工具链中集成 Planner (作为AI工具链的决策中枢进行部署)都是非常有用的,毕竟人类对工作自动化的追求永无止境。

.NET

add related component libraries about Planner

集成Planner相关组件库

#r "nuget: Microsoft.SemanticKernel.Planners.Handlebars, *-*"

import library

导入库

using Microsoft.SemanticKernel.Planning;

Note: When using HanlerBars, you need to note that these features are still evolving, and please ignore SKEXP0060 when using them.

注意:使用 Handlebars 时需注意,相关功能仍处于演进阶段。如遇 SKEXP0060 警告,请暂时忽略该提示。

#pragma warning disable SKEXP0060

The Changing Planner    Planner的演进历程

In the official blog, changes in Planner are mentioned https://devblogs.microsoft.com/semantic-kernel/migrating-from-the-sequential-and-stepwise-planners-to-the-new-handlebars-and -stepwise-planner/ combines Function Calling to rearrange the different Planner integrations in the preview version. You can pay attention to this content to learn more.

官方博客中提到了Planner的变更(https://devblogs.microsoft.com/semantic-kernel/migrating-from-the-sequential-and-stepwise-planners-to-the-new-handlebars-and-stepwise-planner/),新版本结合Function Calling功能对预览版中的不同Planner集成方案进行了重构。您可关注该内容获取详细信息。

If you want to understand the principles of Planner implementation, please refer to

若需了解Planner的实现原理,请参考:

https://github.com/microsoft/semantic-kernel/blob/main/dotnet/src/Planners/Planners.Handlebars/Handlebars/CreatePlanPrompt.handlebars

Sample    示例

.NET 例子 请点击访问这里

Python 例子 请点击访问这里

Summary    小结

The addition of Planner greatly improves the usability of Semantic Kernel, especially for business and tool scenarios. Building an enterprise-level plugin library is also very important for the implementation of Planner. After all, we use plug-ins to combine different tasks to complete the work.

Planner的加入显著提升了Semantic Kernel的实用性,特别针对业务和工具类的场景。构建企业级的插件库,对于 Planner 落地也是非常重要,毕竟我们通过插件组合出不同的任务来完成工作。

posted @ 2025-08-14 10:45  菜鸟吊思  阅读(7)  评论(0)    收藏  举报