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

chore: Enhance workforce utils (#2800)

Tao Sun31c7c85250ce
diff --git a/camel/societies/workforce/prompts.py b/camel/societies/workforce/prompts.py
index 6ee3dacfb..32eb08d22 100644
--- a/camel/societies/workforce/prompts.py
+++ b/camel/societies/workforce/prompts.py
@@ -65,7 +65,8 @@ Example valid response:
"assignments": [
{{"task_id": "task_1", "assignee_id": "node_12345", "dependencies": []}},
{{"task_id": "task_2", "assignee_id": "node_67890", "dependencies": ["task_1"]}},
- {{"task_id": "task_3", "assignee_id": "node_12345", "dependencies": []}}
+ {{"task_id": "task_3", "assignee_id": "node_12345", "dependencies": []}},
+ {{"task_id": "task_4", "assignee_id": "node_67890", "dependencies": ["task_1", "task_2"]}}
]
}}
diff --git a/camel/societies/workforce/utils.py b/camel/societies/workforce/utils.py
index 3468da754..18a1e680b 100644
--- a/camel/societies/workforce/utils.py
+++ b/camel/societies/workforce/utils.py
@@ -14,7 +14,7 @@
from functools import wraps
from typing import Callable, List
-from pydantic import BaseModel, Field
+from pydantic import BaseModel, Field, field_validator
class WorkerConf(BaseModel):
@@ -54,6 +54,23 @@ class TaskAssignment(BaseModel):
"This is critical for the task decomposition and execution.",
)
+ # Allow LLMs to output dependencies as a comma-separated string or empty
+ # string. This validator converts such cases into a list[str] so that
+ # downstream logic does not break with validation errors.
+ @staticmethod
+ def _split_and_strip(dep_str: str) -> List[str]:
+ r"""Utility to split a comma separated string and strip whitespace."""
+ return [d.strip() for d in dep_str.split(',') if d.strip()]
+
+ @field_validator("dependencies", mode="before")
+ def validate_dependencies(cls, v) -> List[str]:
+ if v is None:
+ return []
+ # Handle empty string or comma-separated string from LLM
+ if isinstance(v, str):
+ return TaskAssignment._split_and_strip(v)
+ return v
+
class TaskAssignResult(BaseModel):
r"""The result of task assignment for both single and batch assignments."""