using Microsoft.Agents.AI; using Microsoft.Agents.AI.Workflows; namespace MAF1.Orchestration; public static class WorkflowOrchestration { public static async Task RunAsync(Workflow workflow, string modeLabel, string filePath) { Console.WriteLine(modeLabel); Console.WriteLine(); string prompt = $"请读取这个文件并提取有效城市名:{filePath}"; await using StreamingRun run = await InProcessExecution.RunStreamingAsync(workflow, prompt); await run.TrySendMessageAsync(new TurnToken(emitEvents: true)); string? lastExecutorId = null; await foreach (WorkflowEvent evt in run.WatchStreamAsync()) { switch (evt) { case AgentResponseUpdateEvent update: if (update.ExecutorId != lastExecutorId) { Console.WriteLine(); Console.Write($"{update.ExecutorId}: "); lastExecutorId = update.ExecutorId; } if (!string.IsNullOrEmpty(update.Update.Text)) { Console.Write(update.Update.Text); } break; case AgentResponseEvent: break; case WorkflowOutputEvent output when output.As() is string text: Console.WriteLine(); Console.WriteLine(); Console.WriteLine($"[工作流 / {output.ExecutorId}] {text}"); break; } } Console.WriteLine(); } }