Skip to content

The agent that grows with you

fix(agent): strip arg fragments glued to a bare tool name (#101899)

kshitijk4poorcf8b08edac3a
diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.py
index 96ed1c21cd2..80d1abd08bd 100644
--- a/agent/agent_runtime_helpers.py
+++ b/agent/agent_runtime_helpers.py
@@ -64,11 +64,12 @@ _STRAY_TOOL_CALL_CLOSER_PATTERN = re.compile(
# An unclosed tool call is unrecoverable (#101899), so drop its remaining block.
# Stray argument tags only identify fragment lines, not the rest of the text
-# (#102303). Require a line-start tag or a line-ending closer (wait</arg_value>)
-# so inline prose mentions and subsequent prose survive.
+# (#102303). Require a line-start tag (optionally glued to a bare tool name,
+# process_manage<arg_key>) or a line-ending closer (wait</arg_value>) so inline
+# prose mentions and subsequent prose survive.
_UNTERMINATED_TOOL_CALL_PATTERN = re.compile(
rf'(?:^|\n)[ \t]*<{_NS_PREFIX}(?:{"|".join(_TOOL_CALL_TAG_NAMES)})\b[^>]*>.*$'
- r'|(?:^|\n)[ \t]*</?arg_(?:key|value)\b[^\n]*'
+ r'|(?:^|\n)[ \t]*[\w.:-]*</?arg_(?:key|value)\b[^\n]*'
r'|(?:^|\n)[^\n<]*</arg_(?:key|value)>[ \t\r]*(?=\n|$)',
re.DOTALL | re.IGNORECASE,
)
diff --git a/tests/agent/test_strip_reasoning_tags_cli.py b/tests/agent/test_strip_reasoning_tags_cli.py
index e8528ec4b7f..05d8360f91c 100644
--- a/tests/agent/test_strip_reasoning_tags_cli.py
+++ b/tests/agent/test_strip_reasoning_tags_cli.py
@@ -74,8 +74,11 @@ class TestToolCallStripping:
(_CUT_FRAGMENT + "\nThird line must survive.",
"Both gates started.\nThird line must survive."),
("Waiting.\n<tool_call>process_manage", "Waiting."),
+ ("Done.\nprocess_manage<arg_key>action</arg_key><arg_value>wait</arg_value>", "Done."),
+ ("Hi.\nterminal<arg_key>command</arg_key><arg_value>ls -la", "Hi."),
],
- ids=["original-fragment", "fragment-only", "prose-after-fragment", "unclosed-call"],
+ ids=["original-fragment", "fragment-only", "prose-after-fragment", "unclosed-call",
+ "name-prefixed-fragment", "name-prefixed-fragment-cut-value"],
)
def test_cut_tool_call_stripped_to_visible_prefix(self, stripper, text, expected):
"""A cut call is unrecoverable, but unrelated prose must not be lost."""