Skip to content

fix: preserve XML-like tags in write_file/execute_code/patch content (#72797) - #72821

Open
webtecnica wants to merge 2 commits into
NousResearch:mainfrom
webtecnica:feat/tool-escalator-72747
Open

webtecnica wants to merge 2 commits into
NousResearch:mainfrom
webtecnica:feat/tool-escalator-72747

Conversation

@webtecnica

@webtecnica webtecnica commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #72797: The strip_think_blocks function in agent/agent_runtime_helpers.py and the _strip_reasoning_tags function in cli.py were both 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 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.py already 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 used re.IGNORECASE despite the comment.

The cli.py version also silently used re.IGNORECASE without the clarifying comment.

Changes

agent/agent_runtime_helpers.py

cli.py

Think/reasoning tag patterns (<think>, <thinking>, <reasoning>, <thought>, <REASONING_SCRATCHPAD>) still use re.IGNORECASE — those are expected in any case from reasoning models and should be stripped regardless of case.

Testing

  • All existing tests pass (38/38: 9 in test_strip_reasoning_tags_cli.py + 29 in test_run_agent.py related tests)
  • Manually verified:
    • <TOOL_CALL> literal data in JS/Python source is preserved
    • Lowercase <tool_call> blocks are still correctly stripped
    • Reasoning blocks (<think>, etc.) continue to be stripped case-insensitively as expected

@webtecnica
webtecnica force-pushed the feat/tool-escalator-72747 branch 2 times, most recently from 7e2bbf2 to 73ac8ba Compare July 27, 2026 18:26
@webtecnica webtecnica changed the title feat(plugins): add tool-escalator plugin for automatic MoA escalation (#72747) fix: preserve XML-like tags in write_file/execute_code/patch content (#72797) Jul 27, 2026
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard comp/plugins Plugin system and bundled plugins tool/file File tools (read, write, patch, search) tool/code-exec execute_code sandbox labels Jul 27, 2026
webtecnica 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard comp/plugins Plugin system and bundled plugins P2 Medium — degraded but workaround exists tool/code-exec execute_code sandbox tool/file File tools (read, write, patch, search) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: write_file/execute_code/patch silently strip XML-like tags from content arguments — agent must use chr(60)/chr(62) workarounds

2 participants