29 lines
1.0 KiB
C#
29 lines
1.0 KiB
C#
using MAF1.Agents.FileCity;
|
|||
|
|
using Microsoft.Agents.AI.Workflows;
|
||
|
|
using Microsoft.Extensions.AI;
|
||
|
|
|
||
|
|
namespace MAF1.Workflows;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 只有「有城市」那条边会进到这里,所以这里不再判断。
|
||
|
|
/// </summary>
|
||
|
|
internal sealed class ToWeatherPromptExecutor() : Executor<CityExtraction>("ToWeatherPrompt")
|
||
|
|
{
|
||
|
|
protected override ProtocolBuilder ConfigureProtocol(ProtocolBuilder builder)
|
||
|
|
{
|
||
|
|
return base.ConfigureProtocol(builder)
|
||
|
|
.SendsMessage<ChatMessage>()
|
||
|
|
.SendsMessage<TurnToken>();
|
||
|
|
}
|
||
|
|
|
||
|
|
public override async ValueTask HandleAsync(
|
||
|
|
CityExtraction extraction,
|
||
|
|
IWorkflowContext context,
|
||
|
|
CancellationToken cancellationToken = default)
|
||
|
|
{
|
||
|
|
string prompt = $"请查询这些城市的天气:{string.Join("、", extraction.Cities)}";
|
||
|
|
await context.SendMessageAsync(new ChatMessage(ChatRole.User, prompt), cancellationToken: cancellationToken);
|
||
|
|
await context.SendMessageAsync(new TurnToken(emitEvents: true), cancellationToken: cancellationToken);
|
||
|
|
}
|
||
|
|
}
|