工具执行错误消息合并为单条,集中模型注意力
This commit is contained in:
parent
d2b18958c1
commit
68619f01f8
@ -4,11 +4,11 @@
|
|||||||
|
|
||||||
## 核心程序
|
## 核心程序
|
||||||
|
|
||||||
- [ ] 提示词调用完整实现:以面向对象形式取代字典形式,加入参数和描述
|
- [x] 提示词调用完整实现:以面向对象形式取代字典形式,加入参数和描述
|
||||||
- [ ] 接入本地文件系统等基础性MCP服务
|
- [ ] 接入本地文件系统等基础性MCP服务
|
||||||
- [ ] Python代码执行的实现
|
- [ ] Python代码执行的实现
|
||||||
- [ ] 适配qwen3、deepseek等推理模型并迁移
|
- [ ] 适配qwen3、deepseek等推理模型并迁移
|
||||||
- [ ] 工具执行错误消息合并为一条
|
- [x] 工具执行错误消息合并为一条
|
||||||
|
|
||||||
## 提示词工程
|
## 提示词工程
|
||||||
|
|
||||||
|
|||||||
@ -411,7 +411,7 @@ public class Gateway
|
|||||||
messages.Add(new Message
|
messages.Add(new Message
|
||||||
{
|
{
|
||||||
Role = "user",
|
Role = "user",
|
||||||
Content = toolResponse.IsError ? SystemPrompt.ErrorPromptTemplate : SystemPrompt.ContinuePrompt(JsonConvert.SerializeObject(toolResponse))
|
Content = toolResponse.IsError ? SystemPrompt.ErrorPrompt(JsonConvert.SerializeObject(toolResponse)) : SystemPrompt.ContinuePrompt(JsonConvert.SerializeObject(toolResponse))
|
||||||
});
|
});
|
||||||
callback?.Invoke(toolMessageItem);
|
callback?.Invoke(toolMessageItem);
|
||||||
}else if (mcpServer is StdioMcpServer)
|
}else if (mcpServer is StdioMcpServer)
|
||||||
@ -431,7 +431,7 @@ public class Gateway
|
|||||||
messages.Add(new Message
|
messages.Add(new Message
|
||||||
{
|
{
|
||||||
Role = "user",
|
Role = "user",
|
||||||
Content = toolResponse.IsError ? SystemPrompt.ErrorPromptTemplate : SystemPrompt.ContinuePrompt(JsonConvert.SerializeObject(toolResponse))
|
Content = toolResponse.IsError ? SystemPrompt.ErrorPrompt(JsonConvert.SerializeObject(toolResponse)) : SystemPrompt.ContinuePrompt(JsonConvert.SerializeObject(toolResponse))
|
||||||
});
|
});
|
||||||
callback?.Invoke(toolMessageItem);
|
callback?.Invoke(toolMessageItem);
|
||||||
}else if (mcpServer is InnerMcpServer)
|
}else if (mcpServer is InnerMcpServer)
|
||||||
@ -469,12 +469,7 @@ public class Gateway
|
|||||||
messages.Add(new Message
|
messages.Add(new Message
|
||||||
{
|
{
|
||||||
Role = "user",
|
Role = "user",
|
||||||
Content = SystemPrompt.ErrorPromptTemplate
|
Content = SystemPrompt.ErrorPrompt(JsonConvert.SerializeObject(toolMessageItem))
|
||||||
});
|
|
||||||
messages.Add(new Message
|
|
||||||
{
|
|
||||||
Role = "user",
|
|
||||||
Content = JsonConvert.SerializeObject(toolMessageItem)
|
|
||||||
});
|
});
|
||||||
callback?.Invoke(toolMessageItem);
|
callback?.Invoke(toolMessageItem);
|
||||||
}else if (innerResult is JsonRpcSuccessEntity)
|
}else if (innerResult is JsonRpcSuccessEntity)
|
||||||
|
|||||||
@ -22,7 +22,7 @@ public class SystemPrompt
|
|||||||
public static string ContinuePromptTemplate = "这是上述工具调用的结果。{{toolResult}}\n请根据以下执行结果,清晰解释执行结果并执行下一步操作。" +
|
public static string ContinuePromptTemplate = "这是上述工具调用的结果。{{toolResult}}\n请根据以下执行结果,清晰解释执行结果并执行下一步操作。" +
|
||||||
"执行下一步工具的要求:1. 解析工具输出结果2. 调用下一个工具时确保参数继承前序输出。请据此继续执行";
|
"执行下一步工具的要求:1. 解析工具输出结果2. 调用下一个工具时确保参数继承前序输出。请据此继续执行";
|
||||||
|
|
||||||
public static string ErrorPromptTemplate = "执行上一个工具的时候出现以下错误,需按以下流程处理:1. 错误解析:分析错误类型及具体原因(见下方错误信息),根据错误信息选择修复方案,```" +
|
public static string ErrorPromptTemplate = "执行上一个工具的时候出现以下错误\n{{toolResult}}\n,需按以下流程处理:1. 错误解析:分析错误类型及具体原因(见下方错误信息),根据错误信息选择修复方案,```" +
|
||||||
"2. 修复方案:(1)根据错误类型生成对应的工具重试策略(2)参数调整:明确需要修改的参数及修改方式。3. 工具重试:使用调整后的参数重新调用工具。错误信息如下,请根据报错信息重试,4.如果没有具体的错误描述信息请检查输出文件是否已经存在,若已经存在默认执行成功"+
|
"2. 修复方案:(1)根据错误类型生成对应的工具重试策略(2)参数调整:明确需要修改的参数及修改方式。3. 工具重试:使用调整后的参数重新调用工具。错误信息如下,请根据报错信息重试,4.如果没有具体的错误描述信息请检查输出文件是否已经存在,若已经存在默认执行成功"+
|
||||||
"5.查询可能相关的知识库和帮助文档,纠正调用参数中存在的错误";
|
"5.查询可能相关的知识库和帮助文档,纠正调用参数中存在的错误";
|
||||||
|
|
||||||
@ -40,4 +40,11 @@ public class SystemPrompt
|
|||||||
continuePrompt = continuePrompt.Replace("{{toolResult}}", toolResult);
|
continuePrompt = continuePrompt.Replace("{{toolResult}}", toolResult);
|
||||||
return continuePrompt;
|
return continuePrompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string ErrorPrompt(string toolResult)
|
||||||
|
{
|
||||||
|
string errPrompt = ErrorPromptTemplate;
|
||||||
|
errPrompt = errPrompt.Replace("{{toolResult}}", toolResult);
|
||||||
|
return errPrompt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user