Skip to content

Commit

Permalink
Extracting plan json from ActionPlanner result (microsoft#1802)
Browse files Browse the repository at this point in the history
### Motivation and Context
<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
LLM can return additional texts (i.e., preambles, explanations) around
the proposed plan, so this PR extracts a well-formed JSON from the
result of the planner using a RegEx and balanced group concepts.

In response to: microsoft#1726

### Description
<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
Also, updates any use of Plan State to Plan Parameters due to previous
Planner refactor.

### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->
- [x] The code builds clean without any errors or warnings
- [x] The PR follows SK Contribution Guidelines
(https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
- [x] The code follows the .NET coding conventions
(https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions)
verified with `dotnet format`
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

---------

Co-authored-by: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com>
  • Loading branch information
teresaqhoang and dmytrostruk authored Jul 7, 2023
1 parent db492ba commit f361dcb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ public async Task<string> AcquireExternalInformationAsync(string userIntent, SKC

if (plan.Steps.Count > 0)
{
// Parameters stored in plan's top level state
this.MergeContextIntoPlan(context.Variables, plan.State);
// Parameters stored in plan's top level
this.MergeContextIntoPlan(context.Variables, plan.Parameters);

// TODO: Improve Kernel to give developers option to skip this override
// (i.e., keep functions regardless of whether they're available in the planner's context or not)
Plan sanitizedPlan = this.SanitizePlan(plan, context);
sanitizedPlan.State.Update(plan.State);
sanitizedPlan.Parameters.Update(plan.Parameters);

this.ProposedPlan = new ProposedPlan(sanitizedPlan, this._planner.PlannerOptions!.Type, PlanState.NoOp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ export const PlanViewer: React.FC<PlanViewerProps> = ({ message, messageIndex, g

const planState = message.state ?? parsedContent.state;

// If plan came from ActionPlanner, use parameters from top-level plan state
// TODO: Can remove this after consuming nugets with #997 fixed
// If plan came from ActionPlanner, use parameters from top-level of plan
if (parsedContent.type === PlanType.Action) {
originalPlan.steps[0].parameters = originalPlan.state;
originalPlan.steps[0].parameters = originalPlan.parameters;
}

const userIntentPrefix = 'User Intent:User intent: ';
Expand Down

0 comments on commit f361dcb

Please sign in to comment.