feat: 新增方案 C 的 Handoff 路由宿主,并让抽城市支持自然语言。

把图 JSON 编译成 CreateHandoffBuilderWith + WithHandoff;Agent 固定 Id 以免交接工具名错位;DeepSeek 关闭 thinking,避免多轮丢掉 reasoning_content 导致 400。
This commit is contained in:
2026-09-01 17:56:41 +08:00
parent 2c5c6fd118
commit b0e89b6092
25 changed files with 960 additions and 27 deletions
+84
View File
@@ -0,0 +1,84 @@
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
""");
}
}