The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): strip namespace-prefixed text-channel tool-call XML from visible text
DoGMaTiiC60735cbf81e2
diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.pyindex 1c04a7aed91..18d65346fd0 100644--- a/agent/agent_runtime_helpers.py+++ b/agent/agent_runtime_helpers.py@@ -39,7 +39,7 @@ _REASONING_BLOCK_PATTERNS = tuple(re.compile(rf"<{name}>.*?</{name}>", re.DOTALL | re.IGNORECASE) for name in THINK_TAG_NAMES)_TOOL_CALL_BLOCK_PATTERNS = tuple(- re.compile(rf"<{name}\b[^>]*>.*?</{name}>", re.DOTALL | re.IGNORECASE)+ re.compile(rf"<(?:[\w.-]+:)?{name}\b[^>]*>.*?</(?:[\w.-]+:)?{name}>", re.DOTALL | re.IGNORECASE)for name in _TOOL_CALL_TAG_NAMES)@@ -56,7 +56,7 @@ _ORPHAN_REASONING_TAG_PATTERN = re.compile(rf'</?(?:{"|".join(THINK_TAG_NAMES)})>\s*', re.IGNORECASE)_STRAY_TOOL_CALL_CLOSER_PATTERN = re.compile(- rf'</(?:{"|".join(_TOOL_CALL_TAG_NAMES)}|function)>\s*', re.IGNORECASE+ rf'</(?:(?:[\w.-]+:)?(?:{"|".join(_TOOL_CALL_TAG_NAMES)}|function))>\s*', re.IGNORECASE)# A tool-call opener with no closer, or GLM-style argument markup@@ -65,7 +65,7 @@ _STRAY_TOOL_CALL_CLOSER_PATTERN = re.compile(# can't be recovered; strip from the block-boundary opener (or the line# holding the first stray argument tag) to the end of the text._UNTERMINATED_TOOL_CALL_PATTERN = re.compile(- rf'(?:^|\n)[ \t]*<(?:{"|".join(_TOOL_CALL_TAG_NAMES)})\b[^>]*>.*$'+ rf'(?:^|\n)[ \t]*<(?:[\w.-]+:)?(?:{"|".join(_TOOL_CALL_TAG_NAMES)})\b[^>]*>.*$'r'|(?:^|\n)[^\n<]*</?arg_(?:key|value)\b.*$',re.DOTALL | re.IGNORECASE,)diff --git a/cli.py b/cli.pyindex 3af89c3d034..7c1fab09be5 100644--- a/cli.py+++ b/cli.py@@ -197,20 +197,23 @@ def _strip_reasoning_tags(text: str) -> str:cleaned = re.sub(rf"<{tag}>.*$", "", cleaned, flags=re.DOTALL | re.IGNORECASE)cleaned = re.sub(rf"</{tag}>\s*", "", cleaned, flags=re.IGNORECASE)for tc_tag in _TOOL_CALL_TAGS:- cleaned = re.sub(rf"<{tc_tag}\b[^>]*>.*?</{tc_tag}>\s*", "", cleaned, flags=re.DOTALL | re.IGNORECASE)+ cleaned = re.sub(+ rf"<(?:[\w.-]+:)?{tc_tag}\b[^>]*>.*?</(?:[\w.-]+:)?{tc_tag}>\s*",+ "", cleaned, flags=re.DOTALL | re.IGNORECASE,+ )# <function name="..."> — boundary + attribute gated to avoid prose false positives.cleaned = re.sub(r'(?:(?<=^)|(?<=[\n\r.!?:]))[ \t]*<function\b[^>]*\bname\s*=[^>]*>(?:(?:(?!</function>).)*)</function>\s*','', cleaned, flags=re.DOTALL | re.IGNORECASE,)cleaned = re.sub(- r'</(?:tool_call|tool_calls|tool_result|function_call|function_calls|function)>\s*', '', cleaned,+ r'</(?:(?:[\w.-]+:)?(?:tool_call|tool_calls|tool_result|function_call|function_calls|function))>\s*', '', cleaned,flags=re.IGNORECASE,)# Unterminated opener / stray <arg_key>/<arg_value> markup = stream cut# mid tool-call serialization (#101899); strip to end of text.cleaned = re.sub(- r'(?:^|\n)[ \t]*<(?:tool_call|tool_calls|tool_result|function_call|function_calls)\b[^>]*>.*$'+ r'(?:^|\n)[ \t]*<(?:[\w.-]+:)?(?:tool_call|tool_calls|tool_result|function_call|function_calls)\b[^>]*>.*$'r'|(?:^|\n)[^\n<]*</?arg_(?:key|value)\b.*$','',cleaned,diff --git a/tests/agent/test_strip_reasoning_tags_cli.py b/tests/agent/test_strip_reasoning_tags_cli.pyindex 7d32c538cda..df1c645cfcd 100644--- a/tests/agent/test_strip_reasoning_tags_cli.py+++ b/tests/agent/test_strip_reasoning_tags_cli.py@@ -30,6 +30,29 @@ class TestToolCallStripping:assert "<tool_call>" not in resultassert "result" in result+ def test_namespace_prefixed_tool_call_block_stripped(self):+ # muse-spark (opencode-go, Responses wire) serializes a native call onto the text+ # channel as <atem:function_calls>…</atem:function_calls>; without a namespace-aware+ # pattern the literal XML leaks into the delivered final (the "not covered yet"+ # shape tracked in #103483).+ text = (+ "Checking the queue.\n"+ "<atem:function_calls>\n"+ '<atem:invoke name="default.terminal">\n'+ '<atem:parameter name="command">echo hi</atem:parameter>\n'+ "</atem:invoke>\n"+ "</atem:function_calls>"+ )+ for out in (_strip_reasoning_tags(text), strip_think_blocks(None, text)):+ assert "atem:" not in out+ assert "function_calls" not in out+ assert "Checking the queue." in out.strip()++ def test_cut_namespace_prefixed_tool_call_stripped_to_visible_prefix(self):+ text = 'Waiting.\n<atem:function_calls>\n<atem:invoke name="default.terminal">'+ for out in (_strip_reasoning_tags(text), strip_think_blocks(None, text)):+ assert out.strip() == "Waiting."+