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

feat: Workforce add attempt information as Task additional info (#2520)

Wendong-Fan242c342a1a79
diff --git a/camel/societies/workforce/single_agent_worker.py b/camel/societies/workforce/single_agent_worker.py
index 3dd9fefe6..70f432b45 100644
--- a/camel/societies/workforce/single_agent_worker.py
+++ b/camel/societies/workforce/single_agent_worker.py
@@ -13,6 +13,7 @@
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
from __future__ import annotations
+import datetime
import json
from typing import Any, List
@@ -83,6 +84,28 @@ class SingleAgentWorker(Worker):
)
return TaskState.FAILED
+ # Populate additional_info with worker attempt details
+ if task.additional_info is None:
+ task.additional_info = {}
+
+ # Create worker attempt details with descriptive keys
+ worker_attempt_details = {
+ "agent_id": getattr(
+ self.worker, "agent_id", self.worker.role_name
+ ),
+ "timestamp": str(datetime.datetime.now()),
+ "description": f"Attempt by "
+ f"{getattr(self.worker, 'agent_id', self.worker.role_name)} "
+ f"to process task {task.content}",
+ "response_content": response.msg.content,
+ "tool_calls": response.info["tool_calls"],
+ }
+
+ # Store the worker attempt in additional_info
+ if "worker_attempts" not in task.additional_info:
+ task.additional_info["worker_attempts"] = []
+ task.additional_info["worker_attempts"].append(worker_attempt_details)
+
print(f"======\n{Fore.GREEN}Reply from {self}:{Fore.RESET}")
result_dict = json.loads(response.msg.content)
diff --git a/camel/tasks/task.py b/camel/tasks/task.py
index 9d05d8fda..a3545d0fe 100644
--- a/camel/tasks/task.py
+++ b/camel/tasks/task.py
@@ -14,7 +14,7 @@
import re
from enum import Enum
-from typing import Callable, Dict, List, Literal, Optional, Union
+from typing import Any, Callable, Dict, List, Literal, Optional, Union
from pydantic import BaseModel
@@ -69,14 +69,23 @@ class Task(BaseModel):
r"""Task is specific assignment that can be passed to a agent.
Attributes:
- content: string content for task.
- id: An unique string identifier for the task. This should
- ideally be provided by the provider/model which created the task.
- state: The state which should be OPEN, RUNNING, DONE or DELETED.
- type: task type
- parent: The parent task, None for root task.
- subtasks: The childrent sub-tasks for the task.
- result: The answer for the task.
+ content (str): string content for task.
+ id (str): An unique string identifier for the task. This should
+ ideally be provided by the provider/model which created the task.
+ (default: :obj: `""`)
+ state (TaskState): The state which should be OPEN, RUNNING, DONE or
+ DELETED. (default: :obj: `TaskState.OPEN`)
+ type (Optional[str]): task type. (default: :obj: `None`)
+ parent (Optional[Task]): The parent task, None for root task.
+ (default: :obj: `None`)
+ subtasks (List[Task]): The childrent sub-tasks for the task.
+ (default: :obj: `[]`)
+ result (Optional[str]): The answer for the task.
+ (default: :obj: `""`)
+ failure_count (int): The failure count for the task.
+ (default: :obj: `0`)
+ additional_info (Optional[Dict[str, Any]]): Additional information for
+ the task. (default: :obj: `None`)
"""
content: str
@@ -95,7 +104,7 @@ class Task(BaseModel):
failure_count: int = 0
- additional_info: Optional[str] = None
+ additional_info: Optional[Dict[str, Any]] = None
@classmethod
def from_message(cls, message: BaseMessage) -> "Task":
diff --git a/docs/mintlify/reference/camel.tasks.task.mdx b/docs/mintlify/reference/camel.tasks.task.mdx
index c75b988bc..fc5a6a7db 100644
--- a/docs/mintlify/reference/camel.tasks.task.mdx
+++ b/docs/mintlify/reference/camel.tasks.task.mdx
@@ -46,14 +46,23 @@ class Task(BaseModel):
Task is specific assignment that can be passed to a agent.
Attributes:
-content: string content for task.
-id: An unique string identifier for the task. This should
+content (str): string content for task.
+id (str): An unique string identifier for the task. This should
ideally be provided by the provider/model which created the task.
-state: The state which should be OPEN, RUNNING, DONE or DELETED.
-type: task type
-parent: The parent task, None for root task.
-subtasks: The childrent sub-tasks for the task.
-result: The answer for the task.
+(default: :obj: `""`)
+state (TaskState): The state which should be OPEN, RUNNING, DONE or
+DELETED. (default: :obj: `TaskState.OPEN`)
+type (Optional[str]): task type. (default: :obj: `None`)
+parent (Optional[Task]): The parent task, None for root task.
+(default: :obj: `None`)
+subtasks (List[Task]): The childrent sub-tasks for the task.
+(default: :obj: `[]`)
+result (Optional[str]): The answer for the task.
+(default: :obj: `""`)
+failure_count (int): The failure count for the task.
+(default: :obj: `0`)
+additional_info (Optional[Dict[str, Any]]): Additional information for
+the task. (default: :obj: `None`)
<a id="camel.tasks.task.Task.from_message"></a>