Hi all! I’ve been using Crew AI for the past week and really love the simplicity. However, I do need some help figuring out how to run a task asynchronously. I have n number of tasks that are independent of each other and don’t need to run sequentially. I found these documentation pages:
but I can’t find an example of how this is done. I tried doing something like this in my crew class:
@task
def example_task(self) -> Task:
output_path = Path("example/path"
output_path.mkdir(parents=True, exist_ok=True)
return Task(
config=self.tasks_config["threads_single_task"],
output_file=str(output_path / f"filename.txt"),
async_execution=True,
)
for my n number of files but I got this error:
python main.py run blog_repurpose
Traceback (most recent call last):
File “/Users/cjjohanson/Documents/GitHub/content_team/content_gen_team/main.py”, line 39, in run
crew = CrewClass().crew()
^^^^^^^^^^^^^^^^^^
File “/Users/cjjohanson/.local/share/virtualenvs/content_team-8pRxG-uY/lib/python3.12/site-packages/crewai/project/utils.py”, line 11, in memoized_func
cache[key] = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File “/Users/cjjohanson/.local/share/virtualenvs/content_team-8pRxG-uY/lib/python3.12/site-packages/crewai/project/annotations.py”, line 112, in wrapper
crew = func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/cjjohanson/Documents/GitHub/content_team/content_gen_team/crews/blog_repurpose_crew.py”, line 145, in crew
return Crew(
^^^^^
File “/Users/cjjohanson/.local/share/virtualenvs/content_team-8pRxG-uY/lib/python3.12/site-packages/pydantic/main.py”, line 243, in init
validated_self = self.pydantic_validator.validate_python(data, self_instance=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for Crew
The crew must end with at most one asynchronous task. [type=async_task_count, input_value={‘agents’: [Agent(role=Se…tial’>, ‘verbose’: True}, input_type=dict]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/Users/cjjohanson/Documents/GitHub/content_team/content_gen_team/main.py”, line 94, in
run(CrewClass)
File “/Users/cjjohanson/Documents/GitHub/content_team/content_gen_team/main.py”, line 43, in run
raise Exception(f"An error occurred while running the crew: {e}")
Exception: An error occurred while running the crew: 1 validation error for Crew
The crew must end with at most one asynchronous task. [type=async_task_count, input_value={‘agents’: [Agent(role=Se…tial’>, ‘verbose’: True}, input_type=dict]
When I read it, that error seems to be at odds with the asynchronous functionality but I must be reading it wrong. Can anyone help me out?