Files
MAF1/MAF1.Web/Web/AgentRuntime.cs
T
admin777 950d09ddb0 docs: 为 CLI、网页编排器和插件协议补充学习向注释
在核心类型、图执行器、stdio 插件和前端入口写清职责与对照路径,不改运行行为。
2026-08-28 11:51:48 +08:00

50 lines
2.1 KiB
C#

using MAF1.Agents.FileCity;
using MAF1.Agents.Weather;
using MAF1.Plugins;
using MAF1.Tools;
using MAF1.Utils;
using Microsoft.Agents.AI;
using Microsoft.Extensions.Configuration;
namespace MAF1.Web;
/// <summary>
/// 网页进程的组合根:把 LLM、两个系统 Agent、插件扫描/启动子进程、图执行器绑在一起。
/// ASP.NET 把它注册成 Singleton,一次请求里不要 new 第二份。
/// </summary>
public sealed class AgentRuntime
{
public AgentRuntime(IConfiguration config)
{
AgentFactory factory = new(AgentFactory.Load(config));
WeatherOptions weatherOptions = config.GetSection("Weather").Get<WeatherOptions>() ?? 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; }
}