From 24d1effb52e618773d820ea9e3e7c6dfec2dcf72 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 19:10:13 +0000 Subject: [PATCH] Clarify edge helper target validation Agent-Logs-Url: https://github.com/microsoft/agent-framework/sessions/af831ee2-0a99-4427-9ffd-a3b5022c1b3b Co-authored-by: lokitoth <6936551+lokitoth@users.noreply.github.com> --- .../WorkflowBuilderExtensions.cs | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowBuilderExtensions.cs b/dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowBuilderExtensions.cs index b09dec91f4..03131daf8c 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowBuilderExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowBuilderExtensions.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.Linq; using Microsoft.Shared.Diagnostics; namespace Microsoft.Agents.AI.Workflows; @@ -58,10 +57,9 @@ public static class WorkflowBuilderExtensions { Throw.IfNull(builder); Throw.IfNull(source); - Throw.IfNull(targets); Func predicate = WorkflowBuilder.CreateConditionFunc(IsAllowedTypeAndMatchingCondition)!; - List targetList = targets.Select(target => Throw.IfNull(target, nameof(targets))).ToList(); + List targetList = ValidateTargets(targets); if (targetList.Count == 1) { @@ -102,10 +100,9 @@ public static class WorkflowBuilderExtensions { Throw.IfNull(builder); Throw.IfNull(source); - Throw.IfNull(targets); Func predicate = WorkflowBuilder.CreateConditionFunc((Func)IsAllowedType)!; - List targetList = targets.Select(target => Throw.IfNull(target, nameof(targets))).ToList(); + List targetList = ValidateTargets(targets); if (targetList.Count == 1) { @@ -119,6 +116,25 @@ public static class WorkflowBuilderExtensions static bool IsAllowedType(object? message) => message is null; } + private static List ValidateTargets(IEnumerable targets) + { + Throw.IfNull(targets); + + List targetList = []; + foreach (ExecutorBinding? target in targets) + { + if (target is null) + { + throw new ArgumentNullException(nameof(targets), "Targets collection cannot contain null elements."); + } + + targetList.Add(target); + } + + Throw.IfNullOrEmpty(targetList, nameof(targets)); + return targetList; + } + /// /// Adds a sequential chain of executors to the workflow, connecting each executor in order so that each is /// executed after the previous one.