Files
agent-framework/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/DynamicPortsExecutor.cs
T
Jacob Alber 6e8c7c42c8 .NET: [BREAKING] feat: Improve Agent hosting inside Workflows (#3142)
* refactor: Rename AggregateTurnMessagesExecutor

* feat: Rework Agent Hosting for Configurability and HIL support

* Adds support for selecting whether updates and/or full responses are
  emitted to events
* Adds support for HIL/FunctionCalls (including interception)
* Implements internal support for ExternalRequests from any executor
  (not just RequestPort)

* test: Add tests for new AIAgentHostExecutor functionality

* feat: Unify non-Handoff Agent Hosting

* doc: More explicit documentation for `overwrite` in RouteBuilder
2026-01-23 19:45:29 +00:00

39 lines
1.4 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Microsoft.Agents.AI.Workflows.UnitTests;
internal sealed class DynamicPortsExecutor<TRequest, TResponse>(string id, params IEnumerable<string> ports) : Executor(id)
{
public Dictionary<string, PortBinding> PortBindings { get; } = new();
public ConcurrentDictionary<string, ConcurrentQueue<TResponse>> ReceivedResponses { get; } = new();
protected override RouteBuilder ConfigureRoutes(RouteBuilder routeBuilder)
{
foreach (string portId in ports)
{
routeBuilder = routeBuilder
.AddPortHandler<TRequest, TResponse>(portId,
(response, context, cancellationToken) =>
{
this.ReceivedResponses.GetOrAdd(portId, _ => new()).Enqueue(response);
return default;
}, out PortBinding? binding);
this.PortBindings[portId] = binding;
}
return routeBuilder;
}
public ValueTask PostRequestAsync(string portId, TRequest request, TestRunContext testContext, string? requestId = null)
{
PortBinding binding = this.PortBindings[portId];
return binding.Sink.PostAsync(ExternalRequest.Create(binding.Port, request, requestId));
}
}