fix: correct regex replacement logic in _clean_content()#168
Open
Dabao21 wants to merge 1 commit intolsdefine:mainfrom
Open
fix: correct regex replacement logic in _clean_content()#168Dabao21 wants to merge 1 commit intolsdefine:mainfrom
Dabao21 wants to merge 1 commit intolsdefine:mainfrom
Conversation
The previous implementation used '\\n' in p to decide replacement string, which incorrectly matched the raw string literal \\n in all three patterns. This caused <file_content> and <tool_use> tags to be replaced with newlines instead of empty strings. Now each pattern is explicitly paired with its correct replacement.
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.
Problem
In
agent_loop.py, the_clean_content()function used a heuristic'\\n' in pto decide whether to replace with'\n\n'or'':In Python raw strings,
\nis stored as the literal two characters\andn, so'\\n' in r'(\r?\n){3,}'evaluates toTrue. This means all three patterns were replaced with'\n\n', including<file_content>and<tool_use>tags which should be replaced with an empty string''to remove them entirely.Fix
Replace the heuristic with explicit pattern-replacement pairs:
Impact
<file_content>and<tool_use>tags are now correctly stripped (replaced with empty string) instead of leaving extra newlines