fix: preserve XML-like tags in write_file/execute_code/patch content (#72797) - #72821
Open
webtecnica wants to merge 2 commits into
Open
webtecnica wants to merge 2 commits into
webtecnica wants to merge 2 commits into
Conversation
webtecnica
force-pushed
the
feat/tool-escalator-72747
branch
2 times, most recently
from
July 27, 2026 18:26
7e2bbf2 to
73ac8ba
Compare
added 2 commits
July 27, 2026 22:07
…ousResearch#72797) The strip_think_blocks function in agent_runtime_helpers.py and the _strip_reasoning_tags function in cli.py were using re.IGNORECASE when stripping tool-call XML blocks (<tool_call>, <tool_calls>, <tool_result>, <function_call>, <function_calls>) from assistant text content. This caused uppercase variants like <TOOL_CALL> and </TOOL_CALL> — which are valid literal data in JS/HTML/Python source code — to be silently stripped from tool content arguments. The comment in agent_runtime_helpers.py already documented that case-insensitive matching was intentional but the code was wrong (it used re.IGNORECASE despite the comment saying not to). Fix both functions: - Remove re.IGNORECASE from tool-call XML block regex patterns - Remove re.IGNORECASE from stray tool-call close tag patterns - Add clarifying comments referencing NousResearch#72797 - Keep re.IGNORECASE on think/reasoning tag patterns (those ARE expected in any case from reasoning models) This aligns the behavior with the existing cli.py documentation and prevents LLM-generated source code containing XML-like tags from being silently corrupted.
webtecnica
force-pushed
the
feat/tool-escalator-72747
branch
from
July 28, 2026 01:16
e93f0fe to
202b828
Compare
Closed
1 task
This was referenced Aug 5, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #72797: The
strip_think_blocksfunction inagent/agent_runtime_helpers.pyand the_strip_reasoning_tagsfunction incli.pywere both usingre.IGNORECASEwhen stripping tool-call XML blocks (<tool_call>,<tool_calls>,<tool_result>,<function_call>,<function_calls>) from assistant text content.This caused uppercase variants like
<TOOL_CALL>and</TOOL_CALL>— which appear as valid literal data in JS/HTML/Python source code being written to files — to be silently stripped, truncating the tool content arguments before they reached the tool.Root cause
The comment in
agent_runtime_helpers.pyalready documented that case-insensitive matching was intentionally avoided to prevent corrupting literal data (e.g., JS/HTML containing<TOOL_CALL>strings), but the code was incorrect — it usedre.IGNORECASEdespite the comment.The
cli.pyversion also silently usedre.IGNORECASEwithout the clarifying comment.Changes
agent/agent_runtime_helpers.pyre.IGNORECASEfrom the tool-call XML block regex patternscli.pyre.IGNORECASEfrom the same tool-call XML block patternsThink/reasoning tag patterns (
<think>,<thinking>,<reasoning>,<thought>,<REASONING_SCRATCHPAD>) still usere.IGNORECASE— those are expected in any case from reasoning models and should be stripped regardless of case.Testing
test_strip_reasoning_tags_cli.py+ 29 intest_run_agent.pyrelated tests)<TOOL_CALL>literal data in JS/Python source is preserved<tool_call>blocks are still correctly stripped<think>, etc.) continue to be stripped case-insensitively as expected