fix: Handle stray quotes in tag names and enforce parameter tags in prompt

This commit is contained in:
0xallam
2026-02-20 08:26:44 -08:00
committed by Ahmed Allam
parent b9dcf7f63d
commit 027cea2f25
2 changed files with 12 additions and 7 deletions

View File

@@ -328,6 +328,9 @@ WRONG formats — NEVER use these:
- <tool_call><tool_name>...</tool_name></tool_call> - <tool_call><tool_name>...</tool_name></tool_call>
- {"tool_name": {"param_name": "value"}} - {"tool_name": {"param_name": "value"}}
- ```<function=tool_name>...</function>``` - ```<function=tool_name>...</function>```
- <function=tool_name>value_without_parameter_tags</function>
EVERY argument MUST be wrapped in <parameter=name>...</parameter> tags. NEVER put values directly in the function body without parameter tags. This WILL cause the tool call to fail.
Do NOT emit any extra XML tags in your output. In particular: Do NOT emit any extra XML tags in your output. In particular:
- NO <thinking>...</thinking> or <thought>...</thought> blocks - NO <thinking>...</thinking> or <thought>...</thought> blocks
@@ -337,6 +340,11 @@ If you need to reason, use the think tool. Your raw output must contain ONLY the
Notice: use <function=X> NOT <invoke name="X">, use <parameter=X> NOT <parameter name="X">, use </function> NOT </invoke>. Notice: use <function=X> NOT <invoke name="X">, use <parameter=X> NOT <parameter name="X">, use </function> NOT </invoke>.
Example (terminal tool):
<function=terminal_execute>
<parameter=command>nmap -sV -p 1-1000 target.com</parameter>
</function>
Example (agent creation tool): Example (agent creation tool):
<function=create_agent> <function=create_agent>
<parameter=task>Perform targeted XSS testing on the search endpoint</parameter> <parameter=task>Perform targeted XSS testing on the search endpoint</parameter>

View File

@@ -6,8 +6,7 @@ from typing import Any
_INVOKE_OPEN = re.compile(r'<invoke\s+name=["\']([^"\']+)["\']>') _INVOKE_OPEN = re.compile(r'<invoke\s+name=["\']([^"\']+)["\']>')
_PARAM_NAME_ATTR = re.compile(r'<parameter\s+name=["\']([^"\']+)["\']>') _PARAM_NAME_ATTR = re.compile(r'<parameter\s+name=["\']([^"\']+)["\']>')
_FUNCTION_CALLS_TAG = re.compile(r"</?function_calls>") _FUNCTION_CALLS_TAG = re.compile(r"</?function_calls>")
_QUOTED_FUNCTION = re.compile(r"""<function\s*=\s*['"]([^"']+)['"]\s*>""") _STRIP_TAG_QUOTES = re.compile(r"<(function|parameter)\s*=\s*([^>]*?)>")
_QUOTED_PARAMETER = re.compile(r"""<parameter\s*=\s*['"]([^"']+)['"]\s*>""")
def normalize_tool_format(content: str) -> str: def normalize_tool_format(content: str) -> str:
@@ -27,11 +26,9 @@ def normalize_tool_format(content: str) -> str:
content = _PARAM_NAME_ATTR.sub(r"<parameter=\1>", content) content = _PARAM_NAME_ATTR.sub(r"<parameter=\1>", content)
content = content.replace("</invoke>", "</function>") content = content.replace("</invoke>", "</function>")
content = _QUOTED_FUNCTION.sub(r"<function=\1>", content) return _STRIP_TAG_QUOTES.sub(
content = _QUOTED_PARAMETER.sub(r"<parameter=\1>", content) lambda m: f"<{m.group(1)}={m.group(2).strip().strip(chr(34) + chr(39))}>", content
)
content = re.sub(r"<function=\s+", "<function=", content)
return re.sub(r"<parameter=\s+", "<parameter=", content)
STRIX_MODEL_MAP: dict[str, str] = { STRIX_MODEL_MAP: dict[str, str] = {