Creating and running a plan
Now that we have a planner, we can use it to create a plan for a user’s request and then invoke the plan to get a result. In both languages, we use two steps, one to create the plan and another one to execute it.
For the next two code snippets, assume you have the user’s request loaded into the ask
string. Let’s see how to call the planner:
C#
var plan = await planner.CreatePlanAsync(kernel, ask); var result = await plan.InvokeAsync(kernel); Console.Write ($"Results: {result}");
Python
result = await planner.invoke(kernel, ask) print(result.final_answer)
You may remember from Chapter 1 that in Python, the result variable contains all the steps to create the plan, so in order to see the plan’s results, you need to print result.final_answer
. If you print the result
variable, you’ll get a large JSON object.
An example of how a planner can help
Let’s see a simple example that already shows...