Skip to content

Fix async crew example#3

Open
xiaoxipanda wants to merge 1 commit into
masterfrom
codex/find-and-fix-bug
Open

Fix async crew example#3
xiaoxipanda wants to merge 1 commit into
masterfrom
codex/find-and-fix-bug

Conversation

@xiaoxipanda

Copy link
Copy Markdown
Owner

Summary

  • ensure async kickoff example awaits result

Testing

  • python -m py_compile $(git ls-files '*.py')

https://chatgpt.com/codex/tasks/task_e_684c279ce304832aba0ab15c4e2a1c71

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment on lines +57 to +58
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]})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant