34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using MAF1.Agents.FileCity;
|
|
using Microsoft.Agents.AI.Workflows;
|
|
using Microsoft.Extensions.AI;
|
|
|
|
namespace MAF1.Workflows;
|
|
|
|
/// <summary>
|
|
/// 边条件模式:这里只解析,不做 if。走哪条边由 AddEdge 的 condition 决定。
|
|
/// </summary>
|
|
internal sealed class CityParseExecutor() : ChatProtocolExecutor(
|
|
"CityParse",
|
|
new ChatProtocolExecutorOptions { AutoSendTurnToken = false })
|
|
{
|
|
protected override ProtocolBuilder ConfigureProtocol(ProtocolBuilder builder)
|
|
{
|
|
return base.ConfigureProtocol(builder).SendsMessage<CityExtraction>();
|
|
}
|
|
|
|
protected override async ValueTask TakeTurnAsync(
|
|
List<ChatMessage> messages,
|
|
IWorkflowContext context,
|
|
bool? emitEvents,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
string text = string.Join(
|
|
Environment.NewLine,
|
|
messages
|
|
.Where(message => !string.IsNullOrWhiteSpace(message.Text))
|
|
.Select(message => message.Text));
|
|
|
|
await context.SendMessageAsync(FileCityAgent.Parse(text), cancellationToken: cancellationToken);
|
|
}
|
|
}
|