feat: 新增方案 C 的 Handoff 路由宿主,并让抽城市支持自然语言。
把图 JSON 编译成 CreateHandoffBuilderWith + WithHandoff;Agent 固定 Id 以免交接工具名错位;DeepSeek 关闭 thinking,避免多轮丢掉 reasoning_content 导致 400。
This commit is contained in:
@@ -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.txt、C:\\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)]);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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)]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user