🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
add handle_exception to ensure robustness
seehid148a3217bbe
diff --git a/metagpt/exp_pool/decorator.py b/metagpt/exp_pool/decorator.pyindex 9eb4d9e61..9cf924779 100644--- a/metagpt/exp_pool/decorator.py+++ b/metagpt/exp_pool/decorator.py@@ -10,6 +10,7 @@ from metagpt.exp_pool.manager import ExperienceManager, exp_managerfrom metagpt.exp_pool.schema import Experience, Metric, QueryType, Scorefrom metagpt.exp_pool.scorers import ExperienceScorer, SimpleScorerfrom metagpt.utils.async_helper import NestAsyncio+from metagpt.utils.exceptions import handle_exceptionReturnType = TypeVar("ReturnType")@@ -50,8 +51,7 @@ def exp_cache(return expawait handler.execute_function()- await handler.evaluate_experience()- handler.save_experience()+ await handler.process_experience()return handler._result@@ -87,6 +87,16 @@ class ExpCacheHandler(BaseModel):"""Execute the function, and save the result."""self._result = await self._execute_function()+ @handle_exception+ async def process_experience(self):+ """Process experience.++ Evaluates and saves experience.+ Use `handle_exception` to ensure robustness, do not stop subsequent operations.+ """+ await self.evaluate_experience()+ self.save_experience()+async def evaluate_experience(self):"""Evaluate the experience, and save the score."""diff --git a/metagpt/exp_pool/manager.py b/metagpt/exp_pool/manager.pyindex 58499104d..546086b37 100644--- a/metagpt/exp_pool/manager.py+++ b/metagpt/exp_pool/manager.py@@ -8,6 +8,7 @@ from metagpt.config2 import Config, configfrom metagpt.exp_pool.schema import MAX_SCORE, Experience, QueryTypefrom metagpt.rag.engines import SimpleEnginefrom metagpt.rag.schema import ChromaRetrieverConfig, LLMRankerConfig+from metagpt.utils.exceptions import handle_exceptionclass ExperienceManager(BaseModel):@@ -34,6 +35,7 @@ class ExperienceManager(BaseModel):)return self+ @handle_exceptiondef create_exp(self, exp: Experience):"""Adds an experience to the storage if writing is enabled.@@ -45,6 +47,7 @@ class ExperienceManager(BaseModel):self.storage.add_objs([exp])+ @handle_exception(default_return=[])async def query_exps(self, req: str, tag: str = "", query_type: QueryType = QueryType.SEMANTIC) -> list[Experience]:"""Retrieves and filters experiences.