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
+25 -8
View File
@@ -13,22 +13,39 @@ namespace MAF1.Agents.FileCity;
/// </summary>
public static class FileCityAgent
{
public const string DefaultDescription = "从文件或用户描述中提取有效城市名。";
/// <summary>创建带 ReadTextFile 工具的聊天 Agent。模型必须先读文件,不能凭文件名猜内容。</summary>
public static AIAgent Create(AgentFactory factory)
public static AIAgent Create(
AgentFactory factory,
string name = "FileCityAgent",
string? description = null,
string? extraInstructions = null)
{
return factory.CreateAgent(
name: "FileCityAgent",
instructions:
string instructions =
"""
ReadTextFile
1) Data/cities.txtC:\\a.txt ReadTextFile
2) ReadTextFile
Amsterdam
JSON Markdown
{"hasValidCities": true, "cities": ["成都"], "reason": "说明"}
{"hasValidCities": false, "cities": [], "reason": "原因"}
cities
""",
cities
""";
if (!string.IsNullOrWhiteSpace(extraInstructions))
{
instructions = instructions + "\n" + extraInstructions;
}
return factory.CreateAgent(
name: name,
instructions: instructions,
description: string.IsNullOrWhiteSpace(description) ? DefaultDescription : description,
tools: [AIFunctionFactory.Create(FileTools.ReadTextFile)]);
}
+13
View File
@@ -0,0 +1,13 @@
namespace MAF1.Agents;
/// <summary>
/// 系统节点类型 id,和网页画布、路由图 JSON 共用,避免各写一份字符串。
/// </summary>
public static class SystemNodeTypes
{
public const string FileCity = "fileCity-system";
public const string Weather = "weather-system";
public static bool IsKnown(string? type)
=> type is FileCity or Weather;
}
+19 -5
View File
@@ -11,16 +11,30 @@ namespace MAF1.Agents.Weather;
/// </summary>
public static class WeatherAgent
{
public const string DefaultDescription = "按城市列表查询天气并汇总。";
/// <summary>创建带 GetWeather 工具的 Agent。instructions 要求每个城市都调工具,禁止编造气温。</summary>
public static AIAgent Create(AgentFactory factory, WeatherTools weatherTools)
public static AIAgent Create(
AgentFactory factory,
WeatherTools weatherTools,
string name = "WeatherAgent",
string? description = null,
string? extraInstructions = null)
{
return factory.CreateAgent(
name: "WeatherAgent",
instructions:
string instructions =
"""
GetWeather
""",
""";
if (!string.IsNullOrWhiteSpace(extraInstructions))
{
instructions = instructions + "\n" + extraInstructions;
}
return factory.CreateAgent(
name: name,
instructions: instructions,
description: string.IsNullOrWhiteSpace(description) ? DefaultDescription : description,
tools: [AIFunctionFactory.Create(weatherTools.GetWeather)]);
}