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 ‘step through’ (no pun intended) the generation and evolution of planners available in Semantic Kernel; Action Planner, Sequential Planner, and Stepwise Planner. Planners are a critical element of Semantic Kernel, each has its own strengths, so it’s important to understand how each planner works so you can pick the best one for your needs.Â
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. 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. Â
In this blog we will look at the Action Planner.
The Action Planner works by identifying the most relevant plugin that achieves the user’s goal. What makes it different from other planners is that it only chooses a single plugin to run. See below example of Chat Copilot leveraging the Action Planner with the Klarna plugin to generate a response. Â
This planner is helpful in scenarios where you have already defined higher-order plugins (or plans!) that accomplish a user’s 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 multiple plug-ins, you may need to define your own planner or use a more complex planner like Sequential Planner or Stepwise Planner.Â
Action Planner works by implementing an intent detection pattern, which identifies a user’s intent and compares it to the available plug-in functions loaded into the kernel. Once it finds a plug-in that most aligns with a user’s goal, it uses AI to populate the necessary input parameters.
Here’s an example of how you can use Action Planner in your project:
// Initialize a new instance of the ActionPlanner class
ActionPlanner planner = new ActionPlanner(kernelInstance);
// Use ActionPlanner to select the most appropriate function for a specific goal
Plan result = await planner.CreatePlanAsync(goal);
After running CreatePlanAsync, you can inspect the plan and then run your plan with the InvokeAsync function.
// Execute the selected function with the provided instructions and rationale
await plan.InvokeAsync();
Below is an example of a constructed Action Plan using the Klarna plugin.
{
"proposedPlan": {
"state": [
{
"Key": "INPUT",
"Value": ""
}
],
"steps": [
{
"state": [
{
"Key": "INPUT",
"Value": ""
}
],
"steps": [],
"parameters": [
{
"Key": "INPUT",
"Value": ""
}
],
"outputs": [],
"next_step_index": 0,
"name": "productsUsingGET",
"skill_name": "KlarnaShoppingSkill",
"description": ""
}
],
"parameters": [
{
"Key": "q",
"Value": "Canon Digital Camera"
},
{
"Key": "countryCode",
"Value": "US"
},
{
"Key": "INPUT",
"Value": ""
},
{
"Key": "size",
"Value": "1"
},
{
"Key": "server_url",
"Value": "https://www.klarna.com/us/shopping"
}
],
"outputs": [],
"next_step_index": 0,
"name": "",
"skill_name": "Microsoft.SemanticKernel.Planning.Plan",
"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?"
},
"type": 0,
"state": 0
}
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.
Next Steps:
Learn more about planner concept here and view an example.
Join the community and let us know what you think.
0 comments