diff --git a/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableWorkflowOptions.cs b/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableWorkflowOptions.cs
index 255e36a215..25603c4178 100644
--- a/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableWorkflowOptions.cs
+++ b/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableWorkflowOptions.cs
@@ -63,6 +63,20 @@ public sealed class DurableWorkflowOptions
}
}
+ ///
+ /// Adds a collection of workflows to the current instance.
+ ///
+ /// The collection of objects to add. Cannot be .
+ public void AddWorkflow(IEnumerable workflows)
+ {
+ ArgumentNullException.ThrowIfNull(workflows);
+
+ foreach (var workflow in workflows)
+ {
+ this.AddWorkflow(workflow);
+ }
+ }
+
private static void RegisterExecutors(Workflow workflow, ExecutorRegistry registry)
{
foreach (KeyValuePair executor in workflow.ReflectExecutors())
diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/DurableOptionsExtensions.cs b/dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/DurableOptionsExtensions.cs
index 10dab0f73d..8e5c917b4f 100644
--- a/dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/DurableOptionsExtensions.cs
+++ b/dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/DurableOptionsExtensions.cs
@@ -44,7 +44,7 @@ public static class DurableOptionsExtensions
if (options.Workflows.Workflows.Count > 0)
{
builder.RegisterWorkflowServices();
- ConfigureWorkflowOrchestration(builder);
+ ConfigureWorkflowOrchestrations(builder, options.Workflows);
}
return builder;
@@ -79,23 +79,27 @@ public static class DurableOptionsExtensions
});
}
- private static void ConfigureWorkflowOrchestration(FunctionsApplicationBuilder builder)
+ private static void ConfigureWorkflowOrchestrations(FunctionsApplicationBuilder builder, DurableWorkflowOptions workflows)
{
- // Registering a single orchestration function to handle all workflow runs.
- // This is due to a gap in durable extension today and can be replace with dynamic orchestration registration in future, per workflow.
+ // Registering orchestration functions for each workflow.
builder.ConfigureDurableWorker().AddTasks(tasks =>
- tasks.AddOrchestratorFunc>(
- "WorkflowRunnerOrchestration",
- async (orchestrationContext, request) =>
- {
- FunctionContext functionContext = orchestrationContext.GetFunctionContext()
- ?? throw new InvalidOperationException("FunctionContext is not available in the orchestration context.");
+ {
+ foreach (string workflowName in workflows.Workflows.Select(kp => kp.Key))
+ {
+ tasks.AddOrchestratorFunc>(
+ $"dafx-{workflowName}",
+ async (orchestrationContext, request) =>
+ {
+ FunctionContext functionContext = orchestrationContext.GetFunctionContext()
+ ?? throw new InvalidOperationException("FunctionContext is not available in the orchestration context.");
- DurableWorkflowRunner runner = functionContext.InstanceServices.GetRequiredService();
- ILogger logger = orchestrationContext.CreateReplaySafeLogger("WorkflowRunnerOrchestration");
+ DurableWorkflowRunner runner = functionContext.InstanceServices.GetRequiredService();
+ ILogger logger = orchestrationContext.CreateReplaySafeLogger($"dafx-orchestration-{workflowName}");
- return await runner.RunWorkflowOrchestrationAsync(orchestrationContext, request, logger).ConfigureAwait(true);
- }));
+ return await runner.RunWorkflowOrchestrationAsync(orchestrationContext, request, logger).ConfigureAwait(true);
+ });
+ }
+ });
}
}