🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
Merge branch 'code_interpreter' into mi_refactor
yzlin3244e6cee5c4
diff --cc metagpt/roles/mi/interpreter.pyindex e71514b62,2392863a0..a083f7f7d--- a/metagpt/roles/mi/interpreter.py+++ b/metagpt/roles/mi/interpreter.py@@@ -59,33 -42,11 +59,37 @@@ class Interpreter(Role)def working_memory(self):return self.rc.working_memory+ async def _think(self) -> bool:+ """Useful in 'react' mode. Use LLM to decide whether and what to do next."""+ user_requirement = self.get_memories()[0].content+ context = self.working_memory.get()++ if not context:+ # just started the run, we need action certainly+ self.working_memory.add(self.get_memories()[0]) # add user requirement to working memory+ self._set_state(0)+ return True++ prompt = REACT_THINK_PROMPT.format(user_requirement=user_requirement, context=context)+ rsp = await self.llm.aask(prompt)+ rsp_dict = json.loads(CodeParser.parse_code(block=None, text=rsp))+ self.working_memory.add(Message(content=rsp_dict["thoughts"], role="assistant"))+ need_action = rsp_dict["state"]+ self._set_state(0) if need_action else self._set_state(-1)++ return need_action++ async def _act(self) -> Message:+ """Useful in 'react' mode. Return a Message conforming to Role._act interface."""+ code, _, _ = await self._write_and_exec_code()+ return Message(content=code, role="assistant", cause_by=WriteCodeWithTools)++ async def _plan_and_act(self) -> Message:+ await super()._plan_and_act()+ await self.execute_code.terminate()+async def _act_on_task(self, current_task: Task) -> TaskResult:+ """Useful in 'plan_and_act' mode. Wrap the output in a TaskResult for review and confirmation."""code, result, is_success = await self._write_and_exec_code()task_result = TaskResult(code=code, result=result, is_success=is_success)return task_result