@@ -3679,6 +3679,21 @@ def _add(data: dict) -> None:
36793679 if args :
36803680 _add ({"action" : TOOL_ALIASES .get (raw_action , raw_action ), "args" : args })
36813681
3682+ xml_action_pattern = re .compile (
3683+ r"<\s*action\s*>\s*(?P<name>[A-Za-z_]\w*)[ \t]*\r?\n"
3684+ r"(?P<args>[\s\S]*?)</\s*action\s*>" ,
3685+ re .IGNORECASE ,
3686+ )
3687+ xml_actions = list (xml_action_pattern .finditer (text ))
3688+ # Provider XML is accepted only as one complete, unambiguous action block.
3689+ if len (xml_actions ) == 1 and not re .search (
3690+ r"<\s*action\s*>[\s\S]*<\s*action\s*>" , text , re .IGNORECASE ):
3691+ xml_action = xml_actions [0 ]
3692+ raw_action = xml_action .group ("name" ).strip ().lower ()
3693+ args = html .unescape (xml_action .group ("args" ).strip ())
3694+ if args and _is_valid_action (raw_action ):
3695+ _add ({"action" : TOOL_ALIASES .get (raw_action , raw_action ), "args" : args })
3696+
36823697 for data in _collect_unwrapped_tool_calls (text )[0 ]:
36833698 if _is_valid_action (data .get ("action" )):
36843699 _add (data )
@@ -4378,15 +4393,15 @@ class DeepSeekDSMLFilter:
43784393 r"(?i)(?<![\w])(?P<kind>Action|Thought|Plan|TaskList|TaskDone|DefineTool)\s*:"
43794394 )
43804395 _GENERIC_OPEN_RE = re .compile (
4381- r"<\s*(?P<kind>invoke|parameter|calls|tool_calls|function_calls|tool_use|notes|thought|reasoning)\b[^>]*>" ,
4396+ r"<\s*(?P<kind>action| invoke|parameter|calls|tool_calls|function_calls|tool_use|notes|thought|reasoning)\b[^>]*>" ,
43824397 re .IGNORECASE ,
43834398 )
43844399 _GENERIC_CLOSE_RE = re .compile (
4385- r"</\s*(?P<kind>invoke|parameter|calls|tool_calls|function_calls|tool_use|notes|thought|reasoning)\s*>" ,
4400+ r"</\s*(?P<kind>action| invoke|parameter|calls|tool_calls|function_calls|tool_use|notes|thought|reasoning)\s*>" ,
43864401 re .IGNORECASE ,
43874402 )
43884403 _GENERIC_KINDS = (
4389- "invoke" , "parameter" , "calls" , "tool_calls" , "function_calls" ,
4404+ "action" , " invoke" , "parameter" , "calls" , "tool_calls" , "function_calls" ,
43904405 "tool_use" , "notes" , "thought" , "reasoning" ,
43914406 )
43924407 _ACTION_MARKER_RE = _ACTION_MARKER_RE
@@ -4520,7 +4535,7 @@ def _generic_block_end(cls, value: str, match: re.Match[str]) -> int | None:
45204535 kind = match .group ("kind" ).lower ()
45214536 close_kinds = (
45224537 "parameter" if kind == "parameter" else
4523- "invoke|calls|tool_calls|function_calls|tool_use|notes|thought|reasoning"
4538+ "action| invoke|calls|tool_calls|function_calls|tool_use|notes|thought|reasoning"
45244539 )
45254540 close = re .compile (rf"</\s*(?:{ close_kinds } )\s*>" , re .IGNORECASE ).search (value , match .end ())
45264541 return close .end () if close else None
0 commit comments