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
+97
View File
@@ -0,0 +1,97 @@
using MAF1.Agents;
namespace MAF1.Route;
/// <summary>控制台里用户原话。路径还是描述,交给专家自己判断,不在 C# 里写死。</summary>
public sealed class RouteUserInput
{
public string Raw { get; init; } = "";
public string? ResolvedFilePath { get; init; }
public bool HasRaw => !string.IsNullOrWhiteSpace(Raw);
public string Describe()
{
if (!string.IsNullOrWhiteSpace(ResolvedFilePath))
{
return $"已解析到文件 {ResolvedFilePath}";
}
string preview = Raw.Replace("\r\n", " ").Replace('\n', ' ').Trim();
if (preview.Length > 80)
{
preview = preview[..80] + "…";
}
return $"用户原话「{preview}」";
}
public string ToTask()
=> $"""
请根据用户下面这句话完成任务:提取有效城市,并在图允许时查询天气。
若这句话是本地文件路径,就读文件;若是描述、问句或城市名单,就直接从这句话提取,不要读文件。
用户输入:
{Raw}
""";
public static RouteUserInput ReadFromConsole(RouteGraph graph)
{
string? fallback = graph.Nodes
.Select(n => n.Type == SystemNodeTypes.FileCity && n.Config.TryGetValue("filePath", out string? path) ? path : null)
.FirstOrDefault(p => !string.IsNullOrWhiteSpace(p));
Console.WriteLine("请输入:本地文件路径,或一段描述/城市名单(例如:帮我查成都和杭州的天气)。");
if (!string.IsNullOrWhiteSpace(fallback))
{
Console.WriteLine($"直接回车则使用图里的默认文件:{fallback}");
}
Console.Write("> ");
string? line = Console.ReadLine();
string trimmed = line?.Trim() ?? "";
if (trimmed.Length == 0)
{
trimmed = fallback ?? "";
}
return new RouteUserInput
{
Raw = trimmed,
ResolvedFilePath = ResolveExisting(trimmed),
};
}
public static string? ResolveExisting(string path)
{
if (string.IsNullOrWhiteSpace(path))
{
return null;
}
try
{
if (path.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
{
return null;
}
}
catch (ArgumentException)
{
return null;
}
if (File.Exists(path))
{
return Path.GetFullPath(path);
}
string fromBase = Path.Combine(AppContext.BaseDirectory, path);
if (File.Exists(fromBase))
{
return Path.GetFullPath(fromBase);
}
return null;
}
}