2026-08-26 18:06:02 +08:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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);
|
2026-08-28 10:43:57 +08:00
|
|
|
RunStore = new WorkflowRunStore();
|
|
|
|
|
DecisionTimeoutSeconds = Math.Clamp(config.GetValue("Workflow:DecisionTimeoutSeconds", 30), 1, 600);
|
|
|
|
|
Runner = new ConfigurableWorkflowRunner(FileCity, Weather, Catalog, PluginRunner, RunStore, DecisionTimeoutSeconds);
|
2026-08-26 18:06:02 +08:00
|
|
|
WeatherProvider = weatherOptions.Provider;
|
|
|
|
|
PluginsRoot = pluginOptions.ResolveRoot();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AIAgent FileCity { get; }
|
|
|
|
|
public AIAgent Weather { get; }
|
|
|
|
|
public ConfigurableWorkflowRunner Runner { get; }
|
2026-08-28 10:43:57 +08:00
|
|
|
public WorkflowRunStore RunStore { get; }
|
|
|
|
|
public int DecisionTimeoutSeconds { get; }
|
2026-08-26 18:06:02 +08:00
|
|
|
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; }
|
|
|
|
|
}
|