From e8078c25823edbedd9559dd3cbdce81dfd0d17bc Mon Sep 17 00:00:00 2001
From: Iams4kura <126048986+Iams4kura@users.noreply.github.com>
Date: Sat, 22 Aug 2026 01:11:47 +0800
Subject: [PATCH] fix(s3): reject responses with incomplete tags
---
gui_agents/s3/utils/formatters.py | 11 ++++++++++-
tests/test_formatters.py | 29 +++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 1 deletion(-)
create mode 100644 tests/test_formatters.py
diff --git a/gui_agents/s3/utils/formatters.py b/gui_agents/s3/utils/formatters.py
index 08889826..24889875 100644
--- a/gui_agents/s3/utils/formatters.py
+++ b/gui_agents/s3/utils/formatters.py
@@ -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 = ("", "", "", "")
+ 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 ... and ... tags."
THOUGHTS_ANSWER_TAG_FORMATTER = lambda response: (
thoughts_answer_tag_check(response),
diff --git a/tests/test_formatters.py b/tests/test_formatters.py
new file mode 100644
index 00000000..57fbdfbc
--- /dev/null
+++ b/tests/test_formatters.py
@@ -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",
+ "reasoninganswer",
+ "reasoninganswer",
+ ]
+
+ 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(
+ "reasoninganswer"
+ )
+
+ self.assertTrue(success)
+
+
+if __name__ == "__main__":
+ unittest.main()