From eaac6276001906704d5c0f0dcb3ba67ec90845c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moura?= Date: Mon, 11 Mar 2024 19:53:34 -0300 Subject: [PATCH] updating CLI template and guaranteeing tasks order --- pyproject.toml | 2 +- src/crewai/cli/templates/crew.py | 5 +++-- src/crewai/cli/templates/main.py | 4 +++- src/crewai/cli/templates/tools/custom_tool.py | 3 --- src/crewai/project/annotations.py | 13 ++++++++----- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0d78b3dd66..66727ea571 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "crewai" -version = "0.22.0" +version = "0.22.2" description = "Cutting-edge framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks." authors = ["Joao Moura "] readme = "README.md" diff --git a/src/crewai/cli/templates/crew.py b/src/crewai/cli/templates/crew.py index d143f39ad4..30e1cd9ee0 100644 --- a/src/crewai/cli/templates/crew.py +++ b/src/crewai/cli/templates/crew.py @@ -1,7 +1,8 @@ from crewai import Agent, Crew, Process, Task from crewai.project import CrewBase, agent, crew, task -from .tools.custom_tool import MyCustomTool +# Uncomment the following line to use an example of a custom tool +# from .tools.custom_tool import MyCustomTool # Check our tools documentations for more information on how to use them # from crewai_tools import SerperDevTool @@ -16,7 +17,7 @@ class {{crew_name}}Crew(): def researcher(self) -> Agent: return Agent( config=self.agents_config['researcher'], - # tools=[MyCustomTool()], # Example of custom tool + # tools=[MyCustomTool()], # Example of custom tool, loaded on the beginning of file verbose=True ) diff --git a/src/crewai/cli/templates/main.py b/src/crewai/cli/templates/main.py index 6a71e90bb4..c8ea127260 100644 --- a/src/crewai/cli/templates/main.py +++ b/src/crewai/cli/templates/main.py @@ -4,5 +4,7 @@ def run(): # Replace with your inputs, it will automatically interpolate any tasks and agents information - inputs = {'topic': 'AI LLMs'} + inputs = { + 'topic': 'AI LLMs' + } {{crew_name}}Crew().crew().kickoff(inputs=inputs) \ No newline at end of file diff --git a/src/crewai/cli/templates/tools/custom_tool.py b/src/crewai/cli/templates/tools/custom_tool.py index 1c13a19a02..4d60dc8328 100644 --- a/src/crewai/cli/templates/tools/custom_tool.py +++ b/src/crewai/cli/templates/tools/custom_tool.py @@ -1,6 +1,3 @@ -# For this make sure to install the tools package -# pip install 'crewai[tools]' - from crewai_tools import BaseTool diff --git a/src/crewai/project/annotations.py b/src/crewai/project/annotations.py index b84954ccda..3327296a49 100644 --- a/src/crewai/project/annotations.py +++ b/src/crewai/project/annotations.py @@ -1,5 +1,9 @@ +tasks_order = [] + + def task(func): func.is_task = True + tasks_order.append(func.__name__) return func @@ -13,11 +17,11 @@ def wrapper(self, *args, **kwargs): instantiated_tasks = [] instantiated_agents = [] - # Instantiate tasks and collect their associated agents agent_roles = set() - for attr_name in dir(self): - possible_task = getattr(self, attr_name) - if callable(possible_task) and hasattr(possible_task, "is_task"): + # Iterate over tasks_order to maintain the defined order + for task_name in tasks_order: + possible_task = getattr(self, task_name) + if callable(possible_task): task_instance = possible_task() instantiated_tasks.append(task_instance) if hasattr(task_instance, "agent"): @@ -38,7 +42,6 @@ def wrapper(self, *args, **kwargs): self.agents = instantiated_agents self.tasks = instantiated_tasks - # Now call the original crew method return func(self, *args, **kwargs) return wrapper