mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-04 08:25:26 +08:00
feat: add strict schema enforcement and strip hallucinated fields from tool call parameters
This commit is contained in:
@@ -53,6 +53,7 @@ RULES:
|
||||
5) After receiving a tool result, use it directly. Only call another tool if the result is insufficient.
|
||||
6) If you want to say something AND call a tool, output text first, then the XML block on its own.
|
||||
7) Parameters MUST use the exact field names from the selected tool schema.
|
||||
8) 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.
|
||||
|
||||
❌ WRONG — Do NOT do these:
|
||||
Wrong 1 — mixed text and XML:
|
||||
@@ -61,6 +62,9 @@ Wrong 2 — describing tool calls in text:
|
||||
[调用 Bash] {"command": "ls"}
|
||||
Wrong 3 — missing <tool_calls> wrapper:
|
||||
<tool_call><tool_name>` + ex1 + `</tool_name><parameters>{}</parameters></tool_call>
|
||||
Wrong 4 — extra/invented fields:
|
||||
<parameters>{"_raw": "...", "command": "ls"}</parameters>
|
||||
|
||||
|
||||
✅ CORRECT EXAMPLES:
|
||||
|
||||
|
||||
@@ -158,6 +158,10 @@ func filterToolCallsDetailed(parsed []ParsedToolCall, availableToolNames []strin
|
||||
}
|
||||
if tc.Input == nil {
|
||||
tc.Input = map[string]any{}
|
||||
} else {
|
||||
// Remove known hallucinated fields often generated by models trying to bridge XML and JSON
|
||||
delete(tc.Input, "_raw")
|
||||
delete(tc.Input, "_xml")
|
||||
}
|
||||
out = append(out, tc)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user