🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
1. merge run and run_reflection; 2. remove useless code
stellahsrc9f6b7cc8d68
diff --git a/metagpt/actions/debug_code.py b/metagpt/actions/debug_code.pyindex 9a8b4c122..34dac0147 100644--- a/metagpt/actions/debug_code.py+++ b/metagpt/actions/debug_code.py@@ -47,7 +47,7 @@ Here is an example for you.[runtime Error]{runtime_result}-Analysis the error step by step, provide me improve method and code. Remember to follow [context] rerquirement. Don't forget write code for steps behind the error step.+Analysis the error step by step, provide me improve method and code. Remember to follow [context] requirement. Don't forget write code for steps behind the error step.[reflection on previous impl]:xxx"""@@ -72,19 +72,25 @@ CODE_REFLECTION = {}-def messages_to_str(messages: List[Message]) -> str:- return "\n".join([str(message) for message in messages])+class DebugCode(BaseWriteAnalysisCode):+ async def run(+ self,+ context: List[Message] = None,+ code: str = "",+ runtime_result: str = "",+ ) -> str:+ """+ Execute the debugging process based on the provided context, code, and runtime_result.+ Args:+ context (List[Message]): A list of Message objects representing the context.+ code (str): The code to be debugged.+ runtime_result (str): The result of the code execution.-class DebugCode(BaseWriteAnalysisCode):- name: str = "debugcode"+ Returns:+ str: The improved implementation based on the debugging process.+ """- async def run_reflection(- self,- context: list[Message],- code: str,- runtime_result: str,- ) -> dict:info = []reflection_prompt = REFLECTION_PROMPT.format(debug_example=DEBUG_REFLECTION_EXAMPLE,@@ -96,22 +102,8 @@ class DebugCode(BaseWriteAnalysisCode):info.append(Message(role="system", content=system_prompt))info.append(Message(role="user", content=reflection_prompt))- resp = await self.llm.aask_code(messages=info, **create_func_call_config(CODE_REFLECTION))- logger.info(f"reflection is {resp}")- return resp+ tool_config = create_func_call_config(CODE_REFLECTION)+ reflection = await self.llm.aask_code(messages=info, **tool_config)+ logger.info(f"reflection is {reflection}")- async def run(- self,- context: List[Message] = None,- code: str = "",- runtime_result: str = "",- ) -> str:- """- use reflection to debug, based on current code and the execution errors- """- reflection = await self.run_reflection(- code=code,- context=context,- runtime_result=runtime_result,- )return {"code": reflection["improved_impl"]}diff --git a/tests/metagpt/actions/test_debug_code.py b/tests/metagpt/actions/test_debug_code.pyindex 83ce75761..32a4914f4 100644--- a/tests/metagpt/actions/test_debug_code.py+++ b/tests/metagpt/actions/test_debug_code.py@@ -5,7 +5,7 @@import pytest-from metagpt.actions.debug_code import DebugCode, messages_to_str+from metagpt.actions.debug_code import DebugCodefrom metagpt.schema import MessageErrorStr = """Tested passed:@@ -49,9 +49,3 @@ async def test_debug_code():debug_context = Message(content=DebugContext)new_code = await DebugCode().run(context=debug_context, code=CODE, runtime_result=ErrorStr)assert "def sort_array(arr)" in new_code["code"]---def test_messages_to_str():- debug_context = Message(content=DebugContext)- msg_str = messages_to_str([debug_context])- assert "user: Solve the problem in Python" in msg_str