@@ -122,7 +122,13 @@ def _retrieve_file_content() -> Dict[str, Any]:
122122 "type" : "function" ,
123123 "function" : {
124124 "name" : "retrieve_file_content" ,
125- "description" : "读取已生成的文件内容。测试失败或编译错误时,使用此工具查看当前文件内容进行分析" ,
125+ "description" : """读取已生成的文件内容。测试失败或编译错误时,使用此工具查看当前文件内容进行分析。
126+
127+ ⚠️ 重要约束:
128+ - **retrieve 后必须修改文件!** 禁止「retrieve → compile」不改文件的无效循环
129+ - 如果只是验证修复思路,直接在脑中分析,不要 retrieve
130+ - 只有在不确定当前代码状态、需要确认细节时才 retrieve
131+ - retrieve 后必须调用 create_or_update_file(overwrite_existing=true)更新文件""" ,
126132 "parameters" : {
127133 "type" : "object" ,
128134 "properties" : {
@@ -222,7 +228,12 @@ def _compile_and_test() -> Dict[str, Any]:
222228
223229使用场景:
224230- 生成题目代码后,立即验证正确性
225- - 修复代码后,快速验证修复结果""" ,
231+ - 修复代码后,快速验证修复结果
232+
233+ ⚠️ 重要约束:
234+ - **如果上一次调用返回了 "编译成功,所有测试通过",禁止再次调用!**
235+ - 测试通过后,等待系统处理(LeetCode 提交或生成报告),不要重复测试
236+ - 只有在修改了代码(create_or_update_file)或添加了测试用例(append_test_case)后才再次调用""" ,
226237 "parameters" : {
227238 "type" : "object" ,
228239 "properties" : {
@@ -605,7 +616,8 @@ def _compile_and_test(self, problem_id: int) -> Dict[str, Any]:
605616 "error_type" : error_analysis ["type" ],
606617 "error_details" : error_analysis ["details" ],
607618 "suggestion" : error_analysis ["suggestion" ],
608- "output" : output
619+ "output" : output ,
620+ "next_steps" : "❌ 编译失败。修复流程:1) 仔细阅读错误信息和错误详情;2) 分析问题原因(语法?类型?头文件?);3) 直接调用 create_or_update_file 修复代码(overwrite_existing=true);4) 修复后再次调用 compile_and_test 验证。⚠️ 禁止仅 retrieve 不修改的循环!"
609621 }
610622
611623 # 编译成功,检查测试结果
@@ -619,7 +631,8 @@ def _compile_and_test(self, problem_id: int) -> Dict[str, Any]:
619631 return {
620632 "is_successful" : True ,
621633 "status_message" : f"编译成功,{ test_count } 个测试通过" ,
622- "output" : output [- 2000 :] if len (output ) > 2000 else output
634+ "output" : output [- 2000 :] if len (output ) > 2000 else output ,
635+ "next_steps" : "✅ 本地测试已通过。现在:1) 等待系统自动提交到 LeetCode 验证;2) 禁止再次调用 compile_and_test;3) 如果 LeetCode 返回失败,按 Wrong Answer 流程处理(添加测试用例 → 修复代码 → 重新测试)"
623636 }
624637 elif "FAILED" in output :
625638 # 测试失败,分析失败原因
@@ -630,7 +643,8 @@ def _compile_and_test(self, problem_id: int) -> Dict[str, Any]:
630643 "error_type" : error_analysis ["type" ],
631644 "error_details" : error_analysis ["details" ],
632645 "suggestion" : error_analysis ["suggestion" ],
633- "output" : output
646+ "output" : output ,
647+ "next_steps" : "❌ 测试失败。修复流程:1) 分析错误信息和失败详情;2) 确定修复方案;3) 直接调用 create_or_update_file 修复代码(overwrite_existing=true);4) 修复后再次调用 compile_and_test 验证。⚠️ 禁止 retrieve_file_content → compile 不改文件的循环!"
634648 }
635649 else :
636650 # 无法确定结果
@@ -645,7 +659,8 @@ def _compile_and_test(self, problem_id: int) -> Dict[str, Any]:
645659 "is_successful" : False ,
646660 "error_message" : "编译或测试超时" ,
647661 "error_type" : "timeout" ,
648- "suggestion" : "编译或测试时间过长,请检查代码是否有无限循环或其他问题"
662+ "suggestion" : "编译或测试时间过长,请检查代码是否有无限循环或其他问题" ,
663+ "next_steps" : "⏱️ 超时。检查:1) 是否有死循环;2) 算法时间复杂度是否过高;3) 测试用例是否过大。修复后重新调用 compile_and_test"
649664 }
650665 except Exception as e :
651666 return {"is_successful" : False , "error_message" : str (e )}
0 commit comments