From eae91c340c5ea9c20d164cdbe247ad73d95c1a2d Mon Sep 17 00:00:00 2001 From: dewmal Date: Fri, 16 Aug 2024 01:06:26 +0530 Subject: [PATCH] Add Agent Type Attribute --- bindings/ceylon/ceylon/agent/agent.py | 1 + bindings/ceylon/ceylon/core/worker.py | 1 + bindings/ceylon/ceylon/llm/llm_task_coordinator.py | 5 ++++- bindings/ceylon/ceylon/llm/llm_task_operator.py | 3 +++ bindings/ceylon/ceylon/task/task_operation.py | 3 --- bindings/ceylon/ceylon/task/task_operator.py | 2 ++ bindings/ceylon/tests/tasks/llm_software_agency.py | 2 +- 7 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bindings/ceylon/ceylon/agent/agent.py b/bindings/ceylon/ceylon/agent/agent.py index bd88c23..c76acd7 100644 --- a/bindings/ceylon/ceylon/agent/agent.py +++ b/bindings/ceylon/ceylon/agent/agent.py @@ -4,6 +4,7 @@ class Agent(Worker, AgentCommon): + agent_type = "AGENT" history_responses = [] def __init__(self, name="admin", diff --git a/bindings/ceylon/ceylon/core/worker.py b/bindings/ceylon/ceylon/core/worker.py index a21289d..8b7cb3a 100644 --- a/bindings/ceylon/ceylon/core/worker.py +++ b/bindings/ceylon/ceylon/core/worker.py @@ -10,6 +10,7 @@ class Worker(WorkerAgent, Processor, MessageHandler, EventHandler): + agent_type = "WORKER" def __init__(self, name="admin", workspace_id=DEFAULT_WORKSPACE_ID, admin_peer="", admin_port=DEFAULT_ADMIN_PORT, role="worker", diff --git a/bindings/ceylon/ceylon/llm/llm_task_coordinator.py b/bindings/ceylon/ceylon/llm/llm_task_coordinator.py index 88e5ee1..de999a6 100644 --- a/bindings/ceylon/ceylon/llm/llm_task_coordinator.py +++ b/bindings/ceylon/ceylon/llm/llm_task_coordinator.py @@ -3,6 +3,7 @@ import pydantic.v1 from langchain_core.output_parsers import StrOutputParser from langchain_core.prompts import ChatPromptTemplate, PromptTemplate +from loguru import logger from ceylon.llm.llm_task_operator import LLMTaskOperator from ceylon.static_val import DEFAULT_WORKSPACE_ID, DEFAULT_ADMIN_PORT @@ -43,6 +44,7 @@ def __init__(self, tasks: List[Task], agents: List[LLMTaskOperator], llm=None, t self.tool_llm = tool_llm self.tasks = tasks self.agents = agents + logger.info(f"LLM Task Coordinator initialized with {len(tasks)} tasks and {len(self.get_llm_operators)} agents {[agent for agent in self.get_llm_operators]}") super().__init__(name=name, port=port, tasks=tasks, agents=agents) async def get_task_executor(self, task: SubTask) -> str: @@ -68,7 +70,8 @@ async def update_task(self, idx: int, task: Task): def get_llm_operators(self) -> List[LLMTaskOperator]: operators = [] for agent in self.agents: - if isinstance(agent, LLMTaskOperator): + if isinstance(agent, LLMTaskOperator) and hasattr(agent, + "agent_type") and agent.agent_type == LLMTaskOperator.agent_type: operators.append(agent) return operators diff --git a/bindings/ceylon/ceylon/llm/llm_task_operator.py b/bindings/ceylon/ceylon/llm/llm_task_operator.py index e1df08f..3279ff5 100644 --- a/bindings/ceylon/ceylon/llm/llm_task_operator.py +++ b/bindings/ceylon/ceylon/llm/llm_task_operator.py @@ -13,6 +13,9 @@ class LLMTaskOperator(TaskOperator): + """LLM-based task operator.""" + agent_type = "LLM_TASK_OPERATOR" + def __init__(self, name: str, role: str, context: str, skills: List[str], tools: List[Any] = None, llm=None, tool_llm=None, verbose=False, workspace_id="ceylon_agent_stack", diff --git a/bindings/ceylon/ceylon/task/task_operation.py b/bindings/ceylon/ceylon/task/task_operation.py index 9ebbcd3..67c1636 100644 --- a/bindings/ceylon/ceylon/task/task_operation.py +++ b/bindings/ceylon/ceylon/task/task_operation.py @@ -41,9 +41,6 @@ class Task(BaseModel): def add_subtask(self, subtask: SubTask): subtask.parent_task_id = self.id - if subtask.name in self.subtasks: - raise ValueError(f"Subtask with id {subtask.name} already exists") - self.subtasks[subtask.name] = subtask self._validate_dependencies() self.execution_order = self.get_execution_order() diff --git a/bindings/ceylon/ceylon/task/task_operator.py b/bindings/ceylon/ceylon/task/task_operator.py index a6b8ccb..80a8a39 100644 --- a/bindings/ceylon/ceylon/task/task_operator.py +++ b/bindings/ceylon/ceylon/task/task_operator.py @@ -10,6 +10,8 @@ class TaskOperator(Agent, abc.ABC): + agent_type = "TASK_OPERATOR" + def __init__(self, name: str, role: str, workspace_id: str = DEFAULT_WORKSPACE_ID, admin_port: int = DEFAULT_ADMIN_PORT, *args, **kwargs): diff --git a/bindings/ceylon/tests/tasks/llm_software_agency.py b/bindings/ceylon/tests/tasks/llm_software_agency.py index fbea257..6d12310 100644 --- a/bindings/ceylon/tests/tasks/llm_software_agency.py +++ b/bindings/ceylon/tests/tasks/llm_software_agency.py @@ -52,7 +52,7 @@ ), AgentMonitor() ] -# enable_log("DEBUG") +# enable_log("INFO") # Initialize TaskManager task_manager = LLMTaskCoordinator(tasks, agents, tool_llm=tool_llm, llm=llm)