Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

enhance: added more logging and exception handling to workforce (#2671)

Hesam Sheikha74062ada551
diff --git a/camel/societies/workforce/single_agent_worker.py b/camel/societies/workforce/single_agent_worker.py
index 027ff4f8e..2b4d3cd12 100644
--- a/camel/societies/workforce/single_agent_worker.py
+++ b/camel/societies/workforce/single_agent_worker.py
@@ -286,8 +286,8 @@ class SingleAgentWorker(Worker):
)
except Exception as e:
print(
- f"{Fore.RED}Error occurred while processing task {task.id}:"
- f"\n{e}{Fore.RESET}"
+ f"{Fore.RED}Error processing task {task.id}: "
+ f"{type(e).__name__}: {e}{Fore.RESET}"
)
return TaskState.FAILED
finally:
@@ -336,8 +336,15 @@ class SingleAgentWorker(Worker):
print(f"======\n{Fore.GREEN}Reply from {self}:{Fore.RESET}")
- result_dict = json.loads(response.msg.content)
- task_result = TaskResult(**result_dict)
+ try:
+ result_dict = json.loads(response.msg.content)
+ task_result = TaskResult(**result_dict)
+ except json.JSONDecodeError as e:
+ print(
+ f"{Fore.RED}JSON parsing error for task {task.id}: "
+ f"Invalid response format - {e}{Fore.RESET}"
+ )
+ return TaskState.FAILED
color = Fore.RED if task_result.failed else Fore.GREEN
print(