using MAF1.Agents.FileCity; using MAF1.Agents.Weather; using MAF1.Plugins; using MAF1.Tools; using MAF1.Utils; using MAF1.Web.Web; using Microsoft.Agents.AI; using Microsoft.Extensions.Configuration; namespace MAF1.Web; /// /// 网页进程的组合根:把 LLM、两个系统 Agent、插件扫描/启动子进程、图执行器绑在一起。 /// ASP.NET 把它注册成 Singleton,一次请求里不要 new 第二份。 /// public sealed class AgentRuntime { public AgentRuntime(IConfiguration config) { AgentFactory factory = new(AgentFactory.Load(config)); WeatherOptions weatherOptions = config.GetSection("Weather").Get() ?? new WeatherOptions(); Http = WeatherTools.CreateHttpClient(); WeatherTools weatherTools = new(weatherOptions, Http); FileCity = FileCityAgent.Create(factory); Weather = WeatherAgent.Create(factory, weatherTools); PluginOptions pluginOptions = PluginOptions.Load(config); Credentials = new CredentialStore(config); Scanner = new PluginScanner(pluginOptions); Catalog = new NodeCatalogService(Scanner); PluginRunner = new PluginProcessRunner(pluginOptions, Credentials); RunStore = new WorkflowRunStore(); DecisionTimeoutSeconds = Math.Clamp(config.GetValue("Workflow:DecisionTimeoutSeconds", 30), 1, 600); Runner = new ConfigurableWorkflowRunner(FileCity, Weather, Catalog, PluginRunner, RunStore, DecisionTimeoutSeconds); WeatherProvider = weatherOptions.Provider; PluginsRoot = pluginOptions.ResolveRoot(); } public AIAgent FileCity { get; } public AIAgent Weather { get; } public ConfigurableWorkflowRunner Runner { get; } public WorkflowRunStore RunStore { get; } public int DecisionTimeoutSeconds { get; } public NodeCatalogService Catalog { get; } public PluginScanner Scanner { get; } public PluginProcessRunner PluginRunner { get; } public CredentialStore Credentials { get; } public string WeatherProvider { get; } public string PluginsRoot { get; } public HttpClient Http { get; } }