🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
[ehnahce] Workforce JSON validation added (#2739)
Hesam Sheikh4fc08ef90bd6
diff --git a/camel/societies/workforce/workforce.py b/camel/societies/workforce/workforce.pyindex 25579ad4d..fe1e42c29 100644--- a/camel/societies/workforce/workforce.py+++ b/camel/societies/workforce/workforce.py@@ -1325,8 +1325,16 @@ class Workforce(BaseNode):)return TaskAssignResult(assignments=[])- result_dict = json.loads(response.msg.content, parse_int=str)- return TaskAssignResult(**result_dict)+ try:+ result_dict = json.loads(response.msg.content, parse_int=str)+ return TaskAssignResult(**result_dict)+ except json.JSONDecodeError as e:+ logger.error(+ f"JSON parsing error in task assignment: Invalid response "+ f"format - {e}. Response content: "+ f"{response.msg.content[:50]}..."+ )+ return TaskAssignResult(assignments=[])def _validate_assignments(self, assignments: List[TaskAssignment], valid_ids: Set[str]@@ -1550,8 +1558,19 @@ class Workforce(BaseNode):"with various tasks.",)else:- result_dict = json.loads(response.msg.content)- new_node_conf = WorkerConf(**result_dict)+ try:+ result_dict = json.loads(response.msg.content)+ new_node_conf = WorkerConf(**result_dict)+ except json.JSONDecodeError as e:+ logger.error(+ f"JSON parsing error in worker creation: Invalid response "+ f"format - {e}. Response content: "+ f"{response.msg.content[:100]}..."+ )+ raise RuntimeError(+ f"Failed to create worker for task {task.id}: "+ f"Coordinator agent returned malformed JSON response. "+ )new_agent = self._create_new_agent(new_node_conf.role,