Fix async crew example#3
Conversation
| result_1 = await analysis_crew1.kickoff_async(inputs={"ages": [25, 30, 35, 40, 45]}) | ||
| result_2 = analysis_crew2.kickoff(inputs={"ages": [20, 25, 30, 35, 40]}) |
There was a problem hiding this comment.
🟡 await on kickoff_async forces sequential execution, defeating async purpose
On line 57, result_1 = await analysis_crew1.kickoff_async(...) suspends the coroutine until kickoff_async fully completes before line 58 (analysis_crew2.kickoff(...)) even begins. This makes the two crew executions run sequentially, completely defeating the purpose of using kickoff_async (as indicated by the file name, the async_execution=True task flag, and the print labels "Async Crew Thread Output" vs "Main Thread Output"). To achieve concurrency, the async task should be started (e.g., via asyncio.create_task()) before calling the synchronous kickoff, and then awaited afterward, or both should be async and run via asyncio.gather().
Prompt for agents
In src/crew_agent/agents/aysnc.py, the main() function awaits kickoff_async on line 57 before starting the synchronous kickoff on line 58, which makes both operations run sequentially. The intent (based on file naming and print labels) is clearly to run them concurrently.
Two possible fixes:
1. Use asyncio.gather with both crews using kickoff_async:
result_1, result_2 = await asyncio.gather(
analysis_crew1.kickoff_async(inputs={"ages": [25, 30, 35, 40, 45]}),
analysis_crew2.kickoff_async(inputs={"ages": [20, 25, 30, 35, 40]})
)
2. Use asyncio.create_task to start the async work, then run the sync call, then await:
task = asyncio.create_task(analysis_crew1.kickoff_async(inputs={"ages": [25, 30, 35, 40, 45]}))
result_2 = analysis_crew2.kickoff(inputs={"ages": [20, 25, 30, 35, 40]})
result_1 = await task
Note: Option 2 may still block the event loop during the synchronous kickoff() call, so option 1 (making both async) is generally preferred.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
Testing
python -m py_compile $(git ls-files '*.py')https://chatgpt.com/codex/tasks/task_e_684c279ce304832aba0ab15c4e2a1c71