Skip to content

Commit 5e4e423

Browse files
committed
changes to update name of state props in both runtimes
1 parent 39b6a9b commit 5e4e423

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+186
-171
lines changed

dotnet/samples/GettingStartedWithProcesses/Step04/Step04_AgentOrchestration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ await process.StartAsync(
7474

7575
// Cleaning up created agents
7676
var processState = await localProcess.GetStateAsync();
77-
var agentState = (KernelProcessStepState<KernelProcessAgentExecutorState>)processState.Steps.Where(step => step.State.Id == "Student").FirstOrDefault()!.State;
77+
var agentState = (KernelProcessStepState<KernelProcessAgentExecutorState>)processState.Steps.Where(step => step.State.StepId == "Student").FirstOrDefault()!.State;
7878
var agentId = agentState?.State?.AgentId;
7979
if (agentId != null)
8080
{

dotnet/src/Experimental/Process.Abstractions/KernelProcess.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public KernelProcess(KernelProcessState state, IList<KernelProcessStepInfo> step
4747
: base(typeof(KernelProcess), state, edges ?? [])
4848
{
4949
Verify.NotNull(steps);
50-
Verify.NotNullOrWhiteSpace(state.Name);
50+
Verify.NotNullOrWhiteSpace(state.StepId);
5151

5252
this.Steps = [.. steps];
5353
}

dotnet/src/Experimental/Process.Abstractions/KernelProcessFunctionTarget.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Microsoft.SemanticKernel;
99
/// <summary>
1010
/// Represents the target for an edge in a Process
1111
/// </summary>
12+
[DataContract]
1213
public record KernelProcessTarget
1314
{
1415
/// <summary>
@@ -29,6 +30,7 @@ public KernelProcessTarget(ProcessTargetType type)
2930
/// <summary>
3031
/// Represents a state operations target for an edge in a Process
3132
/// </summary>
33+
[DataContract]
3234
public record KernelProcessStateTarget : KernelProcessTarget
3335
{
3436
/// <summary>
@@ -42,12 +44,14 @@ public KernelProcessStateTarget(VariableUpdate variableUpdate) : base(ProcessTar
4244
/// <summary>
4345
/// The associated <see cref="VariableUpdate"/>.
4446
/// </summary>
47+
[DataMember]
4548
public VariableUpdate VariableUpdate { get; init; }
4649
}
4750

4851
/// <summary>
4952
/// Represents a state operations target for an edge in a Process
5053
/// </summary>
54+
[DataContract]
5155
public record KernelProcessEmitTarget : KernelProcessTarget
5256
{
5357
/// <summary>
@@ -65,17 +69,20 @@ public KernelProcessEmitTarget(string eventName, Dictionary<string, string>? pay
6569
/// <summary>
6670
/// The name or type of the event to be emitted.
6771
/// </summary>
72+
[DataMember]
6873
public string EventName { get; init; }
6974

7075
/// <summary>
7176
/// /// The payload to be sent with the event.
7277
/// </summary>
78+
[DataMember]
7379
public Dictionary<string, string>? Payload { get; init; }
7480
}
7581

7682
/// <summary>
7783
/// Represents an agent invocation target for an edge in a Process
7884
/// </summary>
85+
[DataContract]
7986
public record KernelProcessAgentInvokeTarget : KernelProcessTarget
8087
{
8188
/// <summary>
@@ -99,21 +106,25 @@ public KernelProcessAgentInvokeTarget(string stepId, string? threadEval, List<st
99106
/// <summary>
100107
/// The unique identifier of the Step being targeted.
101108
/// </summary>
109+
[DataMember]
102110
public string StepId { get; init; }
103111

104112
/// <summary>
105113
/// An evaluation string that will be evaluated to determine the thread to run on.
106114
/// </summary>
115+
[DataMember]
107116
public string? ThreadEval { get; init; }
108117

109118
/// <summary>
110119
/// An evaluation string that will be evaluated to determine the messages to send to the target.
111120
/// </summary>
121+
[DataMember]
112122
public List<string>? MessagesInEval { get; init; }
113123

114124
/// <summary>
115125
/// An evaluation string that will be evaluated to determine the inputs to send to the target.
116126
/// </summary>
127+
[DataMember]
117128
public Dictionary<string, string> InputEvals { get; init; }
118129
}
119130

dotnet/src/Experimental/Process.Abstractions/KernelProcessMap.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public KernelProcessMap(KernelProcessMapState state, KernelProcessStepInfo opera
2323
: base(typeof(KernelProcessMap), state, edges)
2424
{
2525
Verify.NotNull(operation, nameof(operation));
26-
Verify.NotNullOrWhiteSpace(state.Name, $"{nameof(state)}.{nameof(KernelProcessMapState.Name)}");
27-
Verify.NotNullOrWhiteSpace(state.Id, $"{nameof(state)}.{nameof(KernelProcessMapState.Id)}");
26+
Verify.NotNullOrWhiteSpace(state.StepId, $"{nameof(state)}.{nameof(KernelProcessMapState.StepId)}");
27+
Verify.NotNullOrWhiteSpace(state.RunId, $"{nameof(state)}.{nameof(KernelProcessMapState.RunId)}");
2828

2929
this.Operation = operation;
3030
}

dotnet/src/Experimental/Process.Abstractions/KernelProcessProxy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public sealed record KernelProcessProxy : KernelProcessStepInfo
2323
public KernelProcessProxy(KernelProcessStepState state, Dictionary<string, List<KernelProcessEdge>> edges)
2424
: base(typeof(KernelProxyStep), state, edges)
2525
{
26-
Verify.NotNullOrWhiteSpace(state.Name, $"{nameof(state)}.{nameof(KernelProcessStepState.Name)}");
27-
Verify.NotNullOrWhiteSpace(state.Id, $"{nameof(state)}.{nameof(KernelProcessStepState.Id)}");
26+
Verify.NotNullOrWhiteSpace(state.StepId, $"{nameof(state)}.{nameof(KernelProcessStepState.StepId)}");
27+
Verify.NotNullOrWhiteSpace(state.RunId, $"{nameof(state)}.{nameof(KernelProcessStepState.RunId)}");
2828
}
2929
}

dotnet/src/Experimental/Process.Abstractions/KernelProcessStepState.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ internal static void RegisterDerivedType(Type derivedType)
4040
/// This may be null until a process containing this step has been invoked.
4141
/// </summary>
4242
[DataMember]
43-
public string? Id { get; init; }
43+
public string? RunId { get; set; }
4444

4545
/// <summary>
4646
/// The name of the Step. This is intended to be human readable and is not required to be unique. If
4747
/// not provided, the name will be derived from the steps .NET type.
4848
/// </summary>
4949
[DataMember]
50-
public string Name { get; init; }
50+
public string StepId { get; init; }
5151

5252
/// <summary>
5353
/// Version of the state
@@ -66,8 +66,8 @@ public KernelProcessStepState(string name, string version, string? id = null)
6666
Verify.NotNullOrWhiteSpace(name, nameof(name));
6767
Verify.NotNullOrWhiteSpace(version, nameof(version));
6868

69-
this.Id = id;
70-
this.Name = name;
69+
this.RunId = id;
70+
this.StepId = name;
7171
this.Version = version;
7272
}
7373
}
@@ -96,8 +96,8 @@ public KernelProcessStepState(string name, string version, string? id = null)
9696
{
9797
Verify.NotNullOrWhiteSpace(name);
9898

99-
this.Id = id;
100-
this.Name = name;
99+
this.RunId = id;
100+
this.StepId = name;
101101
this.Version = version;
102102
}
103103
}

dotnet/src/Experimental/Process.Abstractions/Models/Storage/StorageProcessState.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public static StorageProcessState ToKernelStorageProcessState(this KernelProcess
4848
{
4949
return new StorageProcessState
5050
{
51-
ProcessName = kernelProcess.State?.Name ?? string.Empty,
52-
ProcessInstance = kernelProcess.State?.Id ?? string.Empty,
53-
Steps = kernelProcess.Steps.ToList().ToDictionary(step => step.State.Name, step => step.State.Id ?? string.Empty) ?? []
51+
ProcessName = kernelProcess.State?.StepId ?? string.Empty,
52+
ProcessInstance = kernelProcess.State?.RunId ?? string.Empty,
53+
Steps = kernelProcess.Steps.ToList().ToDictionary(step => step.State.StepId, step => step.State.RunId ?? string.Empty) ?? []
5454
};
5555
}
5656
}

dotnet/src/Experimental/Process.Abstractions/Serialization/Model/Workflow.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

33
using System.Collections.Generic;
4+
using System.Runtime.Serialization;
45
using System.Text.Json.Serialization;
56
using Microsoft.SemanticKernel.Agents;
67
using Microsoft.SemanticKernel.Process.Internal;
@@ -843,6 +844,7 @@ public enum HITLMode
843844
/// Represents an update operation to be performed on a workflow variable.
844845
/// Variable updates allow workflows to modify state based on conditions and execution flow.
845846
/// </summary>
847+
[DataContract]
846848
public sealed class VariableUpdate
847849
{
848850
/// <summary>
@@ -851,6 +853,7 @@ public sealed class VariableUpdate
851853
/// </summary>
852854
[YamlMember(Alias = "path")]
853855
[JsonPropertyName("path")]
856+
[DataMember]
854857
public string Path { get; set; } = string.Empty;
855858

856859
/// <summary>
@@ -859,6 +862,7 @@ public sealed class VariableUpdate
859862
/// </summary>
860863
[YamlMember(Alias = "operation")]
861864
[JsonPropertyName("operation")]
865+
[DataMember]
862866
public StateUpdateOperations Operation { get; set; }
863867

864868
/// <summary>
@@ -867,6 +871,7 @@ public sealed class VariableUpdate
867871
/// </summary>
868872
[YamlMember(Alias = "value")]
869873
[JsonPropertyName("value")]
874+
870875
public object? Value { get; set; } = string.Empty;
871876
}
872877

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static string ExportProcess(KernelProcess process)
2323

2424
Workflow workflow = new()
2525
{
26-
Name = process.State.Name,
26+
Name = process.State.StepId,
2727
Description = process.Description,
2828
FormatVersion = "1.0",
2929
WorkflowVersion = process.State.Version,
@@ -50,7 +50,7 @@ private static Node GetNodeFromStep(KernelProcessStepInfo stepInfo)
5050
{
5151
var agentNode = new Node()
5252
{
53-
Id = agentStep.State.Id ?? throw new KernelException("All steps must have an Id."),
53+
Id = agentStep.State.RunId ?? throw new KernelException("All steps must have an Id."),
5454
Description = agentStep.Description,
5555
Type = "agent",
5656
Inputs = agentStep.Inputs.ToDictionary((kvp) => kvp.Key, (kvp) =>

dotnet/src/Experimental/Process.Core/Tools/ProcessVisualizationExtensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ private static string RenderProcess(KernelProcess process, int level, bool isSub
6464

6565
// Dictionary to map step IDs to step names
6666
var stepNames = process.Steps
67-
.Where(step => step.State.Id != null && step.State.Name != null)
67+
.Where(step => step.State.RunId != null && step.State.StepId != null)
6868
.ToDictionary(
69-
step => step.State.Id!,
70-
step => step.State.Name!
69+
step => step.State.RunId!,
70+
step => step.State.StepId!
7171
);
7272

7373
// Add Start and End nodes only if this is not a sub-process
@@ -80,8 +80,8 @@ private static string RenderProcess(KernelProcess process, int level, bool isSub
8080
// Process each step
8181
foreach (var step in process.Steps)
8282
{
83-
var stepId = step.State.Id;
84-
var stepName = step.State.Name;
83+
var stepId = step.State.RunId;
84+
var stepName = step.State.StepId;
8585

8686
// Check if the step is a nested process (sub-process)
8787
if (step is KernelProcess nestedProcess && level < maxLevel)
@@ -115,7 +115,7 @@ private static string RenderProcess(KernelProcess process, int level, bool isSub
115115
var stepEdges = kvp.Value;
116116

117117
// Skip drawing edges that point to a nested process as an entry point
118-
if (stepNames.ContainsKey(eventId) && process.Steps.Any(s => s.State.Name == eventId && s is KernelProcess))
118+
if (stepNames.ContainsKey(eventId) && process.Steps.Any(s => s.State.StepId == eventId && s is KernelProcess))
119119
{
120120
continue;
121121
}
@@ -156,8 +156,8 @@ private static string RenderProcess(KernelProcess process, int level, bool isSub
156156
// Connect Start to the first step and the last step to End (only for the main process)
157157
if (!isSubProcess && process.Steps.Count > 0)
158158
{
159-
var firstStepName = process.Steps.First().State.Name;
160-
var lastStepName = process.Steps.Last().State.Name;
159+
var firstStepName = process.Steps.First().State.StepId;
160+
var lastStepName = process.Steps.Last().State.StepId;
161161

162162
sb.AppendLine($"{indentation}Start --> {firstStepName}[\"{firstStepName}\"]");
163163
sb.AppendLine($"{indentation}{lastStepName}[\"{lastStepName}\"] --> End");

dotnet/src/Experimental/Process.Core/Workflow/WorkflowBuilder.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,10 @@ public static Task<Workflow> BuildWorkflow(KernelProcess process)
325325

326326
Workflow workflow = new()
327327
{
328-
Id = process.State.Id ?? throw new KernelException("The process must have an Id set"),
328+
Id = process.State.RunId ?? throw new KernelException("The process must have an Id set"),
329329
Description = process.Description,
330330
FormatVersion = "1.0",
331-
Name = process.State.Name,
331+
Name = process.State.StepId,
332332
Nodes = [new Node { Id = "End", Type = "declarative", Version = "1.0", Description = "Terminal state" }],
333333
Variables = [],
334334
};
@@ -403,7 +403,7 @@ public static Task<Workflow> BuildWorkflow(KernelProcess process)
403403

404404
private static Node BuildNode(KernelProcessStepInfo step, List<OrchestrationStep> orchestrationSteps)
405405
{
406-
Verify.NotNullOrWhiteSpace(step?.State?.Id, nameof(step.State.Id));
406+
Verify.NotNullOrWhiteSpace(step?.State?.RunId, nameof(step.State.RunId));
407407

408408
if (step is KernelProcessAgentStep agentStep)
409409
{
@@ -418,12 +418,12 @@ private static Node BuildNode(KernelProcessStepInfo step, List<OrchestrationStep
418418

419419
var node = new Node()
420420
{
421-
Id = step.State.Id,
421+
Id = step.State.RunId,
422422
Type = "dotnet",
423423
Agent = new AgentDefinition()
424424
{
425425
Type = innerStepTypeString,
426-
Id = step.State.Id
426+
Id = step.State.RunId
427427
}
428428
};
429429

@@ -433,7 +433,7 @@ private static Node BuildNode(KernelProcessStepInfo step, List<OrchestrationStep
433433
{
434434
ListenFor = new ListenCondition()
435435
{
436-
From = step.State.Id,
436+
From = step.State.RunId,
437437
Event = edge.Key,
438438
Condition = edge.Value.FirstOrDefault()?.Condition.DeclarativeDefinition
439439
},
@@ -465,14 +465,14 @@ private static Node BuildAgentNode(KernelProcessAgentStep agentStep, List<Orches
465465
{
466466
Verify.NotNull(agentStep);
467467

468-
if (agentStep.AgentDefinition is null || string.IsNullOrWhiteSpace(agentStep.State?.Id) || string.IsNullOrWhiteSpace(agentStep.AgentDefinition.Type))
468+
if (agentStep.AgentDefinition is null || string.IsNullOrWhiteSpace(agentStep.State?.RunId) || string.IsNullOrWhiteSpace(agentStep.AgentDefinition.Type))
469469
{
470470
throw new InvalidOperationException("Attempt to build a workflow node from step with no Id");
471471
}
472472

473473
var node = new Node()
474474
{
475-
Id = agentStep.State.Id!,
475+
Id = agentStep.State.RunId!,
476476
Type = agentStep.AgentDefinition.Type!,
477477
Agent = agentStep.AgentDefinition,
478478
HumanInLoopType = agentStep.HumanInLoopMode,
@@ -511,7 +511,7 @@ private static Node BuildAgentNode(KernelProcessAgentStep agentStep, List<Orches
511511
{
512512
ListenFor = new ListenCondition()
513513
{
514-
From = agentStep.State.Id,
514+
From = agentStep.State.RunId,
515515
Event = ResolveEventName(edge.Key.key),
516516
Condition = edge.Key.DeclarativeDefinition
517517
},

dotnet/src/Experimental/Process.IntegrationTestRunner.Dapr/DaprTestProcessContext.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ internal sealed class DaprTestProcessContext : KernelProcessContext
2323
/// <param name="httpClient"></param>
2424
internal DaprTestProcessContext(KernelProcess process, HttpClient httpClient)
2525
{
26-
if (string.IsNullOrWhiteSpace(process.State.Id))
26+
if (string.IsNullOrWhiteSpace(process.State.RunId))
2727
{
28-
process = process with { State = process.State with { Id = Guid.NewGuid().ToString() } };
28+
process = process with { State = process.State with { RunId = Guid.NewGuid().ToString() } };
2929
}
3030

3131
this._process = process;
32-
this._processId = process.State.Id;
32+
this._processId = process.State.RunId;
3333
this._httpClient = httpClient;
3434

3535
this._serializerOptions = new JsonSerializerOptions()
@@ -146,5 +146,5 @@ public override Task StopAsync()
146146
};
147147
}
148148

149-
public override Task<string> GetProcessIdAsync() => Task.FromResult(this._process?.State.Id!);
149+
public override Task<string> GetProcessIdAsync() => Task.FromResult(this._process?.State.RunId!);
150150
}

dotnet/src/Experimental/Process.IntegrationTests.Shared/ProcessCycleTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public async Task TestCycleAndExitWithFanInAsync()
7474
var processContext = await this._fixture.StartProcessAsync(kernelProcess, kernel, new KernelProcessEvent() { Id = CommonEvents.StartProcess, Data = "foo" });
7575

7676
var processState = await processContext.GetStateAsync();
77-
var cStepState = processState.Steps.Where(s => s.State.Name == "CStep").FirstOrDefault()?.State as KernelProcessStepState<CStepState>;
77+
var cStepState = processState.Steps.Where(s => s.State.StepId == "CStep").FirstOrDefault()?.State as KernelProcessStepState<CStepState>;
7878

7979
Assert.NotNull(cStepState?.State);
8080
Assert.Equal(3, cStepState.State.CurrentCycle);

0 commit comments

Comments
 (0)