mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
6a3d22598f
* feat: Implement Polymorphic Routing * feat: Add support for Send/Yield annotations with basic Executor * Adds annotations to Declarative workflow executors * fix: Address PR Comments * Implicit filter in collection loops * Remove debug / usused / superfluous code * Fix ProtocolBuilder implicit output registrations * Fix logic error in ExecuteRouteGeneratorTests.ClassWithManualConfigureProtocol_DoesNotGenerate * fix: Solidify type checks and send/yield type registrations * fix: Suppress generation of TurnTokens out of AggregateTurnMessagesExecutor * Fixes an issue where ConcurrentEndExecutor is not expecting TurnTokens. * fix: Add ProtocolBuilder support for chained-delegation * Updates Declarative pacakge to rely on chained-delegation Send/Yield registration * Renames DeclarativeActionExectuor's new ExecuteAsync to ExecuteActionAsync to avoid colliding with Executor.ExecutoeAsync * fix: Address PR Comments * Fixes type mapping in FanInEdgeRunner * Fixes and expalins send/yield type registration in FunctionExecutor * fixup: build-break * fix: Add missing SendsMesage declaration to InvokeAzureAgentExecutor
42 lines
1.5 KiB
C#
42 lines
1.5 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 ProtocolBuilder ConfigureProtocol(ProtocolBuilder protocolBuilder)
|
|
{
|
|
return protocolBuilder.ConfigureRoutes(ConfigureRoutes);
|
|
|
|
void 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;
|
|
}
|
|
}
|
|
}
|
|
|
|
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));
|
|
}
|
|
}
|