mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
647db9635a
* Renaming Microsoft.Agent.Workflows to Microsoft.Agents.AI.Workflows * Removing local settings. * Removing remining old files from merge.
50 lines
1.8 KiB
C#
50 lines
1.8 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Agents.AI.Workflows.Declarative.Extensions;
|
|
using Microsoft.Agents.AI.Workflows.Declarative.Interpreter;
|
|
using Microsoft.Agents.AI.Workflows.Declarative.PowerFx;
|
|
using Microsoft.Bot.ObjectModel;
|
|
using Microsoft.Bot.ObjectModel.Abstractions;
|
|
using Microsoft.Extensions.AI;
|
|
using Microsoft.Shared.Diagnostics;
|
|
|
|
namespace Microsoft.Agents.AI.Workflows.Declarative.ObjectModel;
|
|
|
|
internal sealed class CopyConversationMessagesExecutor(CopyConversationMessages model, WorkflowAgentProvider agentProvider, WorkflowFormulaState state) :
|
|
DeclarativeActionExecutor<CopyConversationMessages>(model, state)
|
|
{
|
|
protected override async ValueTask<object?> ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)
|
|
{
|
|
Throw.IfNull(this.Model.ConversationId, $"{nameof(this.Model)}.{nameof(this.Model.ConversationId)}");
|
|
string conversationId = this.Evaluator.GetValue(this.Model.ConversationId).Value;
|
|
|
|
IEnumerable<ChatMessage>? inputMessages = this.GetInputMessages();
|
|
|
|
if (inputMessages is not null)
|
|
{
|
|
foreach (ChatMessage message in inputMessages)
|
|
{
|
|
await agentProvider.CreateMessageAsync(conversationId, message, cancellationToken).ConfigureAwait(false);
|
|
}
|
|
}
|
|
|
|
return default;
|
|
}
|
|
|
|
private IEnumerable<ChatMessage>? GetInputMessages()
|
|
{
|
|
DataValue? messages = null;
|
|
|
|
if (this.Model.Messages is not null)
|
|
{
|
|
EvaluationResult<DataValue> expressionResult = this.Evaluator.GetValue(this.Model.Messages);
|
|
messages = expressionResult.Value;
|
|
}
|
|
|
|
return messages?.ToChatMessages();
|
|
}
|
|
}
|