using Microsoft.Agents.AI; using Microsoft.Agents.AI.Workflows; using MAF1.Agents.FileCity; namespace MAF1.Workflows; public static class CityWeatherWorkflow { public static Workflow BuildNodeCondition(AIAgent fileCityAgent, AIAgent weatherAgent) { (ExecutorBinding fileCity, ExecutorBinding weather) = BindAgents(fileCityAgent, weatherAgent); CityGateExecutor gate = new(); return new WorkflowBuilder(fileCity) .AddEdge(fileCity, gate) .AddEdge(gate, weather) .WithOutputFrom(gate, weather) .WithName("CityWeather-Node") .Build(); } public static Workflow BuildEdgeCondition(AIAgent fileCityAgent, AIAgent weatherAgent) { (ExecutorBinding fileCity, ExecutorBinding weather) = BindAgents(fileCityAgent, weatherAgent); CityParseExecutor parse = new(); ToWeatherPromptExecutor toWeather = new(); SkipWeatherExecutor skip = new(); return new WorkflowBuilder(fileCity) .AddEdge(fileCity, parse) .AddEdge(parse, toWeather, extraction => extraction is { HasValidCities: true }) .AddEdge(parse, skip, extraction => extraction is not { HasValidCities: true }) .AddEdge(toWeather, weather) .WithOutputFrom(skip, weather) .WithName("CityWeather-Edge") .Build(); } private static (ExecutorBinding FileCity, ExecutorBinding Weather) BindAgents(AIAgent fileCityAgent, AIAgent weatherAgent) { AIAgentHostOptions agentOptions = new() { ForwardIncomingMessages = false, ReassignOtherAgentsAsUsers = true, EmitAgentUpdateEvents = true, EmitAgentResponseEvents = true, }; return (fileCityAgent.BindAsExecutor(agentOptions), weatherAgent.BindAsExecutor(agentOptions)); } }