mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-28 06:51:16 +08:00
fix: add <thought> stripping to auxiliary_client + tests
auxiliary_client.py had its own regex mirroring _strip_think_blocks but was missing the <thought> variant. Also adds test coverage for <thought> paired and orphaned tags.
This commit is contained in:
@@ -2454,9 +2454,9 @@ def extract_content_or_reasoning(response) -> str:
|
|||||||
if content:
|
if content:
|
||||||
# Strip inline think/reasoning blocks (mirrors _strip_think_blocks)
|
# Strip inline think/reasoning blocks (mirrors _strip_think_blocks)
|
||||||
cleaned = re.sub(
|
cleaned = re.sub(
|
||||||
r"<(?:think|thinking|reasoning|REASONING_SCRATCHPAD)>"
|
r"<(?:think|thinking|reasoning|thought|REASONING_SCRATCHPAD)>"
|
||||||
r".*?"
|
r".*?"
|
||||||
r"</(?:think|thinking|reasoning|REASONING_SCRATCHPAD)>",
|
r"</(?:think|thinking|reasoning|thought|REASONING_SCRATCHPAD)>",
|
||||||
"", content, flags=re.DOTALL | re.IGNORECASE,
|
"", content, flags=re.DOTALL | re.IGNORECASE,
|
||||||
).strip()
|
).strip()
|
||||||
if cleaned:
|
if cleaned:
|
||||||
|
|||||||
@@ -302,6 +302,17 @@ class TestStripThinkBlocks:
|
|||||||
assert "<think>" not in result
|
assert "<think>" not in result
|
||||||
assert "visible" in result
|
assert "visible" in result
|
||||||
|
|
||||||
|
def test_thought_block_removed(self, agent):
|
||||||
|
"""Gemma 4 uses <thought> tags for inline reasoning."""
|
||||||
|
result = agent._strip_think_blocks("<thought>internal reasoning</thought> answer")
|
||||||
|
assert "internal reasoning" not in result
|
||||||
|
assert "<thought>" not in result
|
||||||
|
assert "answer" in result
|
||||||
|
|
||||||
|
def test_orphaned_thought_tag(self, agent):
|
||||||
|
result = agent._strip_think_blocks("<thought>orphaned reasoning without close")
|
||||||
|
assert "<thought>" not in result
|
||||||
|
|
||||||
|
|
||||||
class TestExtractReasoning:
|
class TestExtractReasoning:
|
||||||
def test_reasoning_field(self, agent):
|
def test_reasoning_field(self, agent):
|
||||||
|
|||||||
Reference in New Issue
Block a user