feat: implement code fence awareness in tool sieve to prevent false-positive XML tool detection inside code blocks and refine prompt instructions.

This commit is contained in:
CJACK
2026-04-20 00:13:14 +08:00
parent 12256ceb24
commit f313d0068f
9 changed files with 300 additions and 143 deletions

View File

@@ -36,8 +36,6 @@ func BuildToolCallInstructions(toolNames []string) string {
return `TOOL CALL FORMAT — FOLLOW EXACTLY:
If you need to call tools, your entire response must be exactly one XML block and nothing else.
<tool_calls>
<tool_call>
<tool_name>TOOL_NAME_HERE</tool_name>
@@ -63,7 +61,8 @@ PARAMETER SHAPES:
- array => repeated tags or <item> children
- number/bool/null => plain text
WRONG — Do NOT do these:
WRONG — Do NOT do these:
Wrong 1 — mixed text after XML:
<tool_calls>...</tool_calls> I hope this helps.
Wrong 2 — function-call syntax:
@@ -74,14 +73,10 @@ Wrong 4 — Markdown code fences:
` + "```xml" + `
<tool_calls>...</tool_calls>
` + "```" + `
Wrong 5 — native tool tokens:
<Tool>call_some_tool{"param":1}<Tool>
Wrong 6 — role markers in response:
<Assistant> Here is the result...
Remember: The ONLY valid way to use tools is the <tool_calls> XML block at the end of your response.
CORRECT EXAMPLES:
CORRECT EXAMPLES:
Example A — Single tool:
<tool_calls>
@@ -127,7 +122,7 @@ fi
</tool_call>
</tool_calls>
Remember: Output ONLY the <tool_calls>...</tool_calls> XML block when calling tools.`
`
}
func matchAny(name string, candidates ...string) bool {