mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
6e8c7c42c8
* 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
39 lines
1.4 KiB
C#
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));
|
|
}
|
|
}
|