-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net Processes - Refactoring/expanding Process Sample02 (#9811)
### Description - Updating Sample 02 to expand the usage and show case how to refactor the same process by using subprocesses as steps. - Improving README file with more details on this sample - Add more unit tests for Process testing/improving comments Fixes #9836 Fixes #9837 ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄 --------- Co-authored-by: Estefania Tenorio <estenori@microsoft.com>
- Loading branch information
1 parent
30b67ec
commit 3c13912
Showing
23 changed files
with
686 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
dotnet/samples/GettingStartedWithProcesses/Step02/Processes/NewAccountCreationProcess.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using Microsoft.SemanticKernel; | ||
using Step02.Models; | ||
using Step02.Steps; | ||
|
||
namespace Step02.Processes; | ||
|
||
/// <summary> | ||
/// Demonstrate creation of <see cref="KernelProcess"/> and | ||
/// eliciting its response to five explicit user messages.<br/> | ||
/// For each test there is a different set of user messages that will cause different steps to be triggered using the same pipeline.<br/> | ||
/// For visual reference of the process check the <see href="https://github.com/microsoft/semantic-kernel/tree/main/dotnet/samples/GettingStartedWithProcesses/README.md#step02b_accountOpening" >diagram</see>. | ||
/// </summary> | ||
public static class NewAccountCreationProcess | ||
{ | ||
public static ProcessBuilder CreateProcess() | ||
{ | ||
ProcessBuilder process = new("AccountCreationProcess"); | ||
|
||
var coreSystemRecordCreationStep = process.AddStepFromType<NewAccountStep>(); | ||
var marketingRecordCreationStep = process.AddStepFromType<NewMarketingEntryStep>(); | ||
var crmRecordStep = process.AddStepFromType<CRMRecordCreationStep>(); | ||
var welcomePacketStep = process.AddStepFromType<WelcomePacketStep>(); | ||
|
||
// When the newCustomerForm is completed... | ||
process | ||
.OnInputEvent(AccountOpeningEvents.NewCustomerFormCompleted) | ||
// The information gets passed to the core system record creation step | ||
.SendEventTo(new ProcessFunctionTargetBuilder(coreSystemRecordCreationStep, functionName: NewAccountStep.Functions.CreateNewAccount, parameterName: "customerDetails")); | ||
|
||
// When the newCustomerForm is completed, the user interaction transcript with the user is passed to the core system record creation step | ||
process | ||
.OnInputEvent(AccountOpeningEvents.CustomerInteractionTranscriptReady) | ||
.SendEventTo(new ProcessFunctionTargetBuilder(coreSystemRecordCreationStep, functionName: NewAccountStep.Functions.CreateNewAccount, parameterName: "interactionTranscript")); | ||
|
||
// When the fraudDetectionCheck step passes, the information gets to core system record creation step to kickstart this step | ||
process | ||
.OnInputEvent(AccountOpeningEvents.NewAccountVerificationCheckPassed) | ||
.SendEventTo(new ProcessFunctionTargetBuilder(coreSystemRecordCreationStep, functionName: NewAccountStep.Functions.CreateNewAccount, parameterName: "previousCheckSucceeded")); | ||
|
||
// When the coreSystemRecordCreation step successfully creates a new accountId, it will trigger the creation of a new marketing entry through the marketingRecordCreation step | ||
coreSystemRecordCreationStep | ||
.OnEvent(AccountOpeningEvents.NewMarketingRecordInfoReady) | ||
.SendEventTo(new ProcessFunctionTargetBuilder(marketingRecordCreationStep, functionName: NewMarketingEntryStep.Functions.CreateNewMarketingEntry, parameterName: "userDetails")); | ||
|
||
// When the coreSystemRecordCreation step successfully creates a new accountId, it will trigger the creation of a new CRM entry through the crmRecord step | ||
coreSystemRecordCreationStep | ||
.OnEvent(AccountOpeningEvents.CRMRecordInfoReady) | ||
.SendEventTo(new ProcessFunctionTargetBuilder(crmRecordStep, functionName: CRMRecordCreationStep.Functions.CreateCRMEntry, parameterName: "userInteractionDetails")); | ||
|
||
// ParameterName is necessary when the step has multiple input arguments like welcomePacketStep.CreateWelcomePacketAsync | ||
// When the coreSystemRecordCreation step successfully creates a new accountId, it will pass the account information details to the welcomePacket step | ||
coreSystemRecordCreationStep | ||
.OnEvent(AccountOpeningEvents.NewAccountDetailsReady) | ||
.SendEventTo(new ProcessFunctionTargetBuilder(welcomePacketStep, parameterName: "accountDetails")); | ||
|
||
// When the marketingRecordCreation step successfully creates a new marketing entry, it will notify the welcomePacket step it is ready | ||
marketingRecordCreationStep | ||
.OnEvent(AccountOpeningEvents.NewMarketingEntryCreated) | ||
.SendEventTo(new ProcessFunctionTargetBuilder(welcomePacketStep, parameterName: "marketingEntryCreated")); | ||
|
||
// When the crmRecord step successfully creates a new CRM entry, it will notify the welcomePacket step it is ready | ||
crmRecordStep | ||
.OnEvent(AccountOpeningEvents.CRMRecordInfoEntryCreated) | ||
.SendEventTo(new ProcessFunctionTargetBuilder(welcomePacketStep, parameterName: "crmRecordCreated")); | ||
|
||
return process; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
dotnet/samples/GettingStartedWithProcesses/Step02/Processes/NewAccountVerificationProcess.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using Microsoft.SemanticKernel; | ||
using Step02.Models; | ||
using Step02.Steps; | ||
|
||
namespace Step02.Processes; | ||
|
||
/// <summary> | ||
/// Demonstrate creation of <see cref="KernelProcess"/> and | ||
/// eliciting its response to five explicit user messages.<br/> | ||
/// For each test there is a different set of user messages that will cause different steps to be triggered using the same pipeline.<br/> | ||
/// For visual reference of the process check the <see href="https://github.com/microsoft/semantic-kernel/tree/main/dotnet/samples/GettingStartedWithProcesses/README.md#step02b_accountOpening" >diagram</see>. | ||
/// </summary> | ||
public static class NewAccountVerificationProcess | ||
{ | ||
public static ProcessBuilder CreateProcess() | ||
{ | ||
ProcessBuilder process = new("AccountVerificationProcess"); | ||
|
||
var customerCreditCheckStep = process.AddStepFromType<CreditScoreCheckStep>(); | ||
var fraudDetectionCheckStep = process.AddStepFromType<FraudDetectionStep>(); | ||
|
||
// When the newCustomerForm is completed... | ||
process | ||
.OnInputEvent(AccountOpeningEvents.NewCustomerFormCompleted) | ||
// The information gets passed to the core system record creation step | ||
.SendEventTo(new ProcessFunctionTargetBuilder(customerCreditCheckStep, functionName: CreditScoreCheckStep.Functions.DetermineCreditScore, parameterName: "customerDetails")) | ||
// The information gets passed to the fraud detection step for validation | ||
.SendEventTo(new ProcessFunctionTargetBuilder(fraudDetectionCheckStep, functionName: FraudDetectionStep.Functions.FraudDetectionCheck, parameterName: "customerDetails")); | ||
|
||
// When the creditScoreCheck step results in Approval, the information gets to the fraudDetection step to kickstart this step | ||
customerCreditCheckStep | ||
.OnEvent(AccountOpeningEvents.CreditScoreCheckApproved) | ||
.SendEventTo(new ProcessFunctionTargetBuilder(fraudDetectionCheckStep, functionName: FraudDetectionStep.Functions.FraudDetectionCheck, parameterName: "previousCheckSucceeded")); | ||
|
||
return process; | ||
} | ||
} |
Oops, something went wrong.