From 35caf2823950072b631c6c0ab66fb3c787ce5c3b Mon Sep 17 00:00:00 2001 From: Shyju Krishnankutty Date: Mon, 26 Jan 2026 17:26:52 -0800 Subject: [PATCH] Expose internal items to Microsoft.Agents.AI.DurableTask. Other minor cleanups --- dotnet/agent-framework-dotnet.slnx | 2 +- .../ConsoleApps/12_WorkflowLoop/Program.cs | 2 +- .../DurableExecution.cs | 1 + .../DurableWorkflowOptions.cs | 1 - .../WorkflowHelper.cs | 20 +++++++---- .../Microsoft.Agents.AI.Workflows.csproj | 1 + .../Microsoft.Agents.AI.Workflows/Workflow.cs | 34 ------------------- 7 files changed, 17 insertions(+), 44 deletions(-) diff --git a/dotnet/agent-framework-dotnet.slnx b/dotnet/agent-framework-dotnet.slnx index ddcd9f4080..31816b9571 100644 --- a/dotnet/agent-framework-dotnet.slnx +++ b/dotnet/agent-framework-dotnet.slnx @@ -54,7 +54,7 @@ - + diff --git a/dotnet/samples/DurableAgents/ConsoleApps/12_WorkflowLoop/Program.cs b/dotnet/samples/DurableAgents/ConsoleApps/12_WorkflowLoop/Program.cs index a5723c59d1..c7199cbfd4 100644 --- a/dotnet/samples/DurableAgents/ConsoleApps/12_WorkflowLoop/Program.cs +++ b/dotnet/samples/DurableAgents/ConsoleApps/12_WorkflowLoop/Program.cs @@ -34,7 +34,7 @@ string dtsConnectionString = Environment.GetEnvironmentVariable("DURABLE_TASK_SC ?? "Endpoint=http://localhost:8080;TaskHub=default;Authentication=None"; var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); -var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; +var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT") ?? "gpt-4o-mini"; var chatClient = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()).GetChatClient(deploymentName).AsIChatClient(); // Define executors for the workflow diff --git a/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableExecution.cs b/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableExecution.cs index e69de29bb2..5f282702bb 100644 --- a/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableExecution.cs +++ b/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableExecution.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableWorkflowOptions.cs b/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableWorkflowOptions.cs index 12fc931314..4a72aed3c5 100644 --- a/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableWorkflowOptions.cs +++ b/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableWorkflowOptions.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. using Microsoft.Agents.AI.Workflows; -using Microsoft.Agents.AI.Workflows.Checkpointing; namespace Microsoft.Agents.AI.DurableTask; diff --git a/dotnet/src/Microsoft.Agents.AI.DurableTask/WorkflowHelper.cs b/dotnet/src/Microsoft.Agents.AI.DurableTask/WorkflowHelper.cs index f30b6a1efd..231cd34d23 100644 --- a/dotnet/src/Microsoft.Agents.AI.DurableTask/WorkflowHelper.cs +++ b/dotnet/src/Microsoft.Agents.AI.DurableTask/WorkflowHelper.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. using Microsoft.Agents.AI.Workflows; -using Microsoft.Agents.AI.Workflows.Checkpointing; namespace Microsoft.Agents.AI.DurableTask; @@ -65,8 +64,7 @@ public static class WorkflowHelper ArgumentNullException.ThrowIfNull(workflow); Dictionary executors = workflow.ReflectExecutors(); - Dictionary> edges = workflow.ReflectEdges(); - Dictionary<(string SourceId, string TargetId), Func?> edgeConditions = workflow.ReflectEdgeConditions(); + Dictionary> edges = workflow.Edges; WorkflowExecutionPlan plan = new() { @@ -90,15 +88,16 @@ public static class WorkflowHelper plan.ExecutorOutputTypes[executor.Key] = GetExecutorOutputType(executor.Value.ExecutorType); } - // Build the graph from edges - foreach (KeyValuePair> edgeGroup in edges) + // Build the graph from edges and extract edge conditions + Dictionary<(string SourceId, string TargetId), Func?> edgeConditions = []; + foreach (KeyValuePair> edgeGroup in edges) { string sourceId = edgeGroup.Key; List sourceSuccessors = successors[sourceId]; - foreach (EdgeInfo edge in edgeGroup.Value) + foreach (Edge edge in edgeGroup.Value) { - foreach (string sinkId in edge.Connection.SinkIds) + foreach (string sinkId in edge.Data.Connection.SinkIds) { if (executorIndex.ContainsKey(sinkId)) { @@ -106,6 +105,13 @@ public static class WorkflowHelper predecessors[sinkId].Add(sourceId); } } + + // Extract condition from DirectEdgeData if present + DirectEdgeData? directEdge = edge.DirectEdgeData; + if (directEdge is not null) + { + edgeConditions[(directEdge.SourceId, directEdge.SinkId)] = directEdge.Condition; + } } } diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/Microsoft.Agents.AI.Workflows.csproj b/dotnet/src/Microsoft.Agents.AI.Workflows/Microsoft.Agents.AI.Workflows.csproj index d01e3de970..1f92da87be 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows/Microsoft.Agents.AI.Workflows.csproj +++ b/dotnet/src/Microsoft.Agents.AI.Workflows/Microsoft.Agents.AI.Workflows.csproj @@ -25,6 +25,7 @@ + diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/Workflow.cs b/dotnet/src/Microsoft.Agents.AI.Workflows/Workflow.cs index c1b7cc1817..0bc1b41243 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows/Workflow.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows/Workflow.cs @@ -36,40 +36,6 @@ public class Workflow ); } - /// - /// Gets a mapping of edge identifiers to their associated condition delegates. - /// - /// 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. - public Dictionary<(string SourceId, string TargetId), Func?> ReflectEdgeConditions() - { - int capacity = 0; - foreach (HashSet edgeSet in this.Edges.Values) - { - capacity += edgeSet.Count; - } - - Dictionary<(string SourceId, string TargetId), Func?> conditions = new(capacity); - - foreach (HashSet edgeSet in this.Edges.Values) - { - foreach (Edge edge in edgeSet) - { - DirectEdgeData? directEdge = edge.DirectEdgeData; - if (directEdge is not null) - { - conditions[(directEdge.SourceId, directEdge.SinkId)] = directEdge.Condition; - } - } - } - - return conditions; - } - internal Dictionary Ports { get; init; } = []; ///