Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion gui_agents/s3/utils/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ def _attempt_code_creation(agent, code, obs):
code_valid_error_msg,
)

thoughts_answer_tag_check = lambda response: split_thinking_response(response)[1] != ""

def thoughts_answer_tag_check(response):
tags = ("<thoughts>", "</thoughts>", "<answer>", "</answer>")
tag_positions = [response.find(tag) for tag in tags]
if -1 in tag_positions or tag_positions != sorted(tag_positions):
return False

return split_thinking_response(response)[1] != ""


thoughts_answer_tag_error_msg = "Incorrect response: The response must contain both <thoughts>...</thoughts> and <answer>...</answer> tags."
THOUGHTS_ANSWER_TAG_FORMATTER = lambda response: (
thoughts_answer_tag_check(response),
Expand Down
29 changes: 29 additions & 0 deletions tests/test_formatters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import unittest

from gui_agents.s3.utils.formatters import THOUGHTS_ANSWER_TAG_FORMATTER


class TestThoughtsAnswerFormatter(unittest.TestCase):
def test_rejects_incomplete_tags(self):
responses = [
"plain response",
"<thoughts>reasoning</thoughts>answer",
"reasoning<answer>answer</answer>",
]

for response in responses:
with self.subTest(response=response):
success, _ = THOUGHTS_ANSWER_TAG_FORMATTER(response)

self.assertFalse(success)

def test_accepts_complete_tags(self):
success, _ = THOUGHTS_ANSWER_TAG_FORMATTER(
"<thoughts>reasoning</thoughts><answer>answer</answer>"
)

self.assertTrue(success)


if __name__ == "__main__":
unittest.main()