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

refactor: Using agent id for agent worker node id in workforce (#2545)

Wendong-Fan474f4e6a1778
diff --git a/camel/agents/chat_agent.py b/camel/agents/chat_agent.py
index c2ff40168..22faa9d3e 100644
--- a/camel/agents/chat_agent.py
+++ b/camel/agents/chat_agent.py
@@ -204,7 +204,7 @@ class ChatAgent(BaseAgent):
self.model_type = self.model_backend.model_type
# Assign unique ID
- self.agent_id = agent_id if agent_id else str(uuid.uuid4())
+ self.agent_id = agent_id if agent_id else str(uuid.uuid4())[:6]
# Set up memory
context_creator = ScoreBasedContextCreator(
diff --git a/camel/societies/workforce/base.py b/camel/societies/workforce/base.py
index 760ed3f2d..b78bdbde3 100644
--- a/camel/societies/workforce/base.py
+++ b/camel/societies/workforce/base.py
@@ -12,7 +12,7 @@
# limitations under the License.
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
from abc import ABC, abstractmethod
-from typing import Any
+from typing import Any, Optional
from camel.societies.workforce.task_channel import TaskChannel
from camel.societies.workforce.utils import check_if_running
@@ -23,10 +23,14 @@ class BaseNode(ABC):
Args:
description (str): Description of the node.
+ node_id (Optional[str]): ID of the node. If not provided, it will
+ be generated automatically. (default: :obj:`None`)
"""
- def __init__(self, description: str) -> None:
- self.node_id = str(id(self))
+ def __init__(
+ self, description: str, node_id: Optional[str] = None
+ ) -> None:
+ self.node_id = node_id if node_id is not None else str(id(self))
self.description = description
self._channel: TaskChannel = TaskChannel()
self._running = False
diff --git a/camel/societies/workforce/single_agent_worker.py b/camel/societies/workforce/single_agent_worker.py
index 618f00dd1..3dd9fefe6 100644
--- a/camel/societies/workforce/single_agent_worker.py
+++ b/camel/societies/workforce/single_agent_worker.py
@@ -39,7 +39,8 @@ class SingleAgentWorker(Worker):
description: str,
worker: ChatAgent,
) -> None:
- super().__init__(description)
+ node_id = worker.agent_id
+ super().__init__(description, node_id=node_id)
self.worker = worker
def reset(self) -> Any:
diff --git a/camel/societies/workforce/worker.py b/camel/societies/workforce/worker.py
index a5fa3ea6f..899e14eb8 100644
--- a/camel/societies/workforce/worker.py
+++ b/camel/societies/workforce/worker.py
@@ -15,7 +15,7 @@ from __future__ import annotations
import logging
from abc import ABC, abstractmethod
-from typing import List
+from typing import List, Optional
from colorama import Fore
@@ -33,14 +33,16 @@ class Worker(BaseNode, ABC):
Args:
description (str): Description of the node.
-
+ node_id (Optional[str]): ID of the node. If not provided, it will
+ be generated automatically. (default: :obj:`None`)
"""
def __init__(
self,
description: str,
+ node_id: Optional[str] = None,
) -> None:
- super().__init__(description)
+ super().__init__(description, node_id=node_id)
def __repr__(self):
return f"Worker node {self.node_id} ({self.description})"