From cf6e0070b40875cace5f7c574185cc0165ebb443 Mon Sep 17 00:00:00 2001 From: Shyju Krishnankutty Date: Mon, 26 Jan 2026 09:44:08 -0800 Subject: [PATCH] Cleanup --- .../WorkflowHelper.cs | 2 +- .../Microsoft.Agents.AI.Workflows/Workflow.cs | 31 +++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/dotnet/src/Microsoft.Agents.AI.DurableTask/WorkflowHelper.cs b/dotnet/src/Microsoft.Agents.AI.DurableTask/WorkflowHelper.cs index fe2da3d28d..1237ad7081 100644 --- a/dotnet/src/Microsoft.Agents.AI.DurableTask/WorkflowHelper.cs +++ b/dotnet/src/Microsoft.Agents.AI.DurableTask/WorkflowHelper.cs @@ -65,7 +65,7 @@ public static class WorkflowHelper Dictionary executors = workflow.ReflectExecutors(); Dictionary> edges = workflow.ReflectEdges(); - Dictionary<(string SourceId, string TargetId), Func?> edgeConditions = workflow.GetEdgeConditions(); + Dictionary<(string SourceId, string TargetId), Func?> edgeConditions = workflow.ReflectEdgeConditions(); WorkflowExecutionPlan plan = new(); diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/Workflow.cs b/dotnet/src/Microsoft.Agents.AI.Workflows/Workflow.cs index 28edf94943..0c54d3b8c7 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows/Workflow.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows/Workflow.cs @@ -37,20 +37,31 @@ public class Workflow } /// - /// Gets the condition functions for direct edges, keyed by (sourceId, targetId) tuple. + /// Gets a mapping of edge identifiers to their associated condition delegates. /// - /// A dictionary mapping edge connections to their condition functions (null if no condition). - /// This method creates a new dictionary each time it is called to ensure thread safety. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1024:Use properties where appropriate", Justification = "Method creates a new collection on each call.")] - public Dictionary<(string SourceId, string TargetId), Func?> GetEdgeConditions() + /// The returned dictionary includes only edges that have direct edge data. The condition + /// delegate can be used to determine whether the edge is active or valid for a given input. Edges without direct + /// edge data are not included in the result. + /// A dictionary where each key is a tuple containing the source and target node identifiers, and each value is a + /// delegate that evaluates the condition for the corresponding edge. The value is if the + /// edge has no associated condition. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1024:Use properties where appropriate", Justification = "")] + public Dictionary<(string SourceId, string TargetId), Func?> ReflectEdgeConditions() { - Dictionary<(string SourceId, string TargetId), Func?> conditions = []; - - foreach (KeyValuePair> edgeGroup in this.Edges) + int capacity = 0; + foreach (HashSet edgeSet in this.Edges.Values) { - foreach (Edge edge in edgeGroup.Value) + capacity += edgeSet.Count; + } + + Dictionary<(string SourceId, string TargetId), Func?> conditions = new(capacity); + + foreach (HashSet edgeSet in this.Edges.Values) + { + foreach (Edge edge in edgeSet) { - if (edge.DirectEdgeData is DirectEdgeData directEdge) + DirectEdgeData? directEdge = edge.DirectEdgeData; + if (directEdge is not null) { conditions[(directEdge.SourceId, directEdge.SinkId)] = directEdge.Condition; }