diff --git a/internal/toolcall/tool_prompt.go b/internal/toolcall/tool_prompt.go index 8d6649a..bcf1046 100644 --- a/internal/toolcall/tool_prompt.go +++ b/internal/toolcall/tool_prompt.go @@ -46,24 +46,33 @@ When calling tools, emit ONLY raw XML at the very end of your response. No text RULES: -1) Output ONLY the XML above when calling tools. Do NOT mix tool XML with regular text. -2) MUST contain a strict JSON object. All JSON keys and strings use double quotes. -3) Multiple tools → multiple blocks inside ONE root. -4) Do NOT wrap the XML in markdown code fences (no triple backticks). -5) After receiving a tool result, use it directly. Only call another tool if the result is insufficient. -6) Parameters MUST use the exact field names from the selected tool schema. -7) CRITICAL: Do NOT invent or add any extra fields (such as "_raw", "_xml"). Use ONLY the fields strictly defined in the schema. Extra fields will cause execution failure. +1) When calling tools, you MUST use the XML format. +2) No text is allowed AFTER the XML block. +3) MUST be a single-line strict JSON object. Use double quotes. +4) Multiple tools must be inside the same root. +5) Do NOT wrap XML in markdown fences (` + "```" + `). +6) Do NOT invent parameters. Use only the provided schema. +7) CRITICAL: Do NOT use native tool markers like "<|Tool|>" or "<|tool|>". +8) CRITICAL: Do NOT output role markers like "<|System|>", "<|User|>", or "<|Assistant|>". +9) CRITICAL: Do NOT output internal monologues (e.g. "I will list files now..."). Just output your answer or the XML. ❌ WRONG — Do NOT do these: -Wrong 1 — mixed text and XML: - I'll read the file for you. ... -Wrong 2 — describing tool calls in text: - [调用 Bash] {"command": "ls"} +Wrong 1 — mixed text after XML: + ... I hope this helps. +Wrong 2 — function-call syntax: + Grep({"pattern": "token"}) Wrong 3 — missing wrapper: ` + ex1 + `{} -Wrong 4 — extra/invented fields: - {"_raw": "...", "command": "ls"} +Wrong 4 — Markdown code fences: + ` + "```xml" + ` + ... + ` + "```" + ` +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 XML block at the end of your response. ✅ CORRECT EXAMPLES: diff --git a/internal/toolcall/toolcalls_parse.go b/internal/toolcall/toolcalls_parse.go index 8f0a289..400fd86 100644 --- a/internal/toolcall/toolcalls_parse.go +++ b/internal/toolcall/toolcalls_parse.go @@ -41,7 +41,7 @@ func ParseToolCallsDetailed(text string, availableToolNames []string) ToolCallPa continue } parsed := tc - calls, rejectedNames := filterToolCallsDetailed(parsed, availableToolNames) + calls, rejectedNames := filterToolCallsDetailed(parsed) result.Calls = calls result.RejectedToolNames = rejectedNames result.RejectedByPolicy = len(rejectedNames) > 0 && len(calls) == 0 @@ -77,7 +77,7 @@ func ParseToolCallsDetailed(text string, availableToolNames []string) ToolCallPa result.SawToolCallSyntax = true } - calls, rejectedNames := filterToolCallsDetailed(parsed, availableToolNames) + calls, rejectedNames := filterToolCallsDetailed(parsed) result.Calls = calls result.RejectedToolNames = rejectedNames result.RejectedByPolicy = len(rejectedNames) > 0 && len(calls) == 0 @@ -108,7 +108,7 @@ func ParseStandaloneToolCallsDetailed(text string, availableToolNames []string) continue } result.SawToolCallSyntax = true - calls, rejectedNames := filterToolCallsDetailed(parsed, availableToolNames) + calls, rejectedNames := filterToolCallsDetailed(parsed) result.Calls = calls result.RejectedToolNames = rejectedNames result.RejectedByPolicy = len(rejectedNames) > 0 && len(calls) == 0 @@ -143,14 +143,14 @@ func ParseStandaloneToolCallsDetailed(text string, availableToolNames []string) } } result.SawToolCallSyntax = true - calls, rejectedNames := filterToolCallsDetailed(parsed, availableToolNames) + calls, rejectedNames := filterToolCallsDetailed(parsed) result.Calls = calls result.RejectedToolNames = rejectedNames result.RejectedByPolicy = len(rejectedNames) > 0 && len(calls) == 0 return result } -func filterToolCallsDetailed(parsed []ParsedToolCall, availableToolNames []string) ([]ParsedToolCall, []string) { +func filterToolCallsDetailed(parsed []ParsedToolCall) ([]ParsedToolCall, []string) { out := make([]ParsedToolCall, 0, len(parsed)) for _, tc := range parsed { if tc.Name == "" {