From 5255be144ec668deb70118466c721874e7dada76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=A3=92=E6=A3=92?= Date: Sat, 30 Mar 2024 18:52:53 +0800 Subject: [PATCH] add try_except for _plan_and_act in data_interpreter. --- metagpt/roles/di/data_interpreter.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/metagpt/roles/di/data_interpreter.py b/metagpt/roles/di/data_interpreter.py index a8534b710..44a85fe06 100644 --- a/metagpt/roles/di/data_interpreter.py +++ b/metagpt/roles/di/data_interpreter.py @@ -86,9 +86,13 @@ class DataInterpreter(Role): return Message(content=code, role="assistant", cause_by=WriteAnalysisCode) async def _plan_and_act(self) -> Message: - rsp = await super()._plan_and_act() - await self.execute_code.terminate() - return rsp + try: + rsp = await super()._plan_and_act() + await self.execute_code.terminate() + return rsp + except Exception as e: + await self.execute_code.terminate() + raise e 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."""