// Copyright (c) Microsoft. All rights reserved. using System.Threading.Tasks; using Microsoft.Extensions.AI; using Microsoft.Extensions.AI.Agents; using Microsoft.Extensions.Logging; using Microsoft.SemanticKernel.Agents.Runtime; using Microsoft.SemanticKernel.Agents.Runtime.Core; namespace Microsoft.Agents.Orchestration.Concurrent; /// /// An used with the . /// internal sealed class ConcurrentActor : AgentActor, IHandle { private readonly AgentType _handoffActor; /// /// Initializes a new instance of the class. /// /// The unique identifier of the agent. /// The runtime associated with the agent. /// The orchestration context. /// An . /// Identifies the actor collecting results. /// The logger to use for the actor public ConcurrentActor(AgentId id, IAgentRuntime runtime, OrchestrationContext context, Agent agent, AgentType resultActor, ILogger? logger = null) : base(id, runtime, context, agent, logger) { this._handoffActor = resultActor; } /// public async ValueTask HandleAsync(ConcurrentMessages.Request item, MessageContext messageContext) { this.Logger.LogConcurrentAgentInvoke(this.Id); ChatMessage response = await this.InvokeAsync(item.Messages, messageContext.CancellationToken).ConfigureAwait(false); this.Logger.LogConcurrentAgentResult(this.Id, response.Text); await this.PublishMessageAsync(response.AsResultMessage(), this._handoffActor, messageContext.CancellationToken).ConfigureAwait(false); } }