Kickoff Crew Asynchronously
Kickoff a Crew Asynchronously
Introduction
CrewAI provides the ability to kickoff a crew asynchronously, allowing you to start the crew execution in a non-blocking manner. This feature is particularly useful when you want to run multiple crews concurrently or when you need to perform other tasks while the crew is executing.
Asynchronous Crew Execution
To kickoff a crew asynchronously, use the kickoff_async()
method. This method initiates the crew execution in a separate thread, allowing the main thread to continue executing other tasks.
Method Signature
Parameters
inputs
(dict): A dictionary containing the input data required for the tasks.
Returns
CrewOutput
: An object representing the result of the crew execution.
Potential Use Cases
-
Parallel Content Generation: Kickoff multiple independent crews asynchronously, each responsible for generating content on different topics. For example, one crew might research and draft an article on AI trends, while another crew generates social media posts about a new product launch. Each crew operates independently, allowing content production to scale efficiently.
-
Concurrent Market Research Tasks: Launch multiple crews asynchronously to conduct market research in parallel. One crew might analyze industry trends, while another examines competitor strategies, and yet another evaluates consumer sentiment. Each crew independently completes its task, enabling faster and more comprehensive insights.
-
Independent Travel Planning Modules: Execute separate crews to independently plan different aspects of a trip. One crew might handle flight options, another handles accommodation, and a third plans activities. Each crew works asynchronously, allowing various components of the trip to be planned simultaneously and independently for faster results.
Example: Single Asynchronous Crew Execution
Here’s an example of how to kickoff a crew asynchronously using asyncio and awaiting the result:
Example: Multiple Asynchronous Crew Executions
In this example, we’ll show how to kickoff multiple crews asynchronously and wait for all of them to complete using asyncio.gather()
:
Was this page helpful?