{"id":502,"date":"2023-07-24T11:10:49","date_gmt":"2023-07-24T18:10:49","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/semantic-kernel\/?p=502"},"modified":"2024-01-11T22:01:24","modified_gmt":"2024-01-12T06:01:24","slug":"semantic-kernel-planners-actionplanner","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/agent-framework\/semantic-kernel-planners-actionplanner\/","title":{"rendered":"Semantic Kernel Planners: Action Planner"},"content":{"rendered":"<blockquote><p>The Action Planner is no longer supported. See <a href=\"https:\/\/devblogs.microsoft.com\/semantic-kernel\/migrating-from-the-sequential-and-stepwise-planners-to-the-new-handlebars-and-stepwise-planner\/\">how to migrate legacy code<\/a> away from it.<\/p><\/blockquote>\n<h2><a href=\"https:\/\/devblogs.microsoft.com\/semantic-kernel\/wp-content\/uploads\/sites\/78\/2023\/03\/skpatternlarge.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-89\" src=\"https:\/\/devblogs.microsoft.com\/semantic-kernel\/wp-content\/uploads\/sites\/78\/2023\/03\/skpatternlarge.png\" alt=\"Image skpatternlarge\" width=\"1638\" height=\"136\" srcset=\"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/03\/skpatternlarge.png 1638w, https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/03\/skpatternlarge-300x25.png 300w, https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/03\/skpatternlarge-1024x85.png 1024w, https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/03\/skpatternlarge-768x64.png 768w, https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/03\/skpatternlarge-1536x128.png 1536w\" sizes=\"(max-width: 1638px) 100vw, 1638px\" \/><\/a><\/h2>\n<p>This will be the first of a series of blog posts which will &#8216;step through&#8217; (no pun intended) the generation and evolution of planners available in Semantic Kernel; <span data-contrast=\"none\">Action Planner, Sequential Planner, and Stepwise Planner. <\/span>Planners are a critical element of Semantic Kernel, e<span data-contrast=\"none\">ach has its own strengths, so it\u2019s important to understand how each planner works so you can pick the best one for your needs.<\/span><span data-ccp-props=\"{&quot;134233118&quot;:true,&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:240}\">\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><a href=\"https:\/\/devblogs.microsoft.com\/semantic-kernel\/wp-content\/uploads\/sites\/78\/2023\/07\/Evolution_of_Planners.jpg\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-815\" src=\"https:\/\/devblogs.microsoft.com\/semantic-kernel\/wp-content\/uploads\/sites\/78\/2023\/07\/Evolution_of_Planners.jpg\" alt=\"Image Evolution of Planners\" width=\"1174\" height=\"597\" srcset=\"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/07\/Evolution_of_Planners.jpg 1174w, https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/07\/Evolution_of_Planners-300x153.jpg 300w, https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/07\/Evolution_of_Planners-1024x521.jpg 1024w, https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/07\/Evolution_of_Planners-768x391.jpg 768w\" sizes=\"(max-width: 1174px) 100vw, 1174px\" \/><\/a><\/h2>\n<p>&nbsp;<\/p>\n<p><span data-contrast=\"none\">In Semantic Kernel, you can easily build custom plugins or import ones you have already. Once you have all these plugins registered in the kernel, you now need a way to orchestrate them to accomplish user goals.<\/span><span data-ccp-props=\"{&quot;134233118&quot;:true,&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:240}\">\u00a0<\/span><span data-contrast=\"none\">Semantic Kernel Planners provide a way to manually orchestrate plugins using the RunAsync function. Or a key superpower of Semantic Kernel comes from having AI automatically combine your plugins to address the needs of your users via planners. <\/span><span data-ccp-props=\"{&quot;134233118&quot;:true,&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:240}\">\u00a0<\/span><\/p>\n<p><span class=\"TextRun SCXW61959700 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SpellingErrorV2Themed SCXW61959700 BCX8\">In this blog we will look at the Action Planner. <\/span><\/span><\/p>\n<p><span data-contrast=\"none\">The Action Planner works by identifying the most relevant plugin that achieves the user\u2019s goal. What makes it different from other planners is that it only chooses a <\/span><i><span data-contrast=\"none\">single<\/span><\/i><span data-contrast=\"none\"> plugin to run. See below example of <a href=\"https:\/\/github.com\/microsoft\/chat-copilot\">Chat Copilot<\/a> leveraging the Action Planner with the Klarna plugin to generate a response. \u00a0<\/span><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/semantic-kernel\/wp-content\/uploads\/sites\/78\/2023\/07\/chat-copilot-actionplanner-1.jpg\"><img decoding=\"async\" class=\"aligncenter wp-image-981\" src=\"https:\/\/devblogs.microsoft.com\/semantic-kernel\/wp-content\/uploads\/sites\/78\/2023\/07\/chat-copilot-actionplanner-1.jpg\" alt=\"Image chat copilot actionplanner\" width=\"1084\" height=\"519\" srcset=\"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/07\/chat-copilot-actionplanner-1.jpg 1913w, https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/07\/chat-copilot-actionplanner-1-300x144.jpg 300w, https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/07\/chat-copilot-actionplanner-1-1024x490.jpg 1024w, https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/07\/chat-copilot-actionplanner-1-768x368.jpg 768w, https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/07\/chat-copilot-actionplanner-1-1536x735.jpg 1536w\" sizes=\"(max-width: 1084px) 100vw, 1084px\" \/><\/a><\/p>\n<p><span data-contrast=\"none\">This planner is helpful in scenarios where you have already defined higher-order plugins (or plans!) that accomplish a user\u2019s intent and you merely need a mechanism to choose the right one. This makes the action planner highly efficient and get in low latency scenarios. If your requests can only be achieved by <i>multiple<\/i> plug-ins, you may need to define your own planner or use a more complex planner like Sequential Planner or Stepwise Planner.\u00a0<\/span><\/p>\n<p><span class=\"TextRun SCXW61959700 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SpellingErrorV2Themed SCXW61959700 BCX8\">Action Planner<\/span>\u00a0<span class=\"NormalTextRun SCXW61959700 BCX8\">works by <\/span><span class=\"NormalTextRun SCXW61959700 BCX8\">implement<\/span><span class=\"NormalTextRun SCXW61959700 BCX8\">ing<\/span><span class=\"NormalTextRun SCXW61959700 BCX8\"> an i<\/span><span class=\"NormalTextRun CommentStart CommentHighlightPipeRest CommentHighlightRest SCXW61959700 BCX8\">ntent detection pattern<\/span><span class=\"NormalTextRun CommentHighlightPipeRest SCXW61959700 BCX8\">, which <\/span><span class=\"NormalTextRun SCXW61959700 BCX8\">identifies<\/span><span class=\"NormalTextRun SCXW61959700 BCX8\"> a user\u2019s intent and compares it to the available plug-in functions loaded into the kernel<\/span><span class=\"NormalTextRun SCXW61959700 BCX8\">.<\/span><span class=\"NormalTextRun SCXW61959700 BCX8\"> Once it finds a plug-in that most aligns with a user\u2019s goal, it uses AI to populate the necessary input parameters.<\/span><\/span><\/p>\n<p>Here&#8217;s an example of how you can use Action Planner in your project:<\/p>\n<pre class=\"prettyprint language-cs language-csharp\"><code class=\"language-cs language-csharp\">\/\/ Initialize a new instance of the ActionPlanner class\r\nActionPlanner planner = new ActionPlanner(kernelInstance);\r\n\r\n\/\/ Use ActionPlanner to select the most appropriate function for a specific goal\r\nPlan result = await planner.CreatePlanAsync(goal);\r\n<\/code><\/pre>\n<p><span class=\"TextRun SCXW263814953 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW263814953 BCX8\">After running <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW263814953 BCX8\">CreatePlanAsync<\/span><span class=\"NormalTextRun SCXW263814953 BCX8\">, you can inspect the plan and then <\/span><\/span><span class=\"TextRun SCXW189502155 BCX8\" lang=\"EN-US\" style=\"text-align: var(--bs-body-text-align);\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW189502155 BCX8\">run your plan<\/span><span class=\"NormalTextRun SCXW189502155 BCX8\"> with the <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW189502155 BCX8\">InvokeAsync<\/span> <span class=\"NormalTextRun SCXW189502155 BCX8\">function.<\/span><\/span><\/p>\n<pre><code class=\"language-cs language-csharp\">\/\/ Execute the selected function with the provided instructions and rationale\r\nawait plan.InvokeAsync();\r\n<\/code><\/pre>\n<p>Below is an example of a constructed Action Plan using the Klarna plugin.<\/p>\n<pre class=\"prettyprint language-json\"><code class=\"language-json\">{\r\n  \"proposedPlan\": {\r\n    \"state\": [\r\n      {\r\n        \"Key\": \"INPUT\",\r\n        \"Value\": \"\"\r\n      }\r\n    ],\r\n    \"steps\": [\r\n      {\r\n        \"state\": [\r\n          {\r\n            \"Key\": \"INPUT\",\r\n            \"Value\": \"\"\r\n          }\r\n        ],\r\n        \"steps\": [],\r\n        \"parameters\": [\r\n          {\r\n            \"Key\": \"INPUT\",\r\n            \"Value\": \"\"\r\n          }\r\n        ],\r\n        \"outputs\": [],\r\n        \"next_step_index\": 0,\r\n        \"name\": \"productsUsingGET\",\r\n        \"skill_name\": \"KlarnaShoppingSkill\",\r\n        \"description\": \"\"\r\n      }\r\n    ],\r\n    \"parameters\": [\r\n      {\r\n        \"Key\": \"q\",\r\n        \"Value\": \"Canon Digital Camera\"\r\n      },\r\n      {\r\n        \"Key\": \"countryCode\",\r\n        \"Value\": \"US\"\r\n      },\r\n      {\r\n        \"Key\": \"INPUT\",\r\n        \"Value\": \"\"\r\n      },\r\n      {\r\n        \"Key\": \"size\",\r\n        \"Value\": \"1\"\r\n      },\r\n      {\r\n        \"Key\": \"server_url\",\r\n        \"Value\": \"https:\/\/www.klarna.com\/us\/shopping\"\r\n      }\r\n    ],\r\n    \"outputs\": [],\r\n    \"next_step_index\": 0,\r\n    \"name\": \"\",\r\n    \"skill_name\": \"Microsoft.SemanticKernel.Planning.Plan\",\r\n    \"description\": \"Given the following context, accomplish the user intent.\\nINPUT: How much is a Canon Digital Camera?\\nUser Intent:User intent: How much does a Canon Digital Camera cost?\"\r\n  },\r\n  \"type\": 0,\r\n  \"state\": 0\r\n}<\/code><\/pre>\n<p>In conclusion, Action Planner is an essential planning object within Semantic Kernel .Net that leverages an Intent Detection pattern to efficiently select and execute a suitable function based on a specific goal. Its ability to adapt and prioritize actions intelligently makes it a powerful tool in achieving desired outcomes.<\/p>\n<h2><strong>Next Steps:<\/strong><\/h2>\n<p>Learn more about planner concept <a href=\"https:\/\/learn.microsoft.com\/semantic-kernel\/concepts-sk\/planner\">here<\/a> and view an <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/dotnet\/samples\/KernelSyntaxExamples\/Example28_ActionPlanner.cs\">example<\/a>.<\/p>\n<p>Join the <a href=\"https:\/\/aka.ms\/sk-community\">community<\/a> and let us know what you think.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-92\" src=\"https:\/\/devblogs.microsoft.com\/semantic-kernel\/wp-content\/uploads\/sites\/78\/2023\/03\/skpatternsmallbw.png\" alt=\"Image skpatternsmallbw\" width=\"1211\" height=\"137\" srcset=\"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/03\/skpatternsmallbw.png 1211w, https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/03\/skpatternsmallbw-300x34.png 300w, https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/03\/skpatternsmallbw-1024x116.png 1024w, https:\/\/devblogs.microsoft.com\/agent-framework\/wp-content\/uploads\/sites\/78\/2023\/03\/skpatternsmallbw-768x87.png 768w\" sizes=\"(max-width: 1211px) 100vw, 1211px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Action Planner is no longer supported. See how to migrate legacy code away from it. This will be the first of a series of blog posts which will &#8216;step through&#8217; (no pun intended) the generation and evolution of planners available in Semantic Kernel; Action Planner, Sequential Planner, and Stepwise Planner. Planners are a critical [&hellip;]<\/p>\n","protected":false},"author":116113,"featured_media":834,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-502","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-semantic-kernel"],"acf":[],"blog_post_summary":"<p>The Action Planner is no longer supported. See how to migrate legacy code away from it. This will be the first of a series of blog posts which will &#8216;step through&#8217; (no pun intended) the generation and evolution of planners available in Semantic Kernel; Action Planner, Sequential Planner, and Stepwise Planner. Planners are a critical [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/502","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/users\/116113"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/comments?post=502"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/502\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media\/834"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media?parent=502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/categories?post=502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/tags?post=502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}