Spaces:
Paused
Paused
refactor: simplify tool system prompt for better compliance
Browse filesRewrite tool injection prompt to be more concise and authoritative,
framing it as an integrated runtime capability rather than verbose rules.
Strengthen tool_choice enforcement wording.
- internal/tools/prompt.go +7 -16
internal/tools/prompt.go
CHANGED
|
@@ -17,23 +17,14 @@ func BuildToolSystemPrompt(tools []model.Tool, toolChoice interface{}) string {
|
|
| 17 |
|
| 18 |
var sb strings.Builder
|
| 19 |
|
| 20 |
-
sb.WriteString("
|
| 21 |
-
sb.WriteString("
|
| 22 |
sb.WriteString("<tool_call>{\"name\": \"函数名\", \"arguments\": {\"参数名\": \"参数值\"}}</tool_call>\n\n")
|
| 23 |
-
sb.WriteString("
|
| 24 |
-
sb.WriteString("-
|
| 25 |
-
sb.WriteString("- 每个工具调用必须独立包裹在 <tool_call></tool_call> 标签中\n")
|
| 26 |
sb.WriteString("- arguments 必须是合法 JSON 对象\n")
|
| 27 |
-
sb.WriteString("-
|
| 28 |
-
|
| 29 |
-
sb.WriteString("## 示例\n\n")
|
| 30 |
-
sb.WriteString("用户: 帮我创建一个文件 test.txt 内容为 hello\n")
|
| 31 |
-
sb.WriteString("助手: 好的,我来为您创建文件。\n")
|
| 32 |
-
sb.WriteString("<tool_call>{\"name\": \"create_file\", \"arguments\": {\"filename\": \"test.txt\", \"content\": \"hello\"}}</tool_call>\n\n")
|
| 33 |
-
sb.WriteString("用户: 查询北京和上海的天气\n")
|
| 34 |
-
sb.WriteString("助手: 我来查询这两个城市的天气。\n")
|
| 35 |
-
sb.WriteString("<tool_call>{\"name\": \"get_weather\", \"arguments\": {\"location\": \"北京\"}}</tool_call>\n")
|
| 36 |
-
sb.WriteString("<tool_call>{\"name\": \"get_weather\", \"arguments\": {\"location\": \"上海\"}}</tool_call>\n\n")
|
| 37 |
|
| 38 |
sb.WriteString("## 可用工具\n\n")
|
| 39 |
|
|
@@ -66,7 +57,7 @@ func BuildToolSystemPrompt(tools []model.Tool, toolChoice interface{}) string {
|
|
| 66 |
// tool_choice = {"type": "function", "function": {"name": "xxx"}}
|
| 67 |
if fn, ok := tc["function"].(map[string]interface{}); ok {
|
| 68 |
if name, ok := fn["name"].(string); ok {
|
| 69 |
-
sb.WriteString(fmt.Sprintf("**你必须调用工具 \"%s\",
|
| 70 |
}
|
| 71 |
}
|
| 72 |
}
|
|
|
|
| 17 |
|
| 18 |
var sb strings.Builder
|
| 19 |
|
| 20 |
+
sb.WriteString("你的运行环境已接入工具执行系统。当你在回复中输出 <tool_call> 标签时,系统会自动拦截并执行对应的工具,然后将结果返回给你。这不是模拟,你确实拥有此能力。\n\n")
|
| 21 |
+
sb.WriteString("调用格式(严格遵守):\n")
|
| 22 |
sb.WriteString("<tool_call>{\"name\": \"函数名\", \"arguments\": {\"参数名\": \"参数值\"}}</tool_call>\n\n")
|
| 23 |
+
sb.WriteString("规则:\n")
|
| 24 |
+
sb.WriteString("- 每个调用独立包裹在 <tool_call></tool_call> 中\n")
|
|
|
|
| 25 |
sb.WriteString("- arguments 必须是合法 JSON 对象\n")
|
| 26 |
+
sb.WriteString("- 当用户请求可以通过工具完成时,必须直接输出 <tool_call> 标签,不要说「我无法调用」\n")
|
| 27 |
+
sb.WriteString("- 可以在 <tool_call> 之前输出简短说明文字\n\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
sb.WriteString("## 可用工具\n\n")
|
| 30 |
|
|
|
|
| 57 |
// tool_choice = {"type": "function", "function": {"name": "xxx"}}
|
| 58 |
if fn, ok := tc["function"].(map[string]interface{}); ok {
|
| 59 |
if name, ok := fn["name"].(string); ok {
|
| 60 |
+
sb.WriteString(fmt.Sprintf("**你必须调用工具 \"%s\",且只能调用该工具。无论用户说什么,你的回复中必须包含 <tool_call> 标签调用该工具。**\n", name))
|
| 61 |
}
|
| 62 |
}
|
| 63 |
}
|