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. CrewAI offers two approaches for async execution:| Method | Type | Description |
|---|---|---|
akickoff() | Native async | True async/await throughout the entire execution chain |
kickoff_async() | Thread-based | Wraps synchronous execution in asyncio.to_thread |
For high-concurrency workloads,
akickoff() is recommended as it uses native async for task execution, memory operations, and knowledge retrieval.Native Async Execution with akickoff()
The akickoff() method provides true native async execution, using async/await throughout the entire execution chain including task execution, memory operations, and knowledge queries.
Method Signature
Code
Parameters
inputs(dict): A dictionary containing the input data required for the tasks.
Returns
CrewOutput: An object representing the result of the crew execution.
Example: Native Async Crew Execution
Code
Example: Multiple Native Async Crews
Run multiple crews concurrently usingasyncio.gather() with native async:
Code
Example: Native Async for Multiple Inputs
Useakickoff_for_each() to execute your crew against multiple inputs concurrently with native async:
Code
Thread-Based Async with kickoff_async()
The kickoff_async() method provides async execution by wrapping the synchronous kickoff() in a thread. This is useful for simpler async integration or backward compatibility.
Method Signature
Code
Parameters
inputs(dict): A dictionary containing the input data required for the tasks.
Returns
CrewOutput: An object representing the result of the crew execution.
Example: Thread-Based Async Execution
Code
Example: Multiple Thread-Based Async Crews
Code
Async Streaming
Both async methods support streaming whenstream=True is set on the crew:
Code
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.
- 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.
- 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.
Choosing Between akickoff() and kickoff_async()
| Feature | akickoff() | kickoff_async() |
|---|---|---|
| Execution model | Native async/await | Thread-based wrapper |
| Task execution | Async with aexecute_sync() | Sync in thread pool |
| Memory operations | Async | Sync in thread pool |
| Knowledge retrieval | Async | Sync in thread pool |
| Best for | High-concurrency, I/O-bound workloads | Simple async integration |
| Streaming support | Yes | Yes |
