Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CopilotChat: Ensure the planner has full context and users UserIntent as the goal. #686

Merged
merged 6 commits into from
Apr 27, 2023
15 changes: 12 additions & 3 deletions samples/apps/copilot-chat-app/webapi/Skills/ChatSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.SemanticKernel.AI.TextCompletion;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.Planning;
using Microsoft.SemanticKernel.SkillDefinition;
using SemanticKernel.Service.Config;
using SemanticKernel.Service.Storage;
Expand Down Expand Up @@ -198,10 +199,18 @@ public async Task<string> AcquireExternalInformationAsync(SKContext context)
return string.Empty;
}

// Skills run in the planner may modify the SKContext.
// Clone the context to avoid modifying the original context variables.
SKContext plannerContext = Utilities.CopyContextWithVariablesClone(context);

// Use the user intent message as the input to the plan.
plannerContext.Variables.Update(plannerContext["userIntent"]);

// Create a plan and run it.
SKContext planContext = await (await (await this._plannerFactoryAsync(this._kernel))
.CreatePlanAsync(context["userIntent"]))
.InvokeAsync(input: context["userIntent"], context: context);
Plan plan = await (await this._plannerFactoryAsync(this._kernel))
.CreatePlanAsync(plannerContext.Variables.Input);

SKContext planContext = await plan.InvokeAsync(context: plannerContext);

// The result of the plan may be from an OpenAPI skill. Attempt to extract JSON from the response.
if (!this.TryExtractJsonFromPlanResult(planContext.Variables.Input, out string planResult))
Expand Down