Skip to content

Commit 6efcc84

Browse files
.Net: Exposing ToJson method on FoundryProcessBuilder. (#12200)
Exposing the `ToJsonAsync` method on the `FoundryProcessBuilder` to that users can save the JSON if needed. ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] 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 - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄 Co-authored-by: Mark Wallace <127216156+markwallace-microsoft@users.noreply.github.com>
1 parent 93c443e commit 6efcc84

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

dotnet/samples/GettingStartedWithProcesses/Step06/Step06_FoundryAgentProcess.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ public async Task ProcessWithTwoAgentMathChat()
9898
processBuilder.OnEvent(teacher, "correct_answer")
9999
.StopProcess();
100100

101-
/**************************** Build and Deploy ***************************/
101+
// Verify that the process can be built and serialized to json
102+
var processJson = await processBuilder.ToJsonAsync();
103+
Assert.NotEmpty(processJson);
102104

103-
var process = processBuilder.Build();
104-
var foundryWorkflowId = await processBuilder.DeployToFoundryAsync(process, TestConfiguration.AzureAI.WorkflowEndpoint);
105+
var foundryWorkflowId = await processBuilder.DeployToFoundryAsync(TestConfiguration.AzureAI.WorkflowEndpoint);
106+
Assert.NotEmpty(foundryWorkflowId);
105107
}
106108

107109
/// <summary>

dotnet/src/Experimental/Process.Core/FoundryProcessBuilder.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,16 @@ public KernelProcess Build(KernelProcessStateMetadata? stateMetadata = null)
157157
/// <summary>
158158
/// Deploys the process to Azure Foundry.
159159
/// </summary>
160-
/// <param name="process">The built process to deploy.</param>
161160
/// <param name="endpoint">Th workflow endpoint to deploy to.</param>
162161
/// <param name="credential">The credential to use.</param>
163162
/// <param name="cancellationToken"></param>
164163
/// <returns></returns>
165-
public async Task<string> DeployToFoundryAsync(KernelProcess process, string endpoint, TokenCredential? credential = null, CancellationToken cancellationToken = default)
164+
public async Task<string> DeployToFoundryAsync(string endpoint, TokenCredential? credential = null, CancellationToken cancellationToken = default)
166165
{
166+
// Build the process
167+
var process = this.Build();
168+
169+
// Serialize and deploy
167170
using var httpClient = new HttpClient();
168171
if (credential != null)
169172
{
@@ -192,6 +195,16 @@ public async Task<string> DeployToFoundryAsync(KernelProcess process, string end
192195
return foundryWorkflow?.Id ?? throw new KernelException("Failed to parse the response from Foundry.");
193196
}
194197

198+
/// <summary>
199+
/// Serializes the process to JSON.
200+
/// </summary>
201+
public async Task<string> ToJsonAsync()
202+
{
203+
var process = this.Build();
204+
var workflow = await WorkflowBuilder.BuildWorkflow(process).ConfigureAwait(false);
205+
return WorkflowSerializer.SerializeToJson(workflow);
206+
}
207+
195208
private class FoundryWorkflow
196209
{
197210
[JsonPropertyName("id")]

0 commit comments

Comments
 (0)