I’m not sure about the kickoff_async() method to kickoff a crew. Can someone add some details about how it works?
Hey Simone, while you’re waiting for some more experienced folks to chime in on async, here are my 2 cents.
Your question was a bit vague on the scope, so I’ll try to cover from common scenarios to some edge cases, based on what I know.
First off, it’s important to check out the official CrewAI documentation here.
Under the hood, crew.kickoff_async
just uses asyncio.to_thread
to run the synchronous version (crew.kickoff
) in that thread. This is a way to avoid blocking the main thread, letting you do other tasks and also run more than one crew at the same time (I’ll get back to this in a sec). The CrewAI docs I mentioned have an example of asynchronous execution.
Remember that the function (or “coroutine”) running your crews asynchronously needs to be marked as async
, and the crew results should be gathered using await asyncio.gather
, just like the official docs suggest. If you need a refresher on async concepts in Python, you might like this YouTube video.
Lastly, when I mentioned running multiple crews at the same time, it’s important to point out that, from what I gather, if you run, say, a thousand crews simultaneously, they’ll all kick off at once without any control over resource consumption (think especially about your LLM limits here). For situations like that, creating and managing your own ThreadPoolExecutor
and using it with loop.run_in_executor(your_executor, crew.kickoff, inputs)
will give you much better control, allowing for max_workers
simultaneous crews per turn.