把图 JSON 编译成 CreateHandoffBuilderWith + WithHandoff;Agent 固定 Id 以免交接工具名错位;DeepSeek 关闭 thinking,避免多轮丢掉 reasoning_content 导致 400。
85 lines
3.0 KiB
C#
85 lines
3.0 KiB
C#
using MAF1.Tools;
|
||
using MAF1.Utils;
|
||
using Microsoft.Extensions.Configuration;
|
||
|
||
namespace MAF1.Route;
|
||
|
||
/// <summary>
|
||
/// 命令行宿主:读配置和图 JSON,用 MAF WithHandoff 按方案 C 跑路由。
|
||
/// </summary>
|
||
internal static class CliHost
|
||
{
|
||
public static async Task RunAsync(string[] args)
|
||
{
|
||
if (args.Length > 0 && args[0] is "-h" or "--help")
|
||
{
|
||
PrintUsage();
|
||
return;
|
||
}
|
||
|
||
IConfiguration config = new ConfigurationBuilder()
|
||
.SetBasePath(AppContext.BaseDirectory)
|
||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false)
|
||
.AddEnvironmentVariables()
|
||
.Build();
|
||
|
||
string graphPath = args.Length > 0 ? args[0] : Path.Combine("Graphs", "city-weather.json");
|
||
string? resolvedGraph = ResolveExisting(graphPath);
|
||
if (resolvedGraph is null)
|
||
{
|
||
Console.WriteLine($"找不到路由图:{graphPath}");
|
||
PrintUsage();
|
||
return;
|
||
}
|
||
|
||
RouteGraph graph = RouteGraph.LoadFile(resolvedGraph);
|
||
Console.WriteLine($"路由图: {resolvedGraph}");
|
||
Console.WriteLine();
|
||
|
||
RouteUserInput input = RouteUserInput.ReadFromConsole(graph);
|
||
if (!input.HasRaw)
|
||
{
|
||
Console.WriteLine("没有输入,已取消。");
|
||
return;
|
||
}
|
||
|
||
Console.WriteLine($"本次输入: {input.Describe()}");
|
||
Console.WriteLine();
|
||
|
||
AgentFactory factory = new(AgentFactory.Load(config));
|
||
WeatherOptions weatherOptions = config.GetSection("Weather").Get<WeatherOptions>() ?? new WeatherOptions();
|
||
using HttpClient http = WeatherTools.CreateHttpClient();
|
||
WeatherTools weatherTools = new(weatherOptions, http);
|
||
Console.WriteLine($"天气数据源: {weatherOptions.Provider}");
|
||
Console.WriteLine();
|
||
|
||
await RouteOrchestrator.RunAsync(factory, weatherTools, graph, input);
|
||
}
|
||
|
||
private static string? ResolveExisting(string path)
|
||
=> RouteUserInput.ResolveExisting(path);
|
||
|
||
private static void PrintUsage()
|
||
{
|
||
Console.WriteLine(
|
||
"""
|
||
命令行路由(方案 C + MAF WithHandoff):
|
||
dotnet run --project MAF1.Route
|
||
dotnet run --project MAF1.Route -- Graphs/city-weather.json
|
||
dotnet run --project MAF1.Route -- Graphs/nodes-only.json
|
||
|
||
启动后在控制台输入即可,专家自己判断:
|
||
Data/cities.txt
|
||
帮我查成都和杭州的天气
|
||
明天去上海出差
|
||
直接回车则用图节点 config 里的默认 filePath。
|
||
|
||
city-weather.json:专家之间仍是抽城市→天气;主管若认定用户已给出城市名,可直接交给天气。
|
||
nodes-only.json 无边:主管可把对话直接交给白名单里任一专家。
|
||
|
||
对照工作流(不是 Handoff):
|
||
dotnet run --project MAF1 -- node Data/cities.txt
|
||
""");
|
||
}
|
||
}
|